Vim Tips and Tricks
This article does not serve as a general Vim tutorial. There are
already great resources that cover this: the
vimtutor command, YouTube videos and
this cheat sheet.
What I will focus on here is sharing various Vim operations that I have found useful, and you might as well.
System clipboard
You can use the special + register to manipulate the OS
clipboard.
To copy text into this register, use the
"+y command. To paste from it, use "+p.
This shortcut works with the regular version of Vim. Neovim also solves this by linking the default clipboard (accessed with y/d/p shortcuts) to your system clipboard automatically.
Commenting and uncommenting lines (Original source)
For this task, you can use block selection.
Commenting
Go to the first line you want to comment out. Move your cursor to be
placed on the first non-whitespace character. Then, press
Ctrl+V to activate visual block mode.
Keep moving your cursor down until you reach the last line you want
to comment out. Then, press Shift+I to enter insert
mode and insert whatever pattern is used for comments (such as
// in C family languages).
After you're done, press Esc. It may take a few seconds
for the operation to complete.
Uncommenting
Go to the first line you want to activate and put your cursor on the first character of the comment pattern. After that, activate visual block mode.
Now, select the entire pattern you want to remove, then press the
X key.