'VSCode copy and paste 1 line without newline character being prepended
In VScode when you copy a line of text and then put your cursor in the middle of quotes and hit Ctrl+V it pastes the new line above where you intended it to go.
In IntelliJ and PyCharm when you copy a line of code with Ctrl+C without selecting any text then they intelligently remove the \n character at the end of the string while it is in memory. So when you paste it in middle of quotes you get the desired behavior.
Since VS team is not likely going to fix this anytime soon I was wondering if anyone has a macro for it.
Solution 1:[1]
Having struggled with this for long myself too, I finally stumbled across the solution. Add these lines to keybindings.json:
{
"key": "cmd+alt+ctrl+v", // insert your desired shortcut here
"command": "editor.action.insertSnippet",
"args": {
"snippet": "$CLIPBOARD"},
"when": "inputFocus"
},
Now, pressing cmd+option+ctrl+v (or whatever shortcut you define) should paste without newline, regardless of how it was copied.
For an explanation and more cool things you can do with snippets, see https://code.visualstudio.com/docs/editor/userdefinedsnippets#:~:text=In%20Visual%20Studio%20Code%2C%20snippets,%3A%20Enable%20it%20with%20%22editor.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sippo_mu |

