How To Comment Code In Vim
In Vim there is no out-of-the-box way to comment code. But some plugins will make that happen for us.
I suggest using the battle-tested tpope/vim-commentary by Tim Pope.
It introduces a special command (operator) gc
, which fits quite nicely into Vim world.
gcc
comment/uncomment the current linegc
comment/uncomment the selection in Visual modegcap
comment the entire paragraph (it supports the text objects (:help text-objects))
More options
Among other alternatives, there are nerdcommenter and tcomment, which you might want to also check out.