diff --git a/doc/NERD_commenter.txt b/doc/NERD_commenter.txt index fd7aa3d..7890a8c 100644 --- a/doc/NERD_commenter.txt +++ b/doc/NERD_commenter.txt @@ -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,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 |NERDComInsertComment| mapping is for insert mode only. -[count],cc |NERDComComment| -Comments out the current line or text selected in visual mode. +[count]cc |NERDComComment| +Comment out the current line or text selected in visual mode. -[count],cn |NERDComNestedComment| -Same as |NERDComComment| but forces nesting. +[count]cn |NERDComNestedComment| +Same as but forces nesting. -[count],c |NERDComToggleComment| + +[count]c |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]cm |NERDComMinimalComment| Comments the given lines using only one set of multipart delimiters if possible. -[count],ci |NERDComInvertComment| +[count]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]cs |NERDComSexyComment| Comments out the selected lines ``sexily'' -[count],cy |NERDComYankComment| +[count]cy |NERDComYankComment| Same as |NERDComComment| except that the commented line(s) are yanked before commenting. -,c$ |NERDComEOLComment| +c$ |NERDComEOLComment| Comments the current line from the cursor to the end of line. -,cA |NERDComAppendComment| +cA |NERDComAppendComment| Adds comment delimiters to the end of line and goes into insert mode between them. -,cI |NERDComPrependComment| +cI |NERDComPrependComment| Adds comment delimiters to the start of line and goes into insert mode between them. - |NERDComInsertComment| +|NERDComInsertComment| Adds comment delimiters at the current cursor position and inserts between. Disabled by default. -,ca |NERDComAltDelim| +ca |NERDComAltDelim| Switches to the alternative set of delimiters. -[count],cl -[count],cr -[count],cb |NERDComAlignedComment| +[count]cl +[count]cr +[count]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 (cl), the right side (cr) or both sides +(cb). -[count],cu |NERDComUncommentLine| +[count]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]cc +Mapped to: 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]cn +Mapped to: 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 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 -Change the mapping with: NERDComLineToggleMap. +Default mapping: [count]c +Mapped to: 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]cm +Mapped to: 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 '*/' +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: ci +Mapped to: 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]cs +Mapped to: 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]cy +Mapped to: 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 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: c$ +Mapped to: 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: cA +Mapped to: 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: cI +Mapped to: 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: 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: ca +Mapped to: 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 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]cl [count]cr [count]cb +Mapped to: NERDCommenterAlignLeft + NERDCommenterAlignRight + NERDCommenterAlignBoth Applicable modes: normal visual-line. -Same as ,cc except that the comment delimiters are aligned on the left +Same as 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]cu +Mapped to: 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: > +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 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 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 mapping. +For example, to remap the *NERDComComment* mapping to ",omg" you would put +these lines in your vimrc: > + nmap ,omg NERDCommenterComment + vmap ,omg 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 mapping to +map to, and which modes it applies to. -,ca NERDAltComMap -,ce NERDAppendComMap -,cl NERDComAlignLeftMap -,cb NERDComAlignBothMap -,cr NERDComAlignRightMap - NERDComInInsertMap -,ci NERDComLineInvertMap -,cc NERDComLineMap -,cn NERDComLineNestMap -,cs NERDComLineSexyMap -,c 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. diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 0520a49..0857bf2 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -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 . '') -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 ' . g:NERDAltComMap . ' :call SwitchToAlternativeDelimiters(1)' +" switch to/from alternative delimiters +nnoremap NERDCommenterAltDelims :call SwitchToAlternativeDelimiters(1) -" set up the mappings to comment out lines -execute 'nnoremap ' . g:NERDComLineMap . ' :call NERDComment(0, "norm")' -execute 'vnoremap ' . g:NERDComLineMap . ' :call NERDComment(1, "norm")' +" comment out lines +nnoremap NERDCommenterComment :call NERDComment(0, "norm") +vnoremap NERDCommenterComment :call NERDComment(1, "norm") -" set up the mappings to do toggle comments -execute 'nnoremap ' . g:NERDComLineToggleMap . ' :call NERDComment(0, "toggle")' -execute 'vnoremap ' . g:NERDComLineToggleMap . ' :call NERDComment(1, "toggle")' +" toggle comments +nnoremap NERDCommenterToggle :call NERDComment(0, "toggle") +vnoremap NERDCommenterToggle :call NERDComment(1, "toggle") -" set up the mapp to do minimal comments -execute 'nnoremap ' . g:NERDComLineMinimalMap . ' :call NERDComment(0, "minimal")' -execute 'vnoremap ' . g:NERDComLineMinimalMap . ' :call NERDComment(1, "minimal")' +" minimal comments +nnoremap NERDCommenterMinimal :call NERDComment(0, "minimal") +vnoremap NERDCommenterMinimal :call NERDComment(1, "minimal") -" set up the mappings to comment out lines sexily -execute 'nnoremap ' . g:NERDComLineSexyMap . ' :call NERDComment(0, "sexy")' -execute 'vnoremap ' . g:NERDComLineSexyMap . ' :call NERDComment(1, "sexy")' +" sexy comments +nnoremap NERDCommenterSexy :call NERDComment(0, "sexy") +vnoremap NERDCommenterSexy :call NERDComment(1, "sexy") -" set up the mappings to do invert comments -execute 'nnoremap ' . g:NERDComLineInvertMap . ' :call NERDComment(0, "invert")' -execute 'vnoremap ' . g:NERDComLineInvertMap . ' :call NERDComment(1, "invert")' +" invert comments +nnoremap NERDCommenterInvert :call NERDComment(0, "invert") +vnoremap NERDCommenterInvert :call NERDComment(1, "invert") -" set up the mappings to yank then comment out lines -execute 'nmap ' . g:NERDComLineYankMap . ' :call NERDComment(0, "yank")' -execute 'vmap ' . g:NERDComLineYankMap . ' :call NERDComment(1, "yank")' +" yank then comment +nmap NERDCommenterYank :call NERDComment(0, "yank") +vmap NERDCommenterYank :call NERDComment(1, "yank") -" set up the mappings for left aligned comments -execute 'nnoremap ' . g:NERDComAlignLeftMap . ' :call NERDComment(0, "alignLeft")' -execute 'vnoremap ' . g:NERDComAlignLeftMap . ' :call NERDComment(1, "alignLeft")' +" left aligned comments +nnoremap NERDCommenterAlignLeft :call NERDComment(0, "alignLeft") +vnoremap NERDCommenterAlignLeft :call NERDComment(1, "alignLeft") -" set up the mappings for right aligned comments -execute 'nnoremap ' . g:NERDComAlignRightMap . ' :call NERDComment(0, "alignRight")' -execute 'vnoremap ' . g:NERDComAlignRightMap . ' :call NERDComment(1, "alignRight")' +" right aligned comments +nnoremap NERDCommenterAlignRight :call NERDComment(0, "alignRight") +vnoremap NERDCommenterAlignRight :call NERDComment(1, "alignRight") -" set up the mappings for left and right aligned comments -execute 'nnoremap ' . g:NERDComAlignBothMap . ' :call NERDComment(0, "alignBoth")' -execute 'vnoremap ' . g:NERDComAlignBothMap . ' :call NERDComment(1, "alignBoth")' +" left and right aligned comments +nnoremap NERDCommenterAlignBoth :call NERDComment(0, "alignBoth") +vnoremap NERDCommenterAlignBoth :call NERDComment(1, "alignBoth") -" set up the mappings to do nested comments -execute 'nnoremap ' . g:NERDComLineNestMap . ' :call NERDComment(0, "nested")' -execute 'vnoremap ' . g:NERDComLineNestMap . ' :call NERDComment(1, "nested")' +" nested comments +nnoremap NERDCommenterNest :call NERDComment(0, "nested") +vnoremap NERDCommenterNest :call NERDComment(1, "nested") -" set up the mapping to uncomment a line -execute 'nnoremap ' . g:NERDUncomLineMap . ' :call NERDComment(0, "uncomment")' -execute 'vnoremap ' . g:NERDUncomLineMap . ' :call NERDComment(1, "uncomment")' +" uncomment +nnoremap NERDCommenterUncomment :call NERDComment(0, "uncomment") +vnoremap NERDCommenterUncomment :call NERDComment(1, "uncomment") -" set up the mapping to comment out to the end of the line -execute 'nnoremap ' . g:NERDComToEOLMap . ' :call NERDComment(0, "toEOL")' +" comment till the end of the line +nnoremap NERDCommenterToEOL :call NERDComment(0, "toEOL") -" set up the mappings to append comments to the line -execute 'nmap ' . g:NERDAppendComMap . ' :call NERDComment(0, "append")' +" append comments +nmap NERDCommenterAppend :call NERDComment(0, "append") -" set up the mappings to append comments to the line -execute 'nmap ' . g:NERDPrependComMap . ' :call NERDComment(0, "prepend")' +" prepend comments +nmap NERDCommenterPrepend :call NERDComment(0, "prepend") -" set up the mapping to insert comment delims at the cursor position in insert mode -if g:NERDComInInsertMap != '' - execute 'inoremap ' . g:NERDComInInsertMap . ' ' . ':call NERDComment(0, "insert")' +" insert comments +inoremap NERDCommenterInInsert :call NERDComment(0, "insert") + + +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('NERDCommenterComment', 'cc') + call s:CreateMaps('NERDCommenterToggle', 'c') + call s:CreateMaps('NERDCommenterMinimal', 'cm') + call s:CreateMaps('NERDCommenterSexy', 'cs') + call s:CreateMaps('NERDCommenterInvert', 'ci') + call s:CreateMaps('NERDCommenterYank', 'cy') + call s:CreateMaps('NERDCommenterAlignLeft', 'cl') + call s:CreateMaps('NERDCommenterAlignRight', 'cr') + call s:CreateMaps('NERDCommenterAlignBoth', 'cb') + call s:CreateMaps('NERDCommenterNest', 'cn') + call s:CreateMaps('NERDCommenterUncomment', 'cu') + call s:CreateMaps('NERDCommenterToEOL', 'c$') + call s:CreateMaps('NERDCommenterAppend', 'cA') + call s:CreateMaps('NERDCommenterPrepend', 'cI') + + if !hasmapto('NERDCommenterAltDelims', 'n') + nmap ca 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 '. menuRoot .'.Comment' . escape(g:NERDComLineMap, '\') . ' :call NERDComment(0, "norm")' - execute 'vmenu '. menuRoot .'.Comment' . escape(g:NERDComLineMap, '\') . ' :call NERDComment(1, "norm")' - - execute 'nmenu '. menuRoot .'.Comment\ Toggle' . escape(g:NERDComLineToggleMap, '\') . ' :call NERDComment(0, "toggle")' - execute 'vmenu '. menuRoot .'.Comment\ Toggle' . escape(g:NERDComLineToggleMap, '\') . ' :call NERDComment(1, "toggle")' - - execute 'nmenu '. menuRoot .'.Comment\ Minimal' . escape(g:NERDComLineMinimalMap, '\') . ' :call NERDComment(0, "minimal")' - execute 'vmenu '. menuRoot .'.Comment\ Minimal' . escape(g:NERDComLineMinimalMap, '\') . ' :call NERDComment(1, "minimal")' - - execute 'nmenu '. menuRoot .'.Comment\ Nested' . escape(g:NERDComLineNestMap, '\') . ' :call NERDComment(0, "nested")' - execute 'vmenu '. menuRoot .'.Comment\ Nested' . escape(g:NERDComLineNestMap, '\') . ' :call NERDComment(1, "nested")' - - execute 'nmenu '. menuRoot .'.Comment\ To\ EOL' . escape(g:NERDComToEOLMap, '\') . ' :call NERDComment(0, "toEOL")' - - execute 'nmenu '. menuRoot .'.Comment\ Invert' . escape(g:NERDComLineInvertMap, '\') . ' :call NERDComment(0,"invert")' - execute 'vmenu '. menuRoot .'.Comment\ Invert' . escape(g:NERDComLineInvertMap, '\') . ' :call NERDComment(1,"invert")' - - execute 'nmenu '. menuRoot .'.Comment\ Sexily' . escape(g:NERDComLineSexyMap, '\') . ' :call NERDComment(0,"sexy")' - execute 'vmenu '. menuRoot .'.Comment\ Sexily' . escape(g:NERDComLineSexyMap, '\') . ' :call NERDComment(1,"sexy")' - - execute 'nmenu '. menuRoot .'.Yank\ line(s)\ then\ comment' . escape(g:NERDComLineYankMap, '\') . ' "0Y' . g:NERDComLineMap - execute 'vmenu '. menuRoot .'.Yank\ line(s)\ then\ comment' . escape(g:NERDComLineYankMap, '\') . ' "0ygv' . g:NERDComLineMap - - execute 'nmenu '. menuRoot .'.Append\ Comment\ to\ Line' . escape(g:NERDAppendComMap, '\') . ' :call NERDComment(0, "append")' - execute 'nmenu '. menuRoot .'.Prepend\ Comment\ to\ Line' . escape(g:NERDPrependComMap, '\') . ' :call NERDComment(0, "prepend")' - - execute 'menu '. menuRoot .'.-Sep- :' - - execute 'nmenu '. menuRoot .'.Comment\ Align\ Left\ (nested)' . escape(g:NERDComAlignLeftMap, '\') . ' :call NERDComment(0, "alignLeft")' - execute 'vmenu '. menuRoot .'.Comment\ Align\ Left\ (nested)' . escape(g:NERDComAlignLeftMap, '\') . ' :call NERDComment(1, "alignLeft")' - - execute 'nmenu '. menuRoot .'.Comment\ Align\ Right\ (nested)' . escape(g:NERDComAlignRightMap, '\') . ' :call NERDComment(0, "alignRight")' - execute 'vmenu '. menuRoot .'.Comment\ Align\ Right\ (nested)' . escape(g:NERDComAlignRightMap, '\') . ' :call NERDComment(1, "alignRight")' - - execute 'nmenu '. menuRoot .'.Comment\ Align\ Both\ (nested)' . escape(g:NERDComAlignBothMap, '\') . ' :call NERDComment(0, "alignBoth")' - execute 'vmenu '. menuRoot .'.Comment\ Align\ Both\ (nested)' . escape(g:NERDComAlignBothMap, '\') . ' :call NERDComment(1, "alignBoth")' - - execute 'menu '. menuRoot .'.-Sep2- :' - - execute 'menu '. menuRoot .'.Uncomment' . escape(g:NERDUncomLineMap, '\') . ' :call NERDComment(0, "uncomment")' - execute 'vmenu ' . menuRoot.'.Uncomment' . escape(g:NERDUncomLineMap, '\') . ' :call NERDComment(1, "uncomment")' - - execute 'menu '. menuRoot .'.-Sep3- :' - - execute 'nmenu '. menuRoot .'.Use\ Alternative\ Delimiters' . escape(g:NERDAltComMap, '\') . ' :call SwitchToAlternativeDelimiters(1)' - - - execute 'imenu '. menuRoot .'.Insert\ Delims' . escape(g:NERDComInInsertMap, '\') . ' :call NERDComment(0, "insert")' - - execute 'menu '. menuRoot .'.-Sep4- :' - - execute 'menu '. menuRoot .'.Help:help\ NERDCommenterContents :help NERDCommenterContents' + function! s:CreateMenuItems(target, desc, root) + exec 'nmenu ' . a:root . '.' . a:desc . ' ' . a:target + exec 'vmenu ' . a:root . '.' . a:desc . ' ' . a:target + endfunction + call s:CreateMenuItems("NERDCommenterComment", 'Comment', menuRoot) + call s:CreateMenuItems("NERDCommenterToggle", 'Toggle', menuRoot) + call s:CreateMenuItems('NERDCommenterMinimal', 'Minimal', menuRoot) + call s:CreateMenuItems('NERDCommenterNest', 'Nested', menuRoot) + exec 'nmenu '. menuRoot .'.To\ EOL NERDCommenterToEOL' + call s:CreateMenuItems('NERDCommenterInvert', 'Invert', menuRoot) + call s:CreateMenuItems('NERDCommenterSexy', 'Sexy', menuRoot) + call s:CreateMenuItems('NERDCommenterYank', 'Yank\ then\ comment', menuRoot) + exec 'nmenu '. menuRoot .'.Append NERDCommenterAppend' + exec 'nmenu '. menuRoot .'.Prepend NERDCommenterPrepend' + exec 'menu '. menuRoot .'.-Sep- :' + call s:CreateMenuItems('NERDCommenterAlignLeft', 'Left\ aligned', menuRoot) + call s:CreateMenuItems('NERDCommenterAlignRight', 'Right\ aligned', menuRoot) + call s:CreateMenuItems('NERDCommenterAlignBoth', 'Left\ and\ right\ aligned', menuRoot) + exec 'menu '. menuRoot .'.-Sep2- :' + call s:CreateMenuItems('NERDCommenterUncomment', 'Uncomment', menuRoot) + exec 'nmenu '. menuRoot .'.Switch\ Delimiters NERDCommenterAltDelims' + exec 'imenu '. menuRoot .'.Insert\ Comment\ Here NERDCommenterInInsert' + exec 'menu '. menuRoot .'.-Sep3- :' + exec 'menu '. menuRoot .'.Help :help NERDCommenterContents' endif " vim: set foldmethod=marker :