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.1 Options summary...................|NERDComOptionsSummary|
3.2 Options details...................|NERDComOptionsDetails| 3.2 Options details...................|NERDComOptionsDetails|
3.3 Default delimiter Options.........|NERDComDefaultDelims| 3.3 Default delimiter Options.........|NERDComDefaultDelims|
3.4 Key mapping Options...............|NERDComMappings| 4. Customising key mappings...............|NERDComMappings|
4.Issues with the script..................|NERDComIssues| 5. Issues with the script.................|NERDComIssues|
4.1 Delimiter detection heuristics....|NERDComHeuristics| 5.1 Delimiter detection heuristics....|NERDComHeuristics|
4.2 Nesting issues....................|NERDComNesting| 5.2 Nesting issues....................|NERDComNesting|
5.The author..............................|NERDComAuthor| 6.The author..............................|NERDComAuthor|
6.Changelog...............................|NERDComChangelog| 7.Changelog...............................|NERDComChangelog|
7.Credits.................................|NERDComCredits| 8.Credits.................................|NERDComCredits|
8.License.................................|NERDComLicense| 9.License.................................|NERDComLicense|
============================================================================== ==============================================================================
1. Intro *NERDCommenter* 1. Intro *NERDCommenter*
@@ -66,69 +66,70 @@ provided that contains menu items corresponding to all the below mappings):
Most of the following mappings are for normal/visual mode only. The Most of the following mappings are for normal/visual mode only. The
|NERDComInsertComment| mapping is for insert mode only. |NERDComInsertComment| mapping is for insert mode only.
[count],cc |NERDComComment| [count]<leader>cc |NERDComComment|
Comments out the current line or text selected in visual mode. Comment out the current line or text selected in visual mode.
[count],cn |NERDComNestedComment| [count]<leader>cn |NERDComNestedComment|
Same as |NERDComComment| but forces nesting. 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 Toggles the comment state of the selected line(s). If the topmost selected
line is commented, all selected lines are uncommented and vice versa. 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 Comments the given lines using only one set of multipart delimiters if
possible. possible.
[count],ci |NERDComInvertComment| [count]<leader>ci |NERDComInvertComment|
Toggles the comment state of the selected line(s) individually. Each selected Toggles the comment state of the selected line(s) individually. Each selected
line that is commented is uncommented and vice versa. line that is commented is uncommented and vice versa.
[count],cs |NERDComSexyComment| [count]<leader>cs |NERDComSexyComment|
Comments out the selected lines ``sexily'' Comments out the selected lines ``sexily''
[count],cy |NERDComYankComment| [count]<leader>cy |NERDComYankComment|
Same as |NERDComComment| except that the commented line(s) are yanked Same as |NERDComComment| except that the commented line(s) are yanked
before commenting. before commenting.
,c$ |NERDComEOLComment| <leader>c$ |NERDComEOLComment|
Comments the current line from the cursor to the end of line. 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 Adds comment delimiters to the end of line and goes into insert mode between
them. them.
,cI |NERDComPrependComment| <leader>cI |NERDComPrependComment|
Adds comment delimiters to the start of line and goes into insert mode between Adds comment delimiters to the start of line and goes into insert mode between
them. them.
|NERDComInsertComment| |NERDComInsertComment|
Adds comment delimiters at the current cursor position and inserts between. Adds comment delimiters at the current cursor position and inserts between.
Disabled by default. Disabled by default.
,ca |NERDComAltDelim| <leader>ca |NERDComAltDelim|
Switches to the alternative set of delimiters. Switches to the alternative set of delimiters.
[count],cl [count]<leader>cl
[count],cr [count]<leader>cr
[count],cb |NERDComAlignedComment| [count]<leader>cb |NERDComAlignedComment|
Same as |NERDComComment| except that the delimiters are aligned down the Same as |NERDComComment| except that the delimiters are aligned down the
left side (,cl), the right side (,cr) or both sides left side (<leader>cl), the right side (<leader>cr) or both sides
(,cb). (<leader>cb).
[count],cu |NERDComUncommentLine| [count]<leader>cu |NERDComUncommentLine|
Uncomments the selected line(s). Uncomments the selected line(s).
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
@@ -137,8 +138,8 @@ Uncomments the selected line(s).
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
2.2.1 Comment map *NERDComComment* 2.2.1 Comment map *NERDComComment*
Default mapping: [count],cc Default mapping: [count]<leader>cc
Change the mapping with: NERDComLineMap. Mapped to: <plug>NERDCommenterComment
Applicable modes: normal visual visual-line visual-block. 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* 2.2.2 Nested comment map *NERDComNestedComment*
Default mapping: [count],cn Default mapping: [count]<leader>cn
Change the mapping with: NERDComLineNestMap. Mapped to: <plug>NERDCommenterNest
Applicable modes: normal visual visual-line visual-block. 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. line is already commented then it will be commented again.
If |NERDUsePlaceHolders| is set then the previous comment delimiters will If |NERDUsePlaceHolders| is set then the previous comment delimiters will
@@ -174,8 +175,8 @@ Related options:
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
2.2.3 Toggle comment map *NERDComToggleComment* 2.2.3 Toggle comment map *NERDComToggleComment*
Default mapping: [count],c<space> Default mapping: [count]<leader>c<space>
Change the mapping with: NERDComLineToggleMap. Mapped to: <plug>NERDCommenterToggle
Applicable modes: normal visual-line. Applicable modes: normal visual-line.
Toggles commenting of the lines selected. The behaviour of this mapping 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* 2.2.4 Minimal comment map *NERDComMinimalComment*
Default mapping: [count],cm Default mapping: [count]<leader>cm
Change the mapping with: NERDComLineMinimalMap Mapped to: <plug>NERDCommenterMinimal
Applicable modes: normal visual-line. Applicable modes: normal visual-line.
Comments the selected lines using one set of multipart delimiters if possible. 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 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. will be placed at the end of the last line.
Sets of multipart comment delimiters that are between the top and bottom 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* 2.2.5 Invert comment map *NERDComInvertComment*
Default mapping: ,ci Default mapping: <leader>ci
Change the mapping with: NERDComLineInvertMap. Mapped to: <plug>NERDCommenterInvert
Applicable modes: normal visual-line. Applicable modes: normal visual-line.
Inverts the commented state of each selected line. If the a selected line is 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* 2.2.6 Sexy comment map *NERDComSexyComment*
Default mapping: [count],cs Default mapping: [count]<leader>cs
Change the mapping with: NERDComLineSexyMap Mapped to: <plug>NERDCommenterSexy
Applicable modes: normal, visual-line. Applicable modes: normal, visual-line.
Comments the selected line(s) ``sexily''... see |NERDComSexyComments| for Comments the selected line(s) ``sexily''... see |NERDComSexyComments| for
@@ -250,17 +251,17 @@ Related options:
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
2.2.7 Yank comment map *NERDComYankComment* 2.2.7 Yank comment map *NERDComYankComment*
Default mapping: [count],cy Default mapping: [count]<leader>cy
Change the mapping with: NERDComLineYankMap Mapped to: <plug>NERDCommenterYank
Applicable modes: normal visual visual-line visual-block. 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* 2.2.8 Comment to EOL map *NERDComEOLComment*
Default mapping: ,c$ Default mapping: <leader>c$
Change the mapping with: NERDComToEOLMap Mapped to: <plug>NERDCommenterToEOL
Applicable modes: normal. Applicable modes: normal.
Comments the current line from the current cursor position up to the end of 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* 2.2.9 Append com to line map *NERDComAppendComment*
Default mapping: ,cA Default mapping: <leader>cA
Change the mapping with: NERDAppendComMap. Mapped to: <plug>NERDCommenterAppend
Applicable modes: normal. Applicable modes: normal.
Appends comment delimiters to the end of the current line and goes 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* 2.2.10 Prepend com to line map *NERDComPrependComment*
Default mapping: ,cI Default mapping: <leader>cI
Change the mapping with: NERDPrependComMap. Mapped to: <plug>NERDCommenterPrepend
Applicable modes: normal. Applicable modes: normal.
Prepends comment delimiters to the start of the current line and goes to 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* 2.2.11 Insert comment map *NERDComInsertComment*
Default mapping: disabled by default. Default mapping: disabled by default.
Change the mapping with: NERDComInInsertMap. Map it to: <plug>NERDCommenterInInsert
Applicable modes: insert. Applicable modes: insert.
Adds comment delimiters at the current cursor position and inserts 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* 2.2.12 Use alternate delims map *NERDComAltDelim*
Default mapping: ,ca Default mapping: <leader>ca
Change the mapping with: NERDAltComMap Mapped to: <plug>NERDCommenterAltDelims
Applicable modes: normal. Applicable modes: normal.
Changes to the alternative commenting style if one is available. For example, 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. then they will be switched over to /**/ comments.
See also |NERDComDefaultDelims| See also |NERDComDefaultDelims|
@@ -318,12 +319,13 @@ See also |NERDComDefaultDelims|
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
2.2.13 Comment aligned maps *NERDComAlignedComment* 2.2.13 Comment aligned maps *NERDComAlignedComment*
Default mappings: [count],cl [count],cr [count],cb Default mappings: [count]<leader>cl [count]<leader>cr [count]<leader>cb
Change the mappings with: NERDComAlignLeftMap, NERDComAlignRightMap and Mapped to: <plug>NERDCommenterAlignLeft
NERDComAlignBothMap. <plug>NERDCommenterAlignRight
<plug>NERDCommenterAlignBoth
Applicable modes: normal visual-line. 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 side, right side or both sides respectively. These comments are always nested
if the line(s) are already commented. 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* 2.2.14 Uncomment line map *NERDComUncommentLine*
Default mapping: [count],cu Default mapping: [count]<leader>cu
Change the mapping with: NERDUncomLineMap. Mapped to: <plug>NERDCommenterUncomment
Applicable modes: normal visual visual-line visual-block. Applicable modes: normal visual visual-line visual-block.
Uncomments the current line. If multiple lines are selected in 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 |NERDBlockComIgnoreEmpty| Forces right delims to be placed when
doing visual-block comments. doing visual-block comments.
|NERDCommentWholeLinesInVMode| Changes behaviour of visual comments. |NERDCommentWholeLinesInVMode| Changes behaviour of visual comments.
|NERDCreateDefaultMappings| Turn the default mappings on/off.
|NERDDefaultNesting| Tells the script to use nested comments |NERDDefaultNesting| Tells the script to use nested comments
by default. by default.
|NERDMenuMode| Specifies how the NERD commenter menu |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 |NERDLPlace| Specifies what to use as the left
delimiter placeholder when nesting delimiter placeholder when nesting
comments. comments.
|NERDMapleader| Specifies what all the commenting key
mappings will begin with.
|NERDUsePlaceHolders| Specifies which filetypes may use |NERDUsePlaceHolders| Specifies which filetypes may use
placeholders when nesting comments. placeholders when nesting comments.
|NERDRemoveAltComs| Tells the script whether to remove |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. 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* *NERDRemoveAltComs*
Values: 0 or 1. 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. delimiters of the alternative style.
For example, if you are editing a c++ file using // style comments and you go 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! */ /* This is a c++ comment baby! */
< <
It will not be uncommented if the NERDRemoveAltComs is set to 0. 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: > Following the above example, if we have line of c code: >
/* int horse */ /* 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*/ /*FOO int horse BAR*/
< <
When we uncomment this line it will go back to what it was. 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* *NERDMenuMode*
Values: 0, 1, 2, 3. Values: 0, 1, 2, 3.
@@ -754,7 +734,7 @@ Values: 0 or 1.
Default 1. Default 1.
When this option is set to 1, comments are nested automatically. That is, if 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 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. 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 To change a mapping just map another key combo to the internal <plug> mapping.
commenting mappings. Their values must be set to strings. As an example: if For example, to remap the *NERDComComment* mapping to ",omg" you would put
you wanted to use the mapping ,foo to uncomment lines of code then these lines in your vimrc: >
you would place this line in your vimrc > nmap ,omg <plug>NERDCommenterComment
let NERDUncomLineMap=",foo" vmap ,omg <plug>NERDCommenterComment
< <
Check out |NERDComFunctionality| for details about what the following This will stop the corresponding default mappings from being created. Note: in
mappings do. 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 See also |NERDCreateDefaultMappings|.
,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
============================================================================== ==============================================================================
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 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. cases.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
4.2 Nesting issues *NERDComNesting* 5.2 Nesting issues *NERDComNesting*
If we have some line of code like this: > If we have some line of code like this: >
/*int foo */ = /*5 + 9;*/ /*int foo */ = /*5 + 9;*/
@@ -846,7 +814,7 @@ will become: >
for simplicity) for simplicity)
============================================================================== ==============================================================================
5. The author *NERDComAuthor* 6. The author *NERDComAuthor*
The author of the NERD commenter is Martyzillatron --- the half robot, half The author of the NERD commenter is Martyzillatron --- the half robot, half
dinosaur bastard son of Megatron and Godzilla. He enjoys destroying 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? :( if your face looked like a toaster and a t-rex put together? :(
============================================================================== ==============================================================================
7. Changelog *NERDComChangelog* 8. Changelog *NERDComChangelog*
2.x.x 2.x.x
- add support for potwiki. Thanks to Bernhard Grotz for the email. - 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. information.
============================================================================== ==============================================================================
7. Credits *NERDComCredits* 8. Credits *NERDComCredits*
Thanks and respect to the following people: Thanks and respect to the following people:
@@ -1293,7 +1261,7 @@ Bernhard Grotz potwiki
sgronblo man sgronblo man
============================================================================== ==============================================================================
8. License *NERDComLicense* 9. License *NERDComLicense*
The NERD commenter is released under the wtfpl. The NERD commenter is released under the wtfpl.
See http://sam.zoy.org/wtfpl/COPYING. 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:NERDBlockComIgnoreEmpty", 0)
call s:InitVariable("g:NERDCommentWholeLinesInVMode", 0) call s:InitVariable("g:NERDCommentWholeLinesInVMode", 0)
call s:InitVariable("g:NERDCompactSexyComs", 0) call s:InitVariable("g:NERDCompactSexyComs", 0)
call s:InitVariable("g:NERDCreateDefaultMappings", 1)
call s:InitVariable("g:NERDDefaultNesting", 1) call s:InitVariable("g:NERDDefaultNesting", 1)
call s:InitVariable("g:NERDMenuMode", 3) call s:InitVariable("g:NERDMenuMode", 3)
call s:InitVariable("g:NERDLPlace", "[>") 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:NERDSpaceDelims", 0)
call s:InitVariable("g:NERDDelimiterRequests", 1) 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="[]#*$%'\" ?`!&();<>\\" let s:NERDFileNameEscape="[]#*$%'\" ?`!&();<>\\"
" Section: Comment mapping functions, autocommands and commands {{{1 " Section: Comment mapping functions, autocommands and commands {{{1
@@ -3243,70 +3228,100 @@ function s:UntabbedCol(line, col)
endfunction endfunction
" Section: Comment mapping setup {{{1 " 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 " switch to/from alternative delimiters
execute 'nnoremap <silent>' . g:NERDAltComMap . ' :call <SID>SwitchToAlternativeDelimiters(1)<cr>' nnoremap <plug>NERDCommenterAltDelims :call <SID>SwitchToAlternativeDelimiters(1)<cr>
" set up the mappings to comment out lines " comment out lines
execute 'nnoremap <silent>' . g:NERDComLineMap . ' :call NERDComment(0, "norm")<cr>' nnoremap <silent> <plug>NERDCommenterComment :call NERDComment(0, "norm")<cr>
execute 'vnoremap <silent>' . g:NERDComLineMap . ' <ESC>:call NERDComment(1, "norm")<cr>' vnoremap <silent> <plug>NERDCommenterComment <ESC>:call NERDComment(1, "norm")<cr>
" set up the mappings to do toggle comments " toggle comments
execute 'nnoremap <silent>' . g:NERDComLineToggleMap . ' :call NERDComment(0, "toggle")<cr>' nnoremap <silent> <plug>NERDCommenterToggle :call NERDComment(0, "toggle")<cr>
execute 'vnoremap <silent>' . g:NERDComLineToggleMap . ' <ESC>:call NERDComment(1, "toggle")<cr>' vnoremap <silent> <plug>NERDCommenterToggle <ESC>:call NERDComment(1, "toggle")<cr>
" set up the mapp to do minimal comments " minimal comments
execute 'nnoremap <silent>' . g:NERDComLineMinimalMap . ' :call NERDComment(0, "minimal")<cr>' nnoremap <silent> <plug>NERDCommenterMinimal :call NERDComment(0, "minimal")<cr>
execute 'vnoremap <silent>' . g:NERDComLineMinimalMap . ' <ESC>:call NERDComment(1, "minimal")<cr>' vnoremap <silent> <plug>NERDCommenterMinimal <ESC>:call NERDComment(1, "minimal")<cr>
" set up the mappings to comment out lines sexily " sexy comments
execute 'nnoremap <silent>' . g:NERDComLineSexyMap . ' :call NERDComment(0, "sexy")<CR>' nnoremap <silent> <plug>NERDCommenterSexy :call NERDComment(0, "sexy")<CR>
execute 'vnoremap <silent>' . g:NERDComLineSexyMap . ' <ESC>:call NERDComment(1, "sexy")<CR>' vnoremap <silent> <plug>NERDCommenterSexy <ESC>:call NERDComment(1, "sexy")<CR>
" set up the mappings to do invert comments " invert comments
execute 'nnoremap <silent>' . g:NERDComLineInvertMap . ' :call NERDComment(0, "invert")<CR>' nnoremap <silent> <plug>NERDCommenterInvert :call NERDComment(0, "invert")<CR>
execute 'vnoremap <silent>' . g:NERDComLineInvertMap . ' <ESC>:call NERDComment(1, "invert")<CR>' vnoremap <silent> <plug>NERDCommenterInvert <ESC>:call NERDComment(1, "invert")<CR>
" set up the mappings to yank then comment out lines " yank then comment
execute 'nmap <silent>' . g:NERDComLineYankMap . ' :call NERDComment(0, "yank")<CR>' nmap <silent> <plug>NERDCommenterYank :call NERDComment(0, "yank")<CR>
execute 'vmap <silent>' . g:NERDComLineYankMap . ' <ESC>:call NERDComment(1, "yank")<CR>' vmap <silent> <plug>NERDCommenterYank <ESC>:call NERDComment(1, "yank")<CR>
" set up the mappings for left aligned comments " left aligned comments
execute 'nnoremap <silent>' . g:NERDComAlignLeftMap . ' :call NERDComment(0, "alignLeft")<cr>' nnoremap <silent> <plug>NERDCommenterAlignLeft :call NERDComment(0, "alignLeft")<cr>
execute 'vnoremap <silent>' . g:NERDComAlignLeftMap . ' <ESC>:call NERDComment(1, "alignLeft")<cr>' vnoremap <silent> <plug>NERDCommenterAlignLeft <ESC>:call NERDComment(1, "alignLeft")<cr>
" set up the mappings for right aligned comments " right aligned comments
execute 'nnoremap <silent>' . g:NERDComAlignRightMap . ' :call NERDComment(0, "alignRight")<cr>' nnoremap <silent> <plug>NERDCommenterAlignRight :call NERDComment(0, "alignRight")<cr>
execute 'vnoremap <silent>' . g:NERDComAlignRightMap . ' <ESC>:call NERDComment(1, "alignRight")<cr>' vnoremap <silent> <plug>NERDCommenterAlignRight <ESC>:call NERDComment(1, "alignRight")<cr>
" set up the mappings for left and right aligned comments " left and right aligned comments
execute 'nnoremap <silent>' . g:NERDComAlignBothMap . ' :call NERDComment(0, "alignBoth")<cr>' nnoremap <silent> <plug>NERDCommenterAlignBoth :call NERDComment(0, "alignBoth")<cr>
execute 'vnoremap <silent>' . g:NERDComAlignBothMap . ' <ESC>:call NERDComment(1, "alignBoth")<cr>' vnoremap <silent> <plug>NERDCommenterAlignBoth <ESC>:call NERDComment(1, "alignBoth")<cr>
" set up the mappings to do nested comments " nested comments
execute 'nnoremap <silent>' . g:NERDComLineNestMap . ' :call NERDComment(0, "nested")<cr>' nnoremap <silent> <plug>NERDCommenterNest :call NERDComment(0, "nested")<cr>
execute 'vnoremap <silent>' . g:NERDComLineNestMap . ' <ESC>:call NERDComment(1, "nested")<cr>' vnoremap <silent> <plug>NERDCommenterNest <ESC>:call NERDComment(1, "nested")<cr>
" set up the mapping to uncomment a line " uncomment
execute 'nnoremap <silent>' . g:NERDUncomLineMap . ' :call NERDComment(0, "uncomment")<cr>' nnoremap <silent> <plug>NERDCommenterUncomment :call NERDComment(0, "uncomment")<cr>
execute 'vnoremap <silent>' . g:NERDUncomLineMap . ' :call NERDComment(1, "uncomment")<cr>' vnoremap <silent> <plug>NERDCommenterUncomment :call NERDComment(1, "uncomment")<cr>
" set up the mapping to comment out to the end of the line " comment till the end of the line
execute 'nnoremap <silent>' . g:NERDComToEOLMap . ' :call NERDComment(0, "toEOL")<cr>' nnoremap <silent> <plug>NERDCommenterToEOL :call NERDComment(0, "toEOL")<cr>
" set up the mappings to append comments to the line " append comments
execute 'nmap <silent>' . g:NERDAppendComMap . ' :call NERDComment(0, "append")<cr>' nmap <silent> <plug>NERDCommenterAppend :call NERDComment(0, "append")<cr>
" set up the mappings to append comments to the line " prepend comments
execute 'nmap <silent>' . g:NERDPrependComMap . ' :call NERDComment(0, "prepend")<cr>' nmap <silent> <plug>NERDCommenterPrepend :call NERDComment(0, "prepend")<cr>
" set up the mapping to insert comment delims at the cursor position in insert mode " insert comments
if g:NERDComInInsertMap != '' inoremap <silent> <plug>NERDCommenterInInsert <SPACE><BS><ESC>:call NERDComment(0, "insert")<CR>
execute 'inoremap <silent>' . g:NERDComInInsertMap . ' ' . '<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 endif
" Section: Menu item setup {{{1 " Section: Menu item setup {{{1
" =========================================================================== " ===========================================================================
"check if the user wants the menu to be displayed "check if the user wants the menu to be displayed
@@ -3321,57 +3336,29 @@ if g:NERDMenuMode != 0
let menuRoot = '&Plugin.&comment' let menuRoot = '&Plugin.&comment'
endif endif
execute 'nmenu <silent> '. menuRoot .'.Comment<TAB>' . escape(g:NERDComLineMap, '\') . ' :call NERDComment(0, "norm")<CR>' function! s:CreateMenuItems(target, desc, root)
execute 'vmenu <silent> '. menuRoot .'.Comment<TAB>' . escape(g:NERDComLineMap, '\') . ' <ESC>:call NERDComment(1, "norm")<CR>' exec 'nmenu <silent> ' . a:root . '.' . a:desc . ' ' . a:target
exec 'vmenu <silent> ' . a:root . '.' . a:desc . ' ' . a:target
execute 'nmenu <silent> '. menuRoot .'.Comment\ Toggle<TAB>' . escape(g:NERDComLineToggleMap, '\') . ' :call NERDComment(0, "toggle")<CR>' endfunction
execute 'vmenu <silent> '. menuRoot .'.Comment\ Toggle<TAB>' . escape(g:NERDComLineToggleMap, '\') . ' <ESC>:call NERDComment(1, "toggle")<CR>' call s:CreateMenuItems("<plug>NERDCommenterComment", 'Comment', menuRoot)
call s:CreateMenuItems("<plug>NERDCommenterToggle", 'Toggle', menuRoot)
execute 'nmenu <silent> '. menuRoot .'.Comment\ Minimal<TAB>' . escape(g:NERDComLineMinimalMap, '\') . ' :call NERDComment(0, "minimal")<CR>' call s:CreateMenuItems('<plug>NERDCommenterMinimal', 'Minimal', menuRoot)
execute 'vmenu <silent> '. menuRoot .'.Comment\ Minimal<TAB>' . escape(g:NERDComLineMinimalMap, '\') . ' <ESC>:call NERDComment(1, "minimal")<CR>' call s:CreateMenuItems('<plug>NERDCommenterNest', 'Nested', menuRoot)
exec 'nmenu <silent> '. menuRoot .'.To\ EOL <plug>NERDCommenterToEOL'
execute 'nmenu <silent> '. menuRoot .'.Comment\ Nested<TAB>' . escape(g:NERDComLineNestMap, '\') . ' :call NERDComment(0, "nested")<CR>' call s:CreateMenuItems('<plug>NERDCommenterInvert', 'Invert', menuRoot)
execute 'vmenu <silent> '. menuRoot .'.Comment\ Nested<TAB>' . escape(g:NERDComLineNestMap, '\') . ' <ESC>:call NERDComment(1, "nested")<CR>' call s:CreateMenuItems('<plug>NERDCommenterSexy', 'Sexy', menuRoot)
call s:CreateMenuItems('<plug>NERDCommenterYank', 'Yank\ then\ comment', menuRoot)
execute 'nmenu <silent> '. menuRoot .'.Comment\ To\ EOL<TAB>' . escape(g:NERDComToEOLMap, '\') . ' :call NERDComment(0, "toEOL")<cr>' exec 'nmenu <silent> '. menuRoot .'.Append <plug>NERDCommenterAppend'
exec 'nmenu <silent> '. menuRoot .'.Prepend <plug>NERDCommenterPrepend'
execute 'nmenu <silent> '. menuRoot .'.Comment\ Invert<TAB>' . escape(g:NERDComLineInvertMap, '\') . ' :call NERDComment(0,"invert")<CR>' exec 'menu <silent> '. menuRoot .'.-Sep- :'
execute 'vmenu <silent> '. menuRoot .'.Comment\ Invert<TAB>' . escape(g:NERDComLineInvertMap, '\') . ' <ESC>:call NERDComment(1,"invert")<CR>' call s:CreateMenuItems('<plug>NERDCommenterAlignLeft', 'Left\ aligned', menuRoot)
call s:CreateMenuItems('<plug>NERDCommenterAlignRight', 'Right\ aligned', menuRoot)
execute 'nmenu <silent> '. menuRoot .'.Comment\ Sexily<TAB>' . escape(g:NERDComLineSexyMap, '\') . ' :call NERDComment(0,"sexy")<CR>' call s:CreateMenuItems('<plug>NERDCommenterAlignBoth', 'Left\ and\ right\ aligned', menuRoot)
execute 'vmenu <silent> '. menuRoot .'.Comment\ Sexily<TAB>' . escape(g:NERDComLineSexyMap, '\') . ' <ESC>:call NERDComment(1,"sexy")<CR>' exec 'menu <silent> '. menuRoot .'.-Sep2- :'
call s:CreateMenuItems('<plug>NERDCommenterUncomment', 'Uncomment', menuRoot)
execute 'nmenu <silent> '. menuRoot .'.Yank\ line(s)\ then\ comment<TAB>' . escape(g:NERDComLineYankMap, '\') . ' "0Y' . g:NERDComLineMap exec 'nmenu <silent> '. menuRoot .'.Switch\ Delimiters <plug>NERDCommenterAltDelims'
execute 'vmenu <silent> '. menuRoot .'.Yank\ line(s)\ then\ comment<TAB>' . escape(g:NERDComLineYankMap, '\') . ' "0ygv' . g:NERDComLineMap exec 'imenu <silent> '. menuRoot .'.Insert\ Comment\ Here <plug>NERDCommenterInInsert'
exec 'menu <silent> '. menuRoot .'.-Sep3- :'
execute 'nmenu <silent> '. menuRoot .'.Append\ Comment\ to\ Line<TAB>' . escape(g:NERDAppendComMap, '\') . ' :call NERDComment(0, "append")<cr>' exec 'menu <silent>'. menuRoot .'.Help :help NERDCommenterContents<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>'
endif endif
" vim: set foldmethod=marker : " vim: set foldmethod=marker :