Merge branch 'master' into autoload

This commit is contained in:
Caleb Maclennan
2021-07-20 12:46:30 +03:00
2 changed files with 60 additions and 4 deletions

View File

@@ -8,33 +8,61 @@ Comment functions so powerful—no comment necessary.
### Via Plugin Manager (Recommended)
<details>
<summary>Vim Plug</summary>
#### [Vim-Plug](https://github.com/junegunn/vim-plug)
1. Add `Plug 'preservim/nerdcommenter'` to your vimrc file.
2. Reload your vimrc or restart
3. Run `:PlugInstall`
</details>
<details>
<summary>Vundle</summary>
#### [Vundle](https://github.com/VundleVim/Vundle.vim) or similar
1. Add `Plugin 'preservim/nerdcommenter'` to your vimrc file.
2. Reload your vimrc or restart
3. Run `:BundleInstall`
</details>
<details>
<summary>NeoBundle</summary>
#### [NeoBundle](https://github.com/Shougo/neobundle.vim)
1. Add `NeoBundle 'preservim/nerdcommenter'` to your vimrc file.
2. Reload your vimrc or restart
3. Run `:NeoUpdate`
</details>
<details>
<summary>Pathogen</summary>
#### [Pathogen](https://github.com/tpope/vim-pathogen)
```sh
cd ~/.vim/bundle
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
<details>
<summary>Unix</summary>
#### Unix
(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 \
https://raw.githubusercontent.com/preservim/nerdcommenter/master/doc/NERD_commenter.txt
```
</details>
<details>
<summary>Windows</summary>
#### Windows (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($docsuri, $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("~\vimfiles\doc\NERD_commenter.txt"))
```
</details>
### 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:
```vim
" Create default mappings
let g:NERDCreateDefaultMappings = 1
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
@@ -103,6 +138,8 @@ let g:NERDToggleCheckAllLines = 1
### 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):
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).
## 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
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.

View File

@@ -84,6 +84,7 @@ let s:delimiterMap = {
\ 'bc': { 'left': '#' },
\ 'bib': { 'left': '//' },
\ 'bindzone': { 'left': ';' },
\ 'bind-named': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'blade': { 'left': '{{--', 'right': '--}}' },
\ 'bst': { 'left': '%' },
\ 'btm': { 'left': '::' },
@@ -114,6 +115,7 @@ let s:delimiterMap = {
\ 'cucumber': { 'left': '#' },
\ 'cuda': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'cvs': { 'left': 'CVS:' },
\ 'cypher': { 'left': '//' },
\ 'cython': { 'left': '# ', 'leftAlt': '#' },
\ 'd': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'dakota': { 'left': '#' },
@@ -148,6 +150,7 @@ let s:delimiterMap = {
\ 'erlang': { 'left': '%', 'leftAlt': '%%' },
\ 'eruby': { 'left': '<%#', 'right': '%>', 'leftAlt': '<!--', 'rightAlt': '-->' },
\ 'esmtprc': { 'left': '#' },
\ 'exim': { 'left': '#' },
\ 'expect': { 'left': '#' },
\ 'exports': { 'left': '#' },
\ 'factor': { 'left': '! ', 'leftAlt': '!# ' },
@@ -196,6 +199,7 @@ let s:delimiterMap = {
\ 'hbs': { 'left': '{{!-- ', 'right': ' --}}' },
\ 'hercules': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'hive': { 'left': '-- ' },
\ 'hocon': { 'left': '//', 'leftAlt': '#' },
\ 'hog': { 'left': '#' },
\ 'hostsaccess': { 'left': '#' },
\ 'htmlcheetah': { 'left': '##' },
@@ -224,6 +228,8 @@ let s:delimiterMap = {
\ 'jgraph': { 'left': '(*', 'right': '*)' },
\ 'jinja': { 'left': '{#', 'right': '#}', 'leftAlt': '<!--', 'rightAlt': '-->' },
\ 'jproperties': { 'left': '#' },
\ 'jsonc': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'jsonnet': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'jsp': { 'left': '<%--', 'right': '--%>' },
\ 'julia': { 'left': '# ', 'leftAlt': '#=', 'rightAlt': '=#' },
\ 'kivy': { 'left': '#' },
@@ -285,6 +291,7 @@ let s:delimiterMap = {
\ 'newlisp': { 'left': ';' },
\ 'nginx': { 'left': '#' },
\ 'nimrod': { 'left': '#' },
\ 'nix': { 'left': '#' },
\ 'nroff': { 'left': '\"' },
\ 'nsis': { 'left': '#' },
\ 'ntp': { 'left': '#' },
@@ -343,12 +350,13 @@ let s:delimiterMap = {
\ 'rc': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'rebol': { 'left': ';' },
\ 'registry': { 'left': ';' },
\ 'rego': { 'left': '#' },
\ 'remind': { 'left': '#' },
\ 'renpy': { 'left': '# ' },
\ 'resolv': { 'left': '#' },
\ 'rgb': { 'left': '!' },
\ 'rib': { 'left': '#' },
\ 'rmd': { 'left': '<!--', 'right': '-->', 'leftalt': '#' },
\ 'rmd': { 'left': '<!--', 'right': '-->', 'leftAlt': '#' },
\ 'robot': { 'left': '#' },
\ 'robots': { 'left': '#' },
\ 'rspec': { 'left': '#' },
@@ -439,6 +447,7 @@ let s:delimiterMap = {
\ 'typescript': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'typescriptreact': { 'left': '//', 'leftAlt': '{/*', 'rightAlt': '*/}' },
\ 'uc': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'uc4': { 'left': '!' },
\ 'uil': { 'left': '!' },
\ 'upstart': { 'left': '#' },
\ '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
"accurate with multipart delimiters
let switchedDelims = 0
if !s:Multipart() && g:NERDAllowAnyVisualDelims && s:AltMultipart()
if !s:Multipart() && !g:NERDAllowAnyVisualDelims && s:AltMultipart()
let switchedDelims = 1
call s:SwitchToAlternativeDelimiters(0)
endif
@@ -734,7 +743,9 @@ function s:CommentBlock(top, bottom, lSide, rSide, forceNested )
if s:Multipart()
"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 lastRightDelim = s:LastIndexOfDelim(s:Right(), theLine)
@@ -2142,7 +2153,7 @@ endfunction
" Function: s:Esc(str)
" Escapes all the tricky chars in the given string
function s:Esc(str)
let charsToEsc = '*/\."&$+'
let charsToEsc = '*/\."&$+[]'
return escape(a:str, charsToEsc)
endfunction