This plugin for Obsidian adds a "Code block from selection" command that turns the selected text into a code block. It just adds ``` before and after the selected text. In the plugin settings you can specify which language to use in the code block. You can add as many languages as you like and assign hotkeys to them.
Specify the programming language in the plugin settings (for example "c++"), then add the desired hotkey for the "Code block from selection" command on the Obsidian hotkeys panel.
Just select the text with code or put the cursor on the desired line and press hotkey.