Comment stuff out. Use
gcc to comment out a line (takes a count),
gc to comment out the target of a motion (for example,
comment out a paragraph),
gc in visual mode to comment out the selection,
gc in operator pending mode to target a comment. You can also use
it as a command, either with a range like
:7,17Commentary, or as part of a
:global invocation like with
:g/TODO/Commentary. That's it.
I wrote this because 5 years after Vim added support for mapping an operator, I still couldn't find a commenting plugin that leveraged that feature (I overlooked tcomment.vim). Striving for minimalism, it weighs in at under 100 lines of code.
Oh, and it uncomments, too. The above maps actually toggle, and
uncomments a set of adjacent commented lines.
Install using your favorite package manager, or use Vim's built-in package support:
mkdir -p ~/.vim/pack/tpope/start cd ~/.vim/pack/tpope/start git clone https://tpope.io/vim/commentary.git vim -u NONE -c "helptags commentary/doc" -c q
My favorite file type isn't supported!
Relax! You just have to adjust
autocmd FileType apache setlocal commentstring=#\ %s
Copyright (c) Tim Pope. Distributed under the same terms as Vim itself.
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容，可点击提交进行申诉，我们将尽快为您处理。