rewrite the key mappings part of the script

internal <plug> mappings are now used for all the commenting operations.
Key mappings are no longer specified with options. Instead the user must
create their own mappings to the internal <plug> mappings.
This commit is contained in:
Martin Grenfell 2008-09-21 11:08:49 +12:00
parent 27e8727a35
commit b54d3bbc92
2 changed files with 198 additions and 243 deletions

View File

@ -35,14 +35,14 @@ CONTENTS *NERDCommenterContents*
3.1 Options summary...................|NERDComOptionsSummary|
3.2 Options details...................|NERDComOptionsDetails|
3.3 Default delimiter Options.........|NERDComDefaultDelims|
3.4 Key mapping Options...............|NERDComMappings|
4.Issues with the script..................|NERDComIssues|
4.1 Delimiter detection heuristics....|NERDComHeuristics|
4.2 Nesting issues....................|NERDComNesting|
5.The author..............................|NERDComAuthor|
6.Changelog...............................|NERDComChangelog|
7.Credits.................................|NERDComCredits|
8.License.................................|NERDComLicense|
4. Customising key mappings...............|NERDComMappings|
5. Issues with the script.................|NERDComIssues|
5.1 Delimiter detection heuristics....|NERDComHeuristics|
5.2 Nesting issues....................|NERDComNesting|
6.The author..............................|NERDComAuthor|
7.Changelog...............................|NERDComChangelog|
8.Credits.................................|NERDComCredits|
9.License.................................|NERDComLicense|
==============================================================================
1. Intro *NERDCommenter*
@ -66,47 +66,48 @@ provided that contains menu items corresponding to all the below mappings):
Most of the following mappings are for normal/visual mode only. The
|NERDComInsertComment| mapping is for insert mode only.
[count],cc |NERDComComment|
Comments out the current line or text selected in visual mode.
[count]<leader>cc |NERDComComment|
Comment out the current line or text selected in visual mode.
[count],cn |NERDComNestedComment|
Same as |NERDComComment| but forces nesting.
[count]<leader>cn |NERDComNestedComment|
Same as but forces nesting.
[count],c<space> |NERDComToggleComment|
[count]<leader>c<space> |NERDComToggleComment|
Toggles the comment state of the selected line(s). If the topmost selected
line is commented, all selected lines are uncommented and vice versa.
[count],cm |NERDComMinimalComment|
[count]<leader>cm |NERDComMinimalComment|
Comments the given lines using only one set of multipart delimiters if
possible.
[count],ci |NERDComInvertComment|
[count]<leader>ci |NERDComInvertComment|
Toggles the comment state of the selected line(s) individually. Each selected
line that is commented is uncommented and vice versa.
[count],cs |NERDComSexyComment|
[count]<leader>cs |NERDComSexyComment|
Comments out the selected lines ``sexily''
[count],cy |NERDComYankComment|
[count]<leader>cy |NERDComYankComment|
Same as |NERDComComment| except that the commented line(s) are yanked
before commenting.
,c$ |NERDComEOLComment|
<leader>c$ |NERDComEOLComment|
Comments the current line from the cursor to the end of line.
,cA |NERDComAppendComment|
<leader>cA |NERDComAppendComment|
Adds comment delimiters to the end of line and goes into insert mode between
them.
,cI |NERDComPrependComment|
<leader>cI |NERDComPrependComment|
Adds comment delimiters to the start of line and goes into insert mode between
them.
@ -116,19 +117,19 @@ Adds comment delimiters at the current cursor position and inserts between.
Disabled by default.
,ca |NERDComAltDelim|
<leader>ca |NERDComAltDelim|
Switches to the alternative set of delimiters.
[count],cl
[count],cr
[count],cb |NERDComAlignedComment|
[count]<leader>cl
[count]<leader>cr
[count]<leader>cb |NERDComAlignedComment|
Same as |NERDComComment| except that the delimiters are aligned down the
left side (,cl), the right side (,cr) or both sides
(,cb).
left side (<leader>cl), the right side (<leader>cr) or both sides
(<leader>cb).
[count],cu |NERDComUncommentLine|
[count]<leader>cu |NERDComUncommentLine|
Uncomments the selected line(s).
------------------------------------------------------------------------------
@ -137,8 +138,8 @@ Uncomments the selected line(s).
------------------------------------------------------------------------------
2.2.1 Comment map *NERDComComment*
Default mapping: [count],cc
Change the mapping with: NERDComLineMap.
Default mapping: [count]<leader>cc
Mapped to: <plug>NERDCommenterComment
Applicable modes: normal visual visual-line visual-block.
@ -153,11 +154,11 @@ lines were selected in visual-line mode.
------------------------------------------------------------------------------
2.2.2 Nested comment map *NERDComNestedComment*
Default mapping: [count],cn
Change the mapping with: NERDComLineNestMap.
Default mapping: [count]<leader>cn
Mapped to: <plug>NERDCommenterNest
Applicable modes: normal visual visual-line visual-block.
Performs nested commenting. Works the same as ,cc except that if a
Performs nested commenting. Works the same as <leader>cc except that if a
line is already commented then it will be commented again.
If |NERDUsePlaceHolders| is set then the previous comment delimiters will
@ -174,8 +175,8 @@ Related options:
------------------------------------------------------------------------------
2.2.3 Toggle comment map *NERDComToggleComment*
Default mapping: [count],c<space>
Change the mapping with: NERDComLineToggleMap.
Default mapping: [count]<leader>c<space>
Mapped to: <plug>NERDCommenterToggle
Applicable modes: normal visual-line.
Toggles commenting of the lines selected. The behaviour of this mapping
@ -191,14 +192,14 @@ lines were selected in visual-line mode.
------------------------------------------------------------------------------
2.2.4 Minimal comment map *NERDComMinimalComment*
Default mapping: [count],cm
Change the mapping with: NERDComLineMinimalMap
Default mapping: [count]<leader>cm
Mapped to: <plug>NERDCommenterMinimal
Applicable modes: normal visual-line.
Comments the selected lines using one set of multipart delimiters if possible.
For example: if you are programming in c and you select 5 lines and press
,cm then a '/*' will be placed at the start of the top line and a '*/'
<leader>cm then a '/*' will be placed at the start of the top line and a '*/'
will be placed at the end of the last line.
Sets of multipart comment delimiters that are between the top and bottom
@ -213,8 +214,8 @@ lines were selected in visual-line mode.
------------------------------------------------------------------------------
2.2.5 Invert comment map *NERDComInvertComment*
Default mapping: ,ci
Change the mapping with: NERDComLineInvertMap.
Default mapping: <leader>ci
Mapped to: <plug>NERDCommenterInvert
Applicable modes: normal visual-line.
Inverts the commented state of each selected line. If the a selected line is
@ -230,8 +231,8 @@ lines were selected in visual-line mode.
------------------------------------------------------------------------------
2.2.6 Sexy comment map *NERDComSexyComment*
Default mapping: [count],cs
Change the mapping with: NERDComLineSexyMap
Default mapping: [count]<leader>cs
Mapped to: <plug>NERDCommenterSexy
Applicable modes: normal, visual-line.
Comments the selected line(s) ``sexily''... see |NERDComSexyComments| for
@ -250,17 +251,17 @@ Related options:
------------------------------------------------------------------------------
2.2.7 Yank comment map *NERDComYankComment*
Default mapping: [count],cy
Change the mapping with: NERDComLineYankMap
Default mapping: [count]<leader>cy
Mapped to: <plug>NERDCommenterYank
Applicable modes: normal visual visual-line visual-block.
Same as ,cc except that it yanks the line(s) that are commented first.
Same as <leader>cc except that it yanks the line(s) that are commented first.
------------------------------------------------------------------------------
2.2.8 Comment to EOL map *NERDComEOLComment*
Default mapping: ,c$
Change the mapping with: NERDComToEOLMap
Default mapping: <leader>c$
Mapped to: <plug>NERDCommenterToEOL
Applicable modes: normal.
Comments the current line from the current cursor position up to the end of
@ -269,8 +270,8 @@ the line.
------------------------------------------------------------------------------
2.2.9 Append com to line map *NERDComAppendComment*
Default mapping: ,cA
Change the mapping with: NERDAppendComMap.
Default mapping: <leader>cA
Mapped to: <plug>NERDCommenterAppend
Applicable modes: normal.
Appends comment delimiters to the end of the current line and goes
@ -279,8 +280,8 @@ to insert mode between the new delimiters.
------------------------------------------------------------------------------
2.2.10 Prepend com to line map *NERDComPrependComment*
Default mapping: ,cI
Change the mapping with: NERDPrependComMap.
Default mapping: <leader>cI
Mapped to: <plug>NERDCommenterPrepend
Applicable modes: normal.
Prepends comment delimiters to the start of the current line and goes to
@ -290,7 +291,7 @@ insert mode between the new delimiters.
2.2.11 Insert comment map *NERDComInsertComment*
Default mapping: disabled by default.
Change the mapping with: NERDComInInsertMap.
Map it to: <plug>NERDCommenterInInsert
Applicable modes: insert.
Adds comment delimiters at the current cursor position and inserts
@ -305,12 +306,12 @@ to your vimrc.
------------------------------------------------------------------------------
2.2.12 Use alternate delims map *NERDComAltDelim*
Default mapping: ,ca
Change the mapping with: NERDAltComMap
Default mapping: <leader>ca
Mapped to: <plug>NERDCommenterAltDelims
Applicable modes: normal.
Changes to the alternative commenting style if one is available. For example,
if the user is editing a c++ file using // comments and they hit ,ca
if the user is editing a c++ file using // comments and they hit <leader>ca
then they will be switched over to /**/ comments.
See also |NERDComDefaultDelims|
@ -318,12 +319,13 @@ See also |NERDComDefaultDelims|
------------------------------------------------------------------------------
2.2.13 Comment aligned maps *NERDComAlignedComment*
Default mappings: [count],cl [count],cr [count],cb
Change the mappings with: NERDComAlignLeftMap, NERDComAlignRightMap and
NERDComAlignBothMap.
Default mappings: [count]<leader>cl [count]<leader>cr [count]<leader>cb
Mapped to: <plug>NERDCommenterAlignLeft
<plug>NERDCommenterAlignRight
<plug>NERDCommenterAlignBoth
Applicable modes: normal visual-line.
Same as ,cc except that the comment delimiters are aligned on the left
Same as <leader>cc except that the comment delimiters are aligned on the left
side, right side or both sides respectively. These comments are always nested
if the line(s) are already commented.
@ -333,8 +335,8 @@ lines were selected in visual-line mode.
------------------------------------------------------------------------------
2.2.14 Uncomment line map *NERDComUncommentLine*
Default mapping: [count],cu
Change the mapping with: NERDUncomLineMap.
Default mapping: [count]<leader>cu
Mapped to: <plug>NERDCommenterUncomment
Applicable modes: normal visual visual-line visual-block.
Uncomments the current line. If multiple lines are selected in
@ -440,6 +442,7 @@ then the script would do a sexy comment on the last visual selection.
|NERDBlockComIgnoreEmpty| Forces right delims to be placed when
doing visual-block comments.
|NERDCommentWholeLinesInVMode| Changes behaviour of visual comments.
|NERDCreateDefaultMappings| Turn the default mappings on/off.
|NERDDefaultNesting| Tells the script to use nested comments
by default.
|NERDMenuMode| Specifies how the NERD commenter menu
@ -447,8 +450,6 @@ then the script would do a sexy comment on the last visual selection.
|NERDLPlace| Specifies what to use as the left
delimiter placeholder when nesting
comments.
|NERDMapleader| Specifies what all the commenting key
mappings will begin with.
|NERDUsePlaceHolders| Specifies which filetypes may use
placeholders when nesting comments.
|NERDRemoveAltComs| Tells the script whether to remove
@ -588,6 +589,15 @@ then stick the following line in your vimrc: >
Note that this option does not affect the behaviour of |visual-block| mode.
------------------------------------------------------------------------------
*NERDCreateDefaultMappings*
Values: 0 or 1.
Default: 1.
If set to 0, none of the default mappings will be created.
See also |NERDComMappings|.
------------------------------------------------------------------------------
*NERDRemoveAltComs*
Values: 0 or 1.
@ -598,7 +608,7 @@ this option tells the script whether to look for, and remove, comments
delimiters of the alternative style.
For example, if you are editing a c++ file using // style comments and you go
,cu on this line: >
<leader>cu on this line: >
/* This is a c++ comment baby! */
<
It will not be uncommented if the NERDRemoveAltComs is set to 0.
@ -650,41 +660,11 @@ To set these options use lines like: >
Following the above example, if we have line of c code: >
/* int horse */
<
and we comment it with ,cn it will be changed to: >
and we comment it with <leader>cn it will be changed to: >
/*FOO int horse BAR*/
<
When we uncomment this line it will go back to what it was.
------------------------------------------------------------------------------
*NERDMapleader*
Values: arbitrary string.
Default: ,c
NERDMapleader is used to specify what all the NERD commenter key mappings
begin with.
The default key mappings will look like this: >
,cc
,cu
,ca
,ci
,cs
...
<
However, if this line: >
let NERDMapleader = ',x'
<
were present in your vimrc then the default mappings would look like this: >
,xc
,xu
,xa
,xi
,xs
...
<
This option only affects the mappings that have not been explicitly set
manually (see |NERDComMappings|).
------------------------------------------------------------------------------
*NERDMenuMode*
Values: 0, 1, 2, 3.
@ -754,7 +734,7 @@ Values: 0 or 1.
Default 1.
When this option is set to 1, comments are nested automatically. That is, if
you hit ,cc on a line that is already commented it will be commented
you hit <leader>cc on a line that is already commented it will be commented
again
------------------------------------------------------------------------------
@ -771,42 +751,30 @@ Example: java uses // style comments by default, but you want it to default to
See |NERDComAltDelim| for switching commenting styles at runtime.
------------------------------------------------------------------------------
3.4 Key mapping customisation *NERDComMappings*
==============================================================================
4. Key mapping customisation *NERDComMappings*
These options are used to override the default keys that are used for the
commenting mappings. Their values must be set to strings. As an example: if
you wanted to use the mapping ,foo to uncomment lines of code then
you would place this line in your vimrc >
let NERDUncomLineMap=",foo"
To change a mapping just map another key combo to the internal <plug> mapping.
For example, to remap the *NERDComComment* mapping to ",omg" you would put
these lines in your vimrc: >
nmap ,omg <plug>NERDCommenterComment
vmap ,omg <plug>NERDCommenterComment
<
Check out |NERDComFunctionality| for details about what the following
mappings do.
This will stop the corresponding default mappings from being created. Note: in
this case if you only override the nmap, then the default vmap will still be
created.
Default Mapping Option to override~
See the help for the mapping in question to see which <plug> mapping to
map to, and which modes it applies to.
,ca NERDAltComMap
,ce NERDAppendComMap
,cl NERDComAlignLeftMap
,cb NERDComAlignBothMap
,cr NERDComAlignRightMap
<C-c> NERDComInInsertMap
,ci NERDComLineInvertMap
,cc NERDComLineMap
,cn NERDComLineNestMap
,cs NERDComLineSexyMap
,c<space> NERDComLineToggleMap
,cm NERDComLineMinimalMap
,c$ NERDComToEOLMap
,cy NERDComLineYankMap
,cu NERDUncomLineMap
See also |NERDCreateDefaultMappings|.
==============================================================================
4. Issues with the script *NERDComIssues*
5. Issues with the script *NERDComIssues*
------------------------------------------------------------------------------
4.1 Delimiter detection heuristics *NERDComHeuristics*
5.1 Delimiter detection heuristics *NERDComHeuristics*
Heuristics are used to distinguish the real comment delimiters
@ -826,7 +794,7 @@ string. These heuristics, while usually pretty accurate, will not work for all
cases.
------------------------------------------------------------------------------
4.2 Nesting issues *NERDComNesting*
5.2 Nesting issues *NERDComNesting*
If we have some line of code like this: >
/*int foo */ = /*5 + 9;*/
@ -846,7 +814,7 @@ will become: >
for simplicity)
==============================================================================
5. The author *NERDComAuthor*
6. The author *NERDComAuthor*
The author of the NERD commenter is Martyzillatron --- the half robot, half
dinosaur bastard son of Megatron and Godzilla. He enjoys destroying
@ -857,7 +825,7 @@ its a lonely life being the worlds premier terror machine. How would you feel
if your face looked like a toaster and a t-rex put together? :(
==============================================================================
7. Changelog *NERDComChangelog*
8. Changelog *NERDComChangelog*
2.x.x
- add support for potwiki. Thanks to Bernhard Grotz for the email.
@ -1089,7 +1057,7 @@ if your face looked like a toaster and a t-rex put together? :(
information.
==============================================================================
7. Credits *NERDComCredits*
8. Credits *NERDComCredits*
Thanks and respect to the following people:
@ -1293,7 +1261,7 @@ Bernhard Grotz potwiki
sgronblo man
==============================================================================
8. License *NERDComLicense*
9. License *NERDComLicense*
The NERD commenter is released under the wtfpl.
See http://sam.zoy.org/wtfpl/COPYING.

View File

@ -59,6 +59,7 @@ call s:InitVariable("g:NERDAllowAnyVisualDelims", 1)
call s:InitVariable("g:NERDBlockComIgnoreEmpty", 0)
call s:InitVariable("g:NERDCommentWholeLinesInVMode", 0)
call s:InitVariable("g:NERDCompactSexyComs", 0)
call s:InitVariable("g:NERDCreateDefaultMappings", 1)
call s:InitVariable("g:NERDDefaultNesting", 1)
call s:InitVariable("g:NERDMenuMode", 3)
call s:InitVariable("g:NERDLPlace", "[>")
@ -70,24 +71,8 @@ call s:InitVariable("g:NERDShutUp", '0')
call s:InitVariable("g:NERDSpaceDelims", 0)
call s:InitVariable("g:NERDDelimiterRequests", 1)
call s:InitVariable("g:NERDMapleader", ',c')
call s:InitVariable("g:NERDAltComMap", g:NERDMapleader . 'a')
call s:InitVariable("g:NERDAppendComMap", g:NERDMapleader . 'A')
call s:InitVariable("g:NERDComAlignBothMap", g:NERDMapleader . 'b')
call s:InitVariable("g:NERDComAlignLeftMap", g:NERDMapleader . 'l')
call s:InitVariable("g:NERDComAlignRightMap", g:NERDMapleader . 'r')
call s:InitVariable("g:NERDComInInsertMap", '')
call s:InitVariable("g:NERDComLineInvertMap", g:NERDMapleader . 'i')
call s:InitVariable("g:NERDComLineMap", g:NERDMapleader . 'c')
call s:InitVariable("g:NERDComLineNestMap", g:NERDMapleader . 'n')
call s:InitVariable("g:NERDComLineSexyMap", g:NERDMapleader . 's')
call s:InitVariable("g:NERDComLineToggleMap", g:NERDMapleader . '<space>')
call s:InitVariable("g:NERDComLineMinimalMap", g:NERDMapleader . 'm')
call s:InitVariable("g:NERDComLineYankMap", g:NERDMapleader . 'y')
call s:InitVariable("g:NERDComToEOLMap", g:NERDMapleader . '$')
call s:InitVariable("g:NERDPrependComMap", g:NERDMapleader . 'I')
call s:InitVariable("g:NERDUncomLineMap", g:NERDMapleader . 'u')
let s:NERDFileNameEscape="[]#*$%'\" ?`!&();<>\\"
" Section: Comment mapping functions, autocommands and commands {{{1
@ -3243,70 +3228,100 @@ function s:UntabbedCol(line, col)
endfunction
" Section: Comment mapping setup {{{1
" ===========================================================================
" This is where the mappings calls are made that set up the commenting key
" mappings.
" set up the mapping to switch to/from alternative delimiters
execute 'nnoremap <silent>' . g:NERDAltComMap . ' :call <SID>SwitchToAlternativeDelimiters(1)<cr>'
" switch to/from alternative delimiters
nnoremap <plug>NERDCommenterAltDelims :call <SID>SwitchToAlternativeDelimiters(1)<cr>
" set up the mappings to comment out lines
execute 'nnoremap <silent>' . g:NERDComLineMap . ' :call NERDComment(0, "norm")<cr>'
execute 'vnoremap <silent>' . g:NERDComLineMap . ' <ESC>:call NERDComment(1, "norm")<cr>'
" comment out lines
nnoremap <silent> <plug>NERDCommenterComment :call NERDComment(0, "norm")<cr>
vnoremap <silent> <plug>NERDCommenterComment <ESC>:call NERDComment(1, "norm")<cr>
" set up the mappings to do toggle comments
execute 'nnoremap <silent>' . g:NERDComLineToggleMap . ' :call NERDComment(0, "toggle")<cr>'
execute 'vnoremap <silent>' . g:NERDComLineToggleMap . ' <ESC>:call NERDComment(1, "toggle")<cr>'
" toggle comments
nnoremap <silent> <plug>NERDCommenterToggle :call NERDComment(0, "toggle")<cr>
vnoremap <silent> <plug>NERDCommenterToggle <ESC>:call NERDComment(1, "toggle")<cr>
" set up the mapp to do minimal comments
execute 'nnoremap <silent>' . g:NERDComLineMinimalMap . ' :call NERDComment(0, "minimal")<cr>'
execute 'vnoremap <silent>' . g:NERDComLineMinimalMap . ' <ESC>:call NERDComment(1, "minimal")<cr>'
" minimal comments
nnoremap <silent> <plug>NERDCommenterMinimal :call NERDComment(0, "minimal")<cr>
vnoremap <silent> <plug>NERDCommenterMinimal <ESC>:call NERDComment(1, "minimal")<cr>
" set up the mappings to comment out lines sexily
execute 'nnoremap <silent>' . g:NERDComLineSexyMap . ' :call NERDComment(0, "sexy")<CR>'
execute 'vnoremap <silent>' . g:NERDComLineSexyMap . ' <ESC>:call NERDComment(1, "sexy")<CR>'
" sexy comments
nnoremap <silent> <plug>NERDCommenterSexy :call NERDComment(0, "sexy")<CR>
vnoremap <silent> <plug>NERDCommenterSexy <ESC>:call NERDComment(1, "sexy")<CR>
" set up the mappings to do invert comments
execute 'nnoremap <silent>' . g:NERDComLineInvertMap . ' :call NERDComment(0, "invert")<CR>'
execute 'vnoremap <silent>' . g:NERDComLineInvertMap . ' <ESC>:call NERDComment(1, "invert")<CR>'
" invert comments
nnoremap <silent> <plug>NERDCommenterInvert :call NERDComment(0, "invert")<CR>
vnoremap <silent> <plug>NERDCommenterInvert <ESC>:call NERDComment(1, "invert")<CR>
" set up the mappings to yank then comment out lines
execute 'nmap <silent>' . g:NERDComLineYankMap . ' :call NERDComment(0, "yank")<CR>'
execute 'vmap <silent>' . g:NERDComLineYankMap . ' <ESC>:call NERDComment(1, "yank")<CR>'
" yank then comment
nmap <silent> <plug>NERDCommenterYank :call NERDComment(0, "yank")<CR>
vmap <silent> <plug>NERDCommenterYank <ESC>:call NERDComment(1, "yank")<CR>
" set up the mappings for left aligned comments
execute 'nnoremap <silent>' . g:NERDComAlignLeftMap . ' :call NERDComment(0, "alignLeft")<cr>'
execute 'vnoremap <silent>' . g:NERDComAlignLeftMap . ' <ESC>:call NERDComment(1, "alignLeft")<cr>'
" left aligned comments
nnoremap <silent> <plug>NERDCommenterAlignLeft :call NERDComment(0, "alignLeft")<cr>
vnoremap <silent> <plug>NERDCommenterAlignLeft <ESC>:call NERDComment(1, "alignLeft")<cr>
" set up the mappings for right aligned comments
execute 'nnoremap <silent>' . g:NERDComAlignRightMap . ' :call NERDComment(0, "alignRight")<cr>'
execute 'vnoremap <silent>' . g:NERDComAlignRightMap . ' <ESC>:call NERDComment(1, "alignRight")<cr>'
" right aligned comments
nnoremap <silent> <plug>NERDCommenterAlignRight :call NERDComment(0, "alignRight")<cr>
vnoremap <silent> <plug>NERDCommenterAlignRight <ESC>:call NERDComment(1, "alignRight")<cr>
" set up the mappings for left and right aligned comments
execute 'nnoremap <silent>' . g:NERDComAlignBothMap . ' :call NERDComment(0, "alignBoth")<cr>'
execute 'vnoremap <silent>' . g:NERDComAlignBothMap . ' <ESC>:call NERDComment(1, "alignBoth")<cr>'
" left and right aligned comments
nnoremap <silent> <plug>NERDCommenterAlignBoth :call NERDComment(0, "alignBoth")<cr>
vnoremap <silent> <plug>NERDCommenterAlignBoth <ESC>:call NERDComment(1, "alignBoth")<cr>
" set up the mappings to do nested comments
execute 'nnoremap <silent>' . g:NERDComLineNestMap . ' :call NERDComment(0, "nested")<cr>'
execute 'vnoremap <silent>' . g:NERDComLineNestMap . ' <ESC>:call NERDComment(1, "nested")<cr>'
" nested comments
nnoremap <silent> <plug>NERDCommenterNest :call NERDComment(0, "nested")<cr>
vnoremap <silent> <plug>NERDCommenterNest <ESC>:call NERDComment(1, "nested")<cr>
" set up the mapping to uncomment a line
execute 'nnoremap <silent>' . g:NERDUncomLineMap . ' :call NERDComment(0, "uncomment")<cr>'
execute 'vnoremap <silent>' . g:NERDUncomLineMap . ' :call NERDComment(1, "uncomment")<cr>'
" uncomment
nnoremap <silent> <plug>NERDCommenterUncomment :call NERDComment(0, "uncomment")<cr>
vnoremap <silent> <plug>NERDCommenterUncomment :call NERDComment(1, "uncomment")<cr>
" set up the mapping to comment out to the end of the line
execute 'nnoremap <silent>' . g:NERDComToEOLMap . ' :call NERDComment(0, "toEOL")<cr>'
" comment till the end of the line
nnoremap <silent> <plug>NERDCommenterToEOL :call NERDComment(0, "toEOL")<cr>
" set up the mappings to append comments to the line
execute 'nmap <silent>' . g:NERDAppendComMap . ' :call NERDComment(0, "append")<cr>'
" append comments
nmap <silent> <plug>NERDCommenterAppend :call NERDComment(0, "append")<cr>
" set up the mappings to append comments to the line
execute 'nmap <silent>' . g:NERDPrependComMap . ' :call NERDComment(0, "prepend")<cr>'
" prepend comments
nmap <silent> <plug>NERDCommenterPrepend :call NERDComment(0, "prepend")<cr>
" set up the mapping to insert comment delims at the cursor position in insert mode
if g:NERDComInInsertMap != ''
execute 'inoremap <silent>' . g:NERDComInInsertMap . ' ' . '<SPACE><BS><ESC>:call NERDComment(0, "insert")<CR>'
" insert comments
inoremap <silent> <plug>NERDCommenterInInsert <SPACE><BS><ESC>:call NERDComment(0, "insert")<CR>
function! s:CreateMaps(target, combo)
if !hasmapto(a:target, 'n')
exec 'nmap ' . a:combo . ' ' . a:target
endif
if !hasmapto(a:target, 'v')
exec 'vmap ' . a:combo . ' ' . a:target
endif
endfunction
if g:NERDCreateDefaultMappings
call s:CreateMaps('<plug>NERDCommenterComment', '<leader>cc')
call s:CreateMaps('<plug>NERDCommenterToggle', '<leader>c<space>')
call s:CreateMaps('<plug>NERDCommenterMinimal', '<leader>cm')
call s:CreateMaps('<plug>NERDCommenterSexy', '<leader>cs')
call s:CreateMaps('<plug>NERDCommenterInvert', '<leader>ci')
call s:CreateMaps('<plug>NERDCommenterYank', '<leader>cy')
call s:CreateMaps('<plug>NERDCommenterAlignLeft', '<leader>cl')
call s:CreateMaps('<plug>NERDCommenterAlignRight', '<leader>cr')
call s:CreateMaps('<plug>NERDCommenterAlignBoth', '<leader>cb')
call s:CreateMaps('<plug>NERDCommenterNest', '<leader>cn')
call s:CreateMaps('<plug>NERDCommenterUncomment', '<leader>cu')
call s:CreateMaps('<plug>NERDCommenterToEOL', '<leader>c$')
call s:CreateMaps('<plug>NERDCommenterAppend', '<leader>cA')
call s:CreateMaps('<plug>NERDCommenterPrepend', '<leader>cI')
if !hasmapto('<plug>NERDCommenterAltDelims', 'n')
nmap <leader>ca <plug>NERDCommenterAltDelims
endif
endif
" Section: Menu item setup {{{1
" ===========================================================================
"check if the user wants the menu to be displayed
@ -3321,57 +3336,29 @@ if g:NERDMenuMode != 0
let menuRoot = '&Plugin.&comment'
endif
execute 'nmenu <silent> '. menuRoot .'.Comment<TAB>' . escape(g:NERDComLineMap, '\') . ' :call NERDComment(0, "norm")<CR>'
execute 'vmenu <silent> '. menuRoot .'.Comment<TAB>' . escape(g:NERDComLineMap, '\') . ' <ESC>:call NERDComment(1, "norm")<CR>'
execute 'nmenu <silent> '. menuRoot .'.Comment\ Toggle<TAB>' . escape(g:NERDComLineToggleMap, '\') . ' :call NERDComment(0, "toggle")<CR>'
execute 'vmenu <silent> '. menuRoot .'.Comment\ Toggle<TAB>' . escape(g:NERDComLineToggleMap, '\') . ' <ESC>:call NERDComment(1, "toggle")<CR>'
execute 'nmenu <silent> '. menuRoot .'.Comment\ Minimal<TAB>' . escape(g:NERDComLineMinimalMap, '\') . ' :call NERDComment(0, "minimal")<CR>'
execute 'vmenu <silent> '. menuRoot .'.Comment\ Minimal<TAB>' . escape(g:NERDComLineMinimalMap, '\') . ' <ESC>:call NERDComment(1, "minimal")<CR>'
execute 'nmenu <silent> '. menuRoot .'.Comment\ Nested<TAB>' . escape(g:NERDComLineNestMap, '\') . ' :call NERDComment(0, "nested")<CR>'
execute 'vmenu <silent> '. menuRoot .'.Comment\ Nested<TAB>' . escape(g:NERDComLineNestMap, '\') . ' <ESC>:call NERDComment(1, "nested")<CR>'
execute 'nmenu <silent> '. menuRoot .'.Comment\ To\ EOL<TAB>' . escape(g:NERDComToEOLMap, '\') . ' :call NERDComment(0, "toEOL")<cr>'
execute 'nmenu <silent> '. menuRoot .'.Comment\ Invert<TAB>' . escape(g:NERDComLineInvertMap, '\') . ' :call NERDComment(0,"invert")<CR>'
execute 'vmenu <silent> '. menuRoot .'.Comment\ Invert<TAB>' . escape(g:NERDComLineInvertMap, '\') . ' <ESC>:call NERDComment(1,"invert")<CR>'
execute 'nmenu <silent> '. menuRoot .'.Comment\ Sexily<TAB>' . escape(g:NERDComLineSexyMap, '\') . ' :call NERDComment(0,"sexy")<CR>'
execute 'vmenu <silent> '. menuRoot .'.Comment\ Sexily<TAB>' . escape(g:NERDComLineSexyMap, '\') . ' <ESC>:call NERDComment(1,"sexy")<CR>'
execute 'nmenu <silent> '. menuRoot .'.Yank\ line(s)\ then\ comment<TAB>' . escape(g:NERDComLineYankMap, '\') . ' "0Y' . g:NERDComLineMap
execute 'vmenu <silent> '. menuRoot .'.Yank\ line(s)\ then\ comment<TAB>' . escape(g:NERDComLineYankMap, '\') . ' "0ygv' . g:NERDComLineMap
execute 'nmenu <silent> '. menuRoot .'.Append\ Comment\ to\ Line<TAB>' . escape(g:NERDAppendComMap, '\') . ' :call NERDComment(0, "append")<cr>'
execute 'nmenu <silent> '. menuRoot .'.Prepend\ Comment\ to\ Line<TAB>' . escape(g:NERDPrependComMap, '\') . ' :call NERDComment(0, "prepend")<cr>'
execute 'menu <silent> '. menuRoot .'.-Sep- :'
execute 'nmenu <silent> '. menuRoot .'.Comment\ Align\ Left\ (nested)<TAB>' . escape(g:NERDComAlignLeftMap, '\') . ' :call NERDComment(0, "alignLeft")<CR>'
execute 'vmenu <silent> '. menuRoot .'.Comment\ Align\ Left\ (nested)<TAB>' . escape(g:NERDComAlignLeftMap, '\') . ' <ESC>:call NERDComment(1, "alignLeft")<CR>'
execute 'nmenu <silent> '. menuRoot .'.Comment\ Align\ Right\ (nested)<TAB>' . escape(g:NERDComAlignRightMap, '\') . ' :call NERDComment(0, "alignRight")<CR>'
execute 'vmenu <silent> '. menuRoot .'.Comment\ Align\ Right\ (nested)<TAB>' . escape(g:NERDComAlignRightMap, '\') . ' <ESC>:call NERDComment(1, "alignRight")<CR>'
execute 'nmenu <silent> '. menuRoot .'.Comment\ Align\ Both\ (nested)<TAB>' . escape(g:NERDComAlignBothMap, '\') . ' :call NERDComment(0, "alignBoth")<CR>'
execute 'vmenu <silent> '. menuRoot .'.Comment\ Align\ Both\ (nested)<TAB>' . escape(g:NERDComAlignBothMap, '\') . ' <ESC>:call NERDComment(1, "alignBoth")<CR>'
execute 'menu <silent> '. menuRoot .'.-Sep2- :'
execute 'menu <silent> '. menuRoot .'.Uncomment<TAB>' . escape(g:NERDUncomLineMap, '\') . ' :call NERDComment(0, "uncomment")<cr>'
execute 'vmenu <silent>' . menuRoot.'.Uncomment<TAB>' . escape(g:NERDUncomLineMap, '\') . ' <esc>:call NERDComment(1, "uncomment")<cr>'
execute 'menu <silent> '. menuRoot .'.-Sep3- :'
execute 'nmenu <silent> '. menuRoot .'.Use\ Alternative\ Delimiters<TAB>' . escape(g:NERDAltComMap, '\') . ' :call <SID>SwitchToAlternativeDelimiters(1)<CR>'
execute 'imenu <silent> '. menuRoot .'.Insert\ Delims<TAB>' . escape(g:NERDComInInsertMap, '\') . ' <SPACE><BS><ESC>:call NERDComment(0, "insert")<CR>'
execute 'menu '. menuRoot .'.-Sep4- :'
execute 'menu <silent>'. menuRoot .'.Help<TAB>:help\ NERDCommenterContents :help NERDCommenterContents<CR>'
function! s:CreateMenuItems(target, desc, root)
exec 'nmenu <silent> ' . a:root . '.' . a:desc . ' ' . a:target
exec 'vmenu <silent> ' . a:root . '.' . a:desc . ' ' . a:target
endfunction
call s:CreateMenuItems("<plug>NERDCommenterComment", 'Comment', menuRoot)
call s:CreateMenuItems("<plug>NERDCommenterToggle", 'Toggle', menuRoot)
call s:CreateMenuItems('<plug>NERDCommenterMinimal', 'Minimal', menuRoot)
call s:CreateMenuItems('<plug>NERDCommenterNest', 'Nested', menuRoot)
exec 'nmenu <silent> '. menuRoot .'.To\ EOL <plug>NERDCommenterToEOL'
call s:CreateMenuItems('<plug>NERDCommenterInvert', 'Invert', menuRoot)
call s:CreateMenuItems('<plug>NERDCommenterSexy', 'Sexy', menuRoot)
call s:CreateMenuItems('<plug>NERDCommenterYank', 'Yank\ then\ comment', menuRoot)
exec 'nmenu <silent> '. menuRoot .'.Append <plug>NERDCommenterAppend'
exec 'nmenu <silent> '. menuRoot .'.Prepend <plug>NERDCommenterPrepend'
exec 'menu <silent> '. menuRoot .'.-Sep- :'
call s:CreateMenuItems('<plug>NERDCommenterAlignLeft', 'Left\ aligned', menuRoot)
call s:CreateMenuItems('<plug>NERDCommenterAlignRight', 'Right\ aligned', menuRoot)
call s:CreateMenuItems('<plug>NERDCommenterAlignBoth', 'Left\ and\ right\ aligned', menuRoot)
exec 'menu <silent> '. menuRoot .'.-Sep2- :'
call s:CreateMenuItems('<plug>NERDCommenterUncomment', 'Uncomment', menuRoot)
exec 'nmenu <silent> '. menuRoot .'.Switch\ Delimiters <plug>NERDCommenterAltDelims'
exec 'imenu <silent> '. menuRoot .'.Insert\ Comment\ Here <plug>NERDCommenterInInsert'
exec 'menu <silent> '. menuRoot .'.-Sep3- :'
exec 'menu <silent>'. menuRoot .'.Help :help NERDCommenterContents<CR>'
endif
" vim: set foldmethod=marker :