博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

NERD Commenter

Posted on 2020-05-17 14:41  cxysailor  阅读(392)  评论(0)    收藏  举报

NERD Commenter

by cxysailor 2020-03-17 23:24:30

Vim plugin for instensely nerdy commenting powers

Comment functions so powerful - no comment necessary

Installation

Via Plugin Manager (Recommended)

Vim-Plug

  1. Add Plug 'preservim/nerdcommenter' to your vimrc file

  2. Reload your vimrc or restart

  3. Run :PlugInstall

Vundle or similar

  1. Add Plugin 'preservim/nerdcommenter' to your vimrc file

  2. Reload your vimrc or restart

  3. Run :BundleInstall

NeoBundle

  1. Add NeoBundle 'preservim/nerdcommenter' to your vimrc file

  2. Reload your vimrc or restart

  3. Run :NeoUpdate

Pathogen

 
1 cd ~/.vim/bundle
2  git clone https://github.com/preservim/nerdcommenter.git

 

Manual Installation

Unix (For Neovim,change ~/.vim/ to ~/.config/nvim/)

 
1 curl -fLo ~/.vim/plugin/NERD_Commenter.vim --create-dirs \
2    https://raw.githubusercontent.com/preservim/nerdcommenter/master/plugin/NERD_commenter.vim
3  curl -fLo ~/.vim/doc/NERD_Commenter.txt --create-dirs \
4    https://raw.githubusercontent.com/preservim/nerdcommenter/master/doc/NERD_commenter.txt

 

Windows (PowerShell)

 
1 md ~\vimfiles\plugin
2  md ~\vimfiles\doc
3  $pluguri = 'https://raw.githubusercontent.com/preservim/nerdcommenter/master/plugin/NERD_commenter.vim'
4  $docsuri = 'https://raw.githubusercontent.com/preservim/nerdcommenter/master/doc/NERD_commenter.txt'
5  (New-Object Net.WebClient).DownloadFile($pluguri, $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("~\vimfiles\plugin\NERD_commenter.vim"))
6  (New-Object Net.WebClient).DownloadFile($docsuri, $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("~\vimfiles\doc\NERD_commenter.txt"))

 

Post Installation

Make sure that you have filetype plugins enabled,as the plugin makes use of |commentstring| where possible(which is usually set in a filetype plugin). See |filetype-plugin-on| for details,but the shor version is make sure this line appears in your vimrc:

filetype plugin on

Usage

Documentation

Please see the vim help system for full documentation of all options::help nerdcommenter

Settings

Several settings can be added to your vimrc to change the default behavior.Some example:

 
 1 " Add spaces after comment delimiters by default
 2  let g:NERDSpaceDelims = 1
 3  4  " Use compact syntax for prettified multi-line comments
 5  let g:NERDCompactSexyComs = 1
 6  7  " Align line-wise comment delimiters flush left instead of following code indentation
 8  let g:NERDDefaultAlign = 'left'
 9 10  " Set a language to use its alternate delimiters by default
11  let g:NERDAltDelims_java = 1
12 13  " Add your own custom formats or override the defaults
14  let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } }
15 16  " Allow commenting and inverting empty lines (useful when commenting a region)
17  let g:NERDCommentEmptyLines = 1
18 19  " Enable trimming of trailing whitespace when uncommenting
20  let g:NERDTrimTrailingWhitespace = 1
21 22  " Enable NERDCommenterToggle to check all selected lines is commented or not 
23  let g:NERDToggleCheckAllLines = 1

 

Default mapping

the following key mappings are provided by default(there is also a menu provided that contains menu items corresponding to all the below mapping):

Most of the following mappings are for normal/visual mode only. The |NERDCommenterInsert| mapping is for insert mode only.

  • [count]<leader>cc |NERDCommenterComment|

    Comment out the current line or text selected in visual mode

  • [count]<leader>cn |NERDCommenterNested|

    Same as cc but forces nesting

  • [count]<leader>c<space> |NERDCommenterToggle|

    Toggle the comment state of the selected line(s).If the topmost selected line is commented,all selected lines are uncommented and vice versa

  • [count]<leader>cm |NERDCommeterMinimal|

    Comments the given lines using only one set of multipart delimiters

  • [count]<leader>ci |NERDCommenterInvert|

    Toggles the comment state of the selected line(s) individually

  • [count]<leader>cs |NERDCommenterSexy|

    Comments out the selected lines with a pretty block formatted layout

  • [count]<leader>cy |NERDCommenterYank|

    Same as cc except that the commented line(s) are yanked first

  • <leader>c$ |NERDCommenterToEOL|

    Comments the current line from the cursor to the end of line

  • <leader>cA |NERDCommenterAppend|

    Adds comment delimiters to the end of line and goes into insert mode between them

  • |NERDCommenterInsert|

    Adds comment delimiters at the current cursor position and inserts between.Disable by default

  • <leader>ca |NERDCommenterAltDelims|

    Switchs to the alternative set of delimiters

  • [count]<leader>cl |NERDCommenterAlignLeft| [count]<leader>cb |NERDCommenterAlignBoth|

    Same as |NERDCommenterComment| except that the delimiters are aligned down the left side(<leader>cl) or both (<leader>cb)

  • [count]<leader>cu |NERDCommenterUncomment|

    Uncomments the selected line(s)