How to comment 20 lines of Python code on vim?
Solution 1:
In vi
:
- navigate to the line where you wish to start commenting out
- enter command mode (Esc then :)
- type
.,+20s/^/#/
or.,+20s/^/"""/
and hit Enter
Solution 2:
What I typically do is this:
Leave editing mode Esc, may need to hit couple times
Press Shift+v to enter "Visual" mode
Highlight the desired lines via arrow keys, or use 3j to select 3 lines down or 3k 3 lines up
Enter command mode via :, and when you see
:'<,'>
displayed type ins/^/#/
, and then hit Enter
This is visual approach, sort of like using a mouse in GUI to highlight lines, except without a mouse in vim
Solution 3:
If you are using a Python IDE (As PyCharm) you can select these lines and use Ctrl+/ (or the default "comment" shortcut) to comment them.
If you are using a common text editor either you have to comment line per line or use the multi-line string (triple quotes) as a multi-line comment.