mirror of
https://github.com/preservim/nerdcommenter.git
synced 2025-11-09 10:13:48 -05:00
Merge branch 'master' into autoload
This commit is contained in:
45
README.md
45
README.md
@@ -8,33 +8,61 @@ Comment functions so powerful—no comment necessary.
|
|||||||
|
|
||||||
### Via Plugin Manager (Recommended)
|
### Via Plugin Manager (Recommended)
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Vim Plug</summary>
|
||||||
|
|
||||||
#### [Vim-Plug](https://github.com/junegunn/vim-plug)
|
#### [Vim-Plug](https://github.com/junegunn/vim-plug)
|
||||||
|
|
||||||
1. Add `Plug 'preservim/nerdcommenter'` to your vimrc file.
|
1. Add `Plug 'preservim/nerdcommenter'` to your vimrc file.
|
||||||
2. Reload your vimrc or restart
|
2. Reload your vimrc or restart
|
||||||
3. Run `:PlugInstall`
|
3. Run `:PlugInstall`
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Vundle</summary>
|
||||||
|
|
||||||
#### [Vundle](https://github.com/VundleVim/Vundle.vim) or similar
|
#### [Vundle](https://github.com/VundleVim/Vundle.vim) or similar
|
||||||
|
|
||||||
1. Add `Plugin 'preservim/nerdcommenter'` to your vimrc file.
|
1. Add `Plugin 'preservim/nerdcommenter'` to your vimrc file.
|
||||||
2. Reload your vimrc or restart
|
2. Reload your vimrc or restart
|
||||||
3. Run `:BundleInstall`
|
3. Run `:BundleInstall`
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>NeoBundle</summary>
|
||||||
|
|
||||||
#### [NeoBundle](https://github.com/Shougo/neobundle.vim)
|
#### [NeoBundle](https://github.com/Shougo/neobundle.vim)
|
||||||
|
|
||||||
1. Add `NeoBundle 'preservim/nerdcommenter'` to your vimrc file.
|
1. Add `NeoBundle 'preservim/nerdcommenter'` to your vimrc file.
|
||||||
2. Reload your vimrc or restart
|
2. Reload your vimrc or restart
|
||||||
3. Run `:NeoUpdate`
|
3. Run `:NeoUpdate`
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Pathogen</summary>
|
||||||
|
|
||||||
#### [Pathogen](https://github.com/tpope/vim-pathogen)
|
#### [Pathogen](https://github.com/tpope/vim-pathogen)
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cd ~/.vim/bundle
|
cd ~/.vim/bundle
|
||||||
git clone https://github.com/preservim/nerdcommenter.git
|
git clone https://github.com/preservim/nerdcommenter.git
|
||||||
```
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Vim 8+ Packages</summary>
|
||||||
|
|
||||||
|
git clone https://github.com/preservim/nerdcommenter.git ~/.vim/pack/vendor/start/nerdcommenter
|
||||||
|
</details>
|
||||||
|
|
||||||
### Manual Installation
|
### Manual Installation
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Unix</summary>
|
||||||
|
|
||||||
#### Unix
|
#### Unix
|
||||||
|
|
||||||
(For Neovim, change `~/.vim/` to `~/.config/nvim/`.)
|
(For Neovim, change `~/.vim/` to `~/.config/nvim/`.)
|
||||||
@@ -45,7 +73,10 @@ curl -fLo ~/.vim/plugin/NERD_Commenter.vim --create-dirs \
|
|||||||
curl -fLo ~/.vim/doc/NERD_Commenter.txt --create-dirs \
|
curl -fLo ~/.vim/doc/NERD_Commenter.txt --create-dirs \
|
||||||
https://raw.githubusercontent.com/preservim/nerdcommenter/master/doc/NERD_commenter.txt
|
https://raw.githubusercontent.com/preservim/nerdcommenter/master/doc/NERD_commenter.txt
|
||||||
```
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Windows</summary>
|
||||||
#### Windows (PowerShell)
|
#### Windows (PowerShell)
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
@@ -56,6 +87,7 @@ $docsuri = 'https://raw.githubusercontent.com/preservim/nerdcommenter/master/doc
|
|||||||
(New-Object Net.WebClient).DownloadFile($pluguri, $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("~\vimfiles\plugin\NERD_commenter.vim"))
|
(New-Object Net.WebClient).DownloadFile($pluguri, $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("~\vimfiles\plugin\NERD_commenter.vim"))
|
||||||
(New-Object Net.WebClient).DownloadFile($docsuri, $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("~\vimfiles\doc\NERD_commenter.txt"))
|
(New-Object Net.WebClient).DownloadFile($docsuri, $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("~\vimfiles\doc\NERD_commenter.txt"))
|
||||||
```
|
```
|
||||||
|
</details>
|
||||||
|
|
||||||
### Post Installation
|
### Post Installation
|
||||||
|
|
||||||
@@ -76,6 +108,9 @@ Please see the vim help system for full documentation of all options: `:help ner
|
|||||||
Several settings can be added to your vimrc to change the default behavior. Some examples:
|
Several settings can be added to your vimrc to change the default behavior. Some examples:
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
|
" Create default mappings
|
||||||
|
let g:NERDCreateDefaultMappings = 1
|
||||||
|
|
||||||
" Add spaces after comment delimiters by default
|
" Add spaces after comment delimiters by default
|
||||||
let g:NERDSpaceDelims = 1
|
let g:NERDSpaceDelims = 1
|
||||||
|
|
||||||
@@ -103,6 +138,8 @@ let g:NERDToggleCheckAllLines = 1
|
|||||||
|
|
||||||
### Default mappings
|
### Default mappings
|
||||||
|
|
||||||
|
> **Note:** You can turn off settings default mappings to provide your own from scratch (look at the [Settings list](#settings) above)
|
||||||
|
|
||||||
The following key mappings are provided by default (there is also a menu provided that contains menu items corresponding to all the below mappings):
|
The following key mappings are provided by default (there is also a menu provided that contains menu items corresponding to all the below mappings):
|
||||||
|
|
||||||
Most of the following mappings are for normal/visual mode only. The **|NERDCommenterInsert|** mapping is for insert mode only.
|
Most of the following mappings are for normal/visual mode only. The **|NERDCommenterInsert|** mapping is for insert mode only.
|
||||||
@@ -160,6 +197,14 @@ Most of the following mappings are for normal/visual mode only. The **|NERDComme
|
|||||||
|
|
||||||
Uncomments the selected line(s).
|
Uncomments the selected line(s).
|
||||||
|
|
||||||
|
## Motions
|
||||||
|
|
||||||
|
While the plugin does not directly support motions, you can leverage its support for selections to do something very similar. For example, to add motions to toggle comments on the paragraph text object you could use:
|
||||||
|
```vim
|
||||||
|
nnoremap <silent> <leader>c} V}:call NERDComment('x', 'toggle')<CR>
|
||||||
|
nnoremap <silent> <leader>c{ V{:call NERDComment('x', 'toggle')<CR>
|
||||||
|
```
|
||||||
|
|
||||||
## Contributions
|
## Contributions
|
||||||
|
|
||||||
This plugin was originally written in 2007 by [Martin Grenfell (@scrooloose)](https://github.com/scrooloose/). Lots of features and many of the supported filetypes have come from [community contributors](https://github.com/preservim/nerdcommenter/graphs/contributors). Since 2016 it has been maintained primarily by [Caleb Maclennan (@alerque)](https://github.com/alerque). Additional file type support, bug fixes, and new feature contributons are all welcome, please send them as Pull Requests on Github. If you can't contribute yourself please also feel free to open issues to report problems or request features.
|
This plugin was originally written in 2007 by [Martin Grenfell (@scrooloose)](https://github.com/scrooloose/). Lots of features and many of the supported filetypes have come from [community contributors](https://github.com/preservim/nerdcommenter/graphs/contributors). Since 2016 it has been maintained primarily by [Caleb Maclennan (@alerque)](https://github.com/alerque). Additional file type support, bug fixes, and new feature contributons are all welcome, please send them as Pull Requests on Github. If you can't contribute yourself please also feel free to open issues to report problems or request features.
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ let s:delimiterMap = {
|
|||||||
\ 'bc': { 'left': '#' },
|
\ 'bc': { 'left': '#' },
|
||||||
\ 'bib': { 'left': '//' },
|
\ 'bib': { 'left': '//' },
|
||||||
\ 'bindzone': { 'left': ';' },
|
\ 'bindzone': { 'left': ';' },
|
||||||
|
\ 'bind-named': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||||
\ 'blade': { 'left': '{{--', 'right': '--}}' },
|
\ 'blade': { 'left': '{{--', 'right': '--}}' },
|
||||||
\ 'bst': { 'left': '%' },
|
\ 'bst': { 'left': '%' },
|
||||||
\ 'btm': { 'left': '::' },
|
\ 'btm': { 'left': '::' },
|
||||||
@@ -114,6 +115,7 @@ let s:delimiterMap = {
|
|||||||
\ 'cucumber': { 'left': '#' },
|
\ 'cucumber': { 'left': '#' },
|
||||||
\ 'cuda': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
\ 'cuda': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||||
\ 'cvs': { 'left': 'CVS:' },
|
\ 'cvs': { 'left': 'CVS:' },
|
||||||
|
\ 'cypher': { 'left': '//' },
|
||||||
\ 'cython': { 'left': '# ', 'leftAlt': '#' },
|
\ 'cython': { 'left': '# ', 'leftAlt': '#' },
|
||||||
\ 'd': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
\ 'd': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||||
\ 'dakota': { 'left': '#' },
|
\ 'dakota': { 'left': '#' },
|
||||||
@@ -148,6 +150,7 @@ let s:delimiterMap = {
|
|||||||
\ 'erlang': { 'left': '%', 'leftAlt': '%%' },
|
\ 'erlang': { 'left': '%', 'leftAlt': '%%' },
|
||||||
\ 'eruby': { 'left': '<%#', 'right': '%>', 'leftAlt': '<!--', 'rightAlt': '-->' },
|
\ 'eruby': { 'left': '<%#', 'right': '%>', 'leftAlt': '<!--', 'rightAlt': '-->' },
|
||||||
\ 'esmtprc': { 'left': '#' },
|
\ 'esmtprc': { 'left': '#' },
|
||||||
|
\ 'exim': { 'left': '#' },
|
||||||
\ 'expect': { 'left': '#' },
|
\ 'expect': { 'left': '#' },
|
||||||
\ 'exports': { 'left': '#' },
|
\ 'exports': { 'left': '#' },
|
||||||
\ 'factor': { 'left': '! ', 'leftAlt': '!# ' },
|
\ 'factor': { 'left': '! ', 'leftAlt': '!# ' },
|
||||||
@@ -196,6 +199,7 @@ let s:delimiterMap = {
|
|||||||
\ 'hbs': { 'left': '{{!-- ', 'right': ' --}}' },
|
\ 'hbs': { 'left': '{{!-- ', 'right': ' --}}' },
|
||||||
\ 'hercules': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
\ 'hercules': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||||
\ 'hive': { 'left': '-- ' },
|
\ 'hive': { 'left': '-- ' },
|
||||||
|
\ 'hocon': { 'left': '//', 'leftAlt': '#' },
|
||||||
\ 'hog': { 'left': '#' },
|
\ 'hog': { 'left': '#' },
|
||||||
\ 'hostsaccess': { 'left': '#' },
|
\ 'hostsaccess': { 'left': '#' },
|
||||||
\ 'htmlcheetah': { 'left': '##' },
|
\ 'htmlcheetah': { 'left': '##' },
|
||||||
@@ -224,6 +228,8 @@ let s:delimiterMap = {
|
|||||||
\ 'jgraph': { 'left': '(*', 'right': '*)' },
|
\ 'jgraph': { 'left': '(*', 'right': '*)' },
|
||||||
\ 'jinja': { 'left': '{#', 'right': '#}', 'leftAlt': '<!--', 'rightAlt': '-->' },
|
\ 'jinja': { 'left': '{#', 'right': '#}', 'leftAlt': '<!--', 'rightAlt': '-->' },
|
||||||
\ 'jproperties': { 'left': '#' },
|
\ 'jproperties': { 'left': '#' },
|
||||||
|
\ 'jsonc': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||||
|
\ 'jsonnet': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||||
\ 'jsp': { 'left': '<%--', 'right': '--%>' },
|
\ 'jsp': { 'left': '<%--', 'right': '--%>' },
|
||||||
\ 'julia': { 'left': '# ', 'leftAlt': '#=', 'rightAlt': '=#' },
|
\ 'julia': { 'left': '# ', 'leftAlt': '#=', 'rightAlt': '=#' },
|
||||||
\ 'kivy': { 'left': '#' },
|
\ 'kivy': { 'left': '#' },
|
||||||
@@ -285,6 +291,7 @@ let s:delimiterMap = {
|
|||||||
\ 'newlisp': { 'left': ';' },
|
\ 'newlisp': { 'left': ';' },
|
||||||
\ 'nginx': { 'left': '#' },
|
\ 'nginx': { 'left': '#' },
|
||||||
\ 'nimrod': { 'left': '#' },
|
\ 'nimrod': { 'left': '#' },
|
||||||
|
\ 'nix': { 'left': '#' },
|
||||||
\ 'nroff': { 'left': '\"' },
|
\ 'nroff': { 'left': '\"' },
|
||||||
\ 'nsis': { 'left': '#' },
|
\ 'nsis': { 'left': '#' },
|
||||||
\ 'ntp': { 'left': '#' },
|
\ 'ntp': { 'left': '#' },
|
||||||
@@ -343,12 +350,13 @@ let s:delimiterMap = {
|
|||||||
\ 'rc': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
\ 'rc': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||||
\ 'rebol': { 'left': ';' },
|
\ 'rebol': { 'left': ';' },
|
||||||
\ 'registry': { 'left': ';' },
|
\ 'registry': { 'left': ';' },
|
||||||
|
\ 'rego': { 'left': '#' },
|
||||||
\ 'remind': { 'left': '#' },
|
\ 'remind': { 'left': '#' },
|
||||||
\ 'renpy': { 'left': '# ' },
|
\ 'renpy': { 'left': '# ' },
|
||||||
\ 'resolv': { 'left': '#' },
|
\ 'resolv': { 'left': '#' },
|
||||||
\ 'rgb': { 'left': '!' },
|
\ 'rgb': { 'left': '!' },
|
||||||
\ 'rib': { 'left': '#' },
|
\ 'rib': { 'left': '#' },
|
||||||
\ 'rmd': { 'left': '<!--', 'right': '-->', 'leftalt': '#' },
|
\ 'rmd': { 'left': '<!--', 'right': '-->', 'leftAlt': '#' },
|
||||||
\ 'robot': { 'left': '#' },
|
\ 'robot': { 'left': '#' },
|
||||||
\ 'robots': { 'left': '#' },
|
\ 'robots': { 'left': '#' },
|
||||||
\ 'rspec': { 'left': '#' },
|
\ 'rspec': { 'left': '#' },
|
||||||
@@ -439,6 +447,7 @@ let s:delimiterMap = {
|
|||||||
\ 'typescript': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
\ 'typescript': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||||
\ 'typescriptreact': { 'left': '//', 'leftAlt': '{/*', 'rightAlt': '*/}' },
|
\ 'typescriptreact': { 'left': '//', 'leftAlt': '{/*', 'rightAlt': '*/}' },
|
||||||
\ 'uc': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
\ 'uc': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||||
|
\ 'uc4': { 'left': '!' },
|
||||||
\ 'uil': { 'left': '!' },
|
\ 'uil': { 'left': '!' },
|
||||||
\ 'upstart': { 'left': '#' },
|
\ 'upstart': { 'left': '#' },
|
||||||
\ 'vala': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
\ 'vala': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
|
||||||
@@ -696,7 +705,7 @@ function s:CommentBlock(top, bottom, lSide, rSide, forceNested )
|
|||||||
"alternative delimiters (if THEY are) as the comment will be better and more
|
"alternative delimiters (if THEY are) as the comment will be better and more
|
||||||
"accurate with multipart delimiters
|
"accurate with multipart delimiters
|
||||||
let switchedDelims = 0
|
let switchedDelims = 0
|
||||||
if !s:Multipart() && g:NERDAllowAnyVisualDelims && s:AltMultipart()
|
if !s:Multipart() && !g:NERDAllowAnyVisualDelims && s:AltMultipart()
|
||||||
let switchedDelims = 1
|
let switchedDelims = 1
|
||||||
call s:SwitchToAlternativeDelimiters(0)
|
call s:SwitchToAlternativeDelimiters(0)
|
||||||
endif
|
endif
|
||||||
@@ -734,7 +743,9 @@ function s:CommentBlock(top, bottom, lSide, rSide, forceNested )
|
|||||||
|
|
||||||
if s:Multipart()
|
if s:Multipart()
|
||||||
"stick the right delimiter down
|
"stick the right delimiter down
|
||||||
let theLine = strpart(theLine, 0, rSide+strlen(leftSpaced)) . rightSpaced . strpart(theLine, rSide+strlen(leftSpaced))
|
"byte idx of the char next to the last char = (byte idx of last char + 1) + (last char byte len) - 1
|
||||||
|
let rIndex = (rSide+strlen(leftSpaced)) + strlen(strcharpart(strpart(theLine, rSide+strlen(leftSpaced)-1), 0, 1)) - 1
|
||||||
|
let theLine = strpart(theLine, 0, rIndex) . rightSpaced . strpart(theLine, rIndex)
|
||||||
|
|
||||||
let firstLeftDelim = s:FindDelimiterIndex(s:Left(), theLine)
|
let firstLeftDelim = s:FindDelimiterIndex(s:Left(), theLine)
|
||||||
let lastRightDelim = s:LastIndexOfDelim(s:Right(), theLine)
|
let lastRightDelim = s:LastIndexOfDelim(s:Right(), theLine)
|
||||||
@@ -2142,7 +2153,7 @@ endfunction
|
|||||||
" Function: s:Esc(str)
|
" Function: s:Esc(str)
|
||||||
" Escapes all the tricky chars in the given string
|
" Escapes all the tricky chars in the given string
|
||||||
function s:Esc(str)
|
function s:Esc(str)
|
||||||
let charsToEsc = '*/\."&$+'
|
let charsToEsc = '*/\."&$+[]'
|
||||||
return escape(a:str, charsToEsc)
|
return escape(a:str, charsToEsc)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user