From e5b158fe757edc21e2c539fa4fd544a6fe04c554 Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Tue, 6 Dec 2011 09:33:21 -0500 Subject: [PATCH 01/12] Added modes argument, deleted root argument from s:CreateMenuItems(). --- plugin/NERD_commenter.vim | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 6cb7dbe..f881453 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -3,7 +3,7 @@ " Description: vim global plugin that provides easy code commenting " Maintainer: Martin Grenfell " Version: 2.3.0 -" Last Change: 08th December, 2010 +" Last Change: Tue Dec 06 09:00 AM 2011 Eastern Standard Time " License: This program is free software. It comes without any warranty, " to the extent permitted by applicable law. You can redistribute " it and/or modify it under the terms of the Do What The Fuck You @@ -2785,31 +2785,32 @@ if g:NERDMenuMode != 0 let menuRoot = "" if g:NERDMenuMode == 1 - let menuRoot = 'comment' + let menuRoot = 'comment' elseif g:NERDMenuMode == 2 - let menuRoot = '&comment' + let menuRoot = '&comment' elseif g:NERDMenuMode == 3 - let menuRoot = '&Plugin.&comment' + let menuRoot = '&Plugin.&comment' endif - function! s:CreateMenuItems(target, desc, root) - exec 'nmenu ' . a:root . '.' . a:desc . ' ' . a:target - exec 'vmenu ' . a:root . '.' . a:desc . ' ' . a:target + function! s:CreateMenuItems(modes, target, desc) + for mode in split(a:modes, '\zs') + exec mode . 'menu ' . g:menuRoot . '.' . a:desc . ' ' . a:target + endfor 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) + call s:CreateMenuItems('nv', 'NERDCommenterComment', 'Comment') + call s:CreateMenuItems('nv', 'NERDCommenterToggle', 'Toggle') + call s:CreateMenuItems('nv', 'NERDCommenterMinimal', 'Minimal') + call s:CreateMenuItems('nv', 'NERDCommenterNest', 'Nested') 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) + call s:CreateMenuItems('nv', 'NERDCommenterInvert', 'Invert') + call s:CreateMenuItems('nv', 'NERDCommenterSexy', 'Sexy') + call s:CreateMenuItems('nv', 'NERDCommenterYank', 'Yank\ then\ comment') exec 'nmenu '. menuRoot .'.Append NERDCommenterAppend' exec 'menu '. menuRoot .'.-Sep- :' - call s:CreateMenuItems('NERDCommenterAlignLeft', 'Left\ aligned', menuRoot) - call s:CreateMenuItems('NERDCommenterAlignBoth', 'Left\ and\ right\ aligned', menuRoot) + call s:CreateMenuItems('nv', 'NERDCommenterAlignLeft', 'Left\ aligned') + call s:CreateMenuItems('nv', 'NERDCommenterAlignBoth', 'Left\ and\ right\ aligned') exec 'menu '. menuRoot .'.-Sep2- :' - call s:CreateMenuItems('NERDCommenterUncomment', 'Uncomment', menuRoot) + call s:CreateMenuItems('nv', 'NERDCommenterUncomment', 'Uncomment') exec 'nmenu '. menuRoot .'.Switch\ Delimiters NERDCommenterAltDelims' exec 'imenu '. menuRoot .'.Insert\ Comment\ Here NERDCommenterInInsert' exec 'menu '. menuRoot .'.-Sep3- :' From b141adda9e31aa83a8928e22c3e8f841839fd376 Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Tue, 6 Dec 2011 09:56:48 -0500 Subject: [PATCH 02/12] Replaced all :exec 'menu' lines with calls to s:CreateMenuItems(). --- plugin/NERD_commenter.vim | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index f881453..3317c1e 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -2793,7 +2793,8 @@ if g:NERDMenuMode != 0 endif function! s:CreateMenuItems(modes, target, desc) - for mode in split(a:modes, '\zs') + let modes = (a:modes == '') ? [''] : split(a:modes, '\zs') + for mode in modes exec mode . 'menu ' . g:menuRoot . '.' . a:desc . ' ' . a:target endfor endfunction @@ -2801,19 +2802,19 @@ if g:NERDMenuMode != 0 call s:CreateMenuItems('nv', 'NERDCommenterToggle', 'Toggle') call s:CreateMenuItems('nv', 'NERDCommenterMinimal', 'Minimal') call s:CreateMenuItems('nv', 'NERDCommenterNest', 'Nested') - exec 'nmenu '. menuRoot .'.To\ EOL NERDCommenterToEOL' + call s:CreateMenuItems('n', 'NERDCommenterToEOL', 'To\ EOL') call s:CreateMenuItems('nv', 'NERDCommenterInvert', 'Invert') call s:CreateMenuItems('nv', 'NERDCommenterSexy', 'Sexy') call s:CreateMenuItems('nv', 'NERDCommenterYank', 'Yank\ then\ comment') - exec 'nmenu '. menuRoot .'.Append NERDCommenterAppend' - exec 'menu '. menuRoot .'.-Sep- :' + call s:CreateMenuItems('n', 'NERDCommenterAppend', 'Append') + call s:CreateMenuItems('', ':', '-Sep-') call s:CreateMenuItems('nv', 'NERDCommenterAlignLeft', 'Left\ aligned') call s:CreateMenuItems('nv', 'NERDCommenterAlignBoth', 'Left\ and\ right\ aligned') - exec 'menu '. menuRoot .'.-Sep2- :' + call s:CreateMenuItems('', ':', '-Sep2-') call s:CreateMenuItems('nv', 'NERDCommenterUncomment', 'Uncomment') - exec 'nmenu '. menuRoot .'.Switch\ Delimiters NERDCommenterAltDelims' - exec 'imenu '. menuRoot .'.Insert\ Comment\ Here NERDCommenterInInsert' - exec 'menu '. menuRoot .'.-Sep3- :' - exec 'menu '. menuRoot .'.Help :help NERDCommenterContents' + call s:CreateMenuItems('n', 'NERDCommenterAltDelims', 'Switch\ Delimiters') + call s:CreateMenuItems('i', 'NERDCommenterInInsert', 'Insert\ Comment\ Here') + call s:CreateMenuItems('', ':', '-Sep3-') + call s:CreateMenuItems('', ':help NERDCommenterContents', 'Help') endif " vim: set foldmethod=marker : From 1d40b1965ce46a57d23ef80f6d0e3ac6564f73ff Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Tue, 6 Dec 2011 10:01:35 -0500 Subject: [PATCH 03/12] Replaced global variable menuRoot with a function-local variable. --- plugin/NERD_commenter.vim | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 3317c1e..b7614af 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -3,7 +3,7 @@ " Description: vim global plugin that provides easy code commenting " Maintainer: Martin Grenfell " Version: 2.3.0 -" Last Change: Tue Dec 06 09:00 AM 2011 Eastern Standard Time +" Last Change: Tue Dec 06 10:00 AM 2011 Eastern Standard Time " License: This program is free software. It comes without any warranty, " to the extent permitted by applicable law. You can redistribute " it and/or modify it under the terms of the Do What The Fuck You @@ -2783,19 +2783,13 @@ endif "check if the user wants the menu to be displayed if g:NERDMenuMode != 0 - let menuRoot = "" - if g:NERDMenuMode == 1 - let menuRoot = 'comment' - elseif g:NERDMenuMode == 2 - let menuRoot = '&comment' - elseif g:NERDMenuMode == 3 - let menuRoot = '&Plugin.&comment' - endif - function! s:CreateMenuItems(modes, target, desc) + let menuRoot = get(['', 'comment', '&comment', '&Plugin.&comment'], + \ g:NERDMenuMode, '') + let command = 'menu ' . menuRoot . '.' let modes = (a:modes == '') ? [''] : split(a:modes, '\zs') for mode in modes - exec mode . 'menu ' . g:menuRoot . '.' . a:desc . ' ' . a:target + exec mode . command . a:desc . ' ' . a:target endfor endfunction call s:CreateMenuItems('nv', 'NERDCommenterComment', 'Comment') From 9b9c25368028a8fae5eae54245c9c1e8d389d128 Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Tue, 6 Dec 2011 10:54:28 -0500 Subject: [PATCH 04/12] Added keyboard shortcuts to the GUI menu. --- plugin/NERD_commenter.vim | 55 +++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index b7614af..084781b 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -2761,15 +2761,15 @@ 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('NERDCommenterNest', 'cn') + call s:CreateMaps('NERDCommenterToEOL', 'c$') call s:CreateMaps('NERDCommenterInvert', 'ci') + call s:CreateMaps('NERDCommenterSexy', 'cs') call s:CreateMaps('NERDCommenterYank', 'cy') + call s:CreateMaps('NERDCommenterAppend', 'cA') call s:CreateMaps('NERDCommenterAlignLeft', 'cl') 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') if !hasmapto('NERDCommenterAltDelims', 'n') nmap ca NERDCommenterAltDelims @@ -2783,32 +2783,37 @@ endif "check if the user wants the menu to be displayed if g:NERDMenuMode != 0 - function! s:CreateMenuItems(modes, target, desc) + function! s:CreateMenuItems(modes, target, desc, combo) let menuRoot = get(['', 'comment', '&comment', '&Plugin.&comment'], \ g:NERDMenuMode, '') - let command = 'menu ' . menuRoot . '.' + let command = 'menu ' . menuRoot . '.' . escape(a:desc, ' ') + let leader = escape(exists('mapleader') ? mapleader : '\', '\') + if strlen(a:combo) + let command .= '' . leader . a:combo + endif + let command .= ' ' . a:target let modes = (a:modes == '') ? [''] : split(a:modes, '\zs') for mode in modes - exec mode . command . a:desc . ' ' . a:target + exec mode . command endfor endfunction - call s:CreateMenuItems('nv', 'NERDCommenterComment', 'Comment') - call s:CreateMenuItems('nv', 'NERDCommenterToggle', 'Toggle') - call s:CreateMenuItems('nv', 'NERDCommenterMinimal', 'Minimal') - call s:CreateMenuItems('nv', 'NERDCommenterNest', 'Nested') - call s:CreateMenuItems('n', 'NERDCommenterToEOL', 'To\ EOL') - call s:CreateMenuItems('nv', 'NERDCommenterInvert', 'Invert') - call s:CreateMenuItems('nv', 'NERDCommenterSexy', 'Sexy') - call s:CreateMenuItems('nv', 'NERDCommenterYank', 'Yank\ then\ comment') - call s:CreateMenuItems('n', 'NERDCommenterAppend', 'Append') - call s:CreateMenuItems('', ':', '-Sep-') - call s:CreateMenuItems('nv', 'NERDCommenterAlignLeft', 'Left\ aligned') - call s:CreateMenuItems('nv', 'NERDCommenterAlignBoth', 'Left\ and\ right\ aligned') - call s:CreateMenuItems('', ':', '-Sep2-') - call s:CreateMenuItems('nv', 'NERDCommenterUncomment', 'Uncomment') - call s:CreateMenuItems('n', 'NERDCommenterAltDelims', 'Switch\ Delimiters') - call s:CreateMenuItems('i', 'NERDCommenterInInsert', 'Insert\ Comment\ Here') - call s:CreateMenuItems('', ':', '-Sep3-') - call s:CreateMenuItems('', ':help NERDCommenterContents', 'Help') + call s:CreateMenuItems('nv', 'NERDCommenterComment', 'Comment', 'cc') + call s:CreateMenuItems('nv', 'NERDCommenterToggle', 'Toggle', 'c') + call s:CreateMenuItems('nv', 'NERDCommenterMinimal', 'Minimal', 'cm') + call s:CreateMenuItems('nv', 'NERDCommenterNest', 'Nested', 'cn') + call s:CreateMenuItems('n', 'NERDCommenterToEOL', 'To EOL', 'c$') + call s:CreateMenuItems('nv', 'NERDCommenterInvert', 'Invert', 'ci') + call s:CreateMenuItems('nv', 'NERDCommenterSexy', 'Sexy', 'cs') + call s:CreateMenuItems('nv', 'NERDCommenterYank', 'Yank then comment', 'cy') + call s:CreateMenuItems('n', 'NERDCommenterAppend', 'Append', 'cA') + call s:CreateMenuItems('', ':', '-Sep-', '') + call s:CreateMenuItems('nv', 'NERDCommenterAlignLeft', 'Left aligned', 'cl') + call s:CreateMenuItems('nv', 'NERDCommenterAlignBoth', 'Left and right aligned', 'cb') + call s:CreateMenuItems('', ':', '-Sep2-', '') + call s:CreateMenuItems('nv', 'NERDCommenterUncomment', 'Uncomment', 'cu') + call s:CreateMenuItems('n', 'NERDCommenterAltDelims', 'Switch Delimiters', 'ca') + call s:CreateMenuItems('i', 'NERDCommenterInInsert', 'Insert Comment Here', '') + call s:CreateMenuItems('', ':', '-Sep3-', '') + call s:CreateMenuItems('', ':help NERDCommenterContents', 'Help', '') endif " vim: set foldmethod=marker : From 0bb5f7e8894974d228cd5105a870d3503a8fa64b Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Tue, 6 Dec 2011 11:29:25 -0500 Subject: [PATCH 05/12] Removed s:CreateMaps(), adding its functionality to s:CreateMenuItems(). --- plugin/NERD_commenter.vim | 107 ++++++++++++++------------------------ 1 file changed, 40 insertions(+), 67 deletions(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 084781b..c8b5349 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -3,7 +3,7 @@ " Description: vim global plugin that provides easy code commenting " Maintainer: Martin Grenfell " Version: 2.3.0 -" Last Change: Tue Dec 06 10:00 AM 2011 Eastern Standard Time +" Last Change: Tue Dec 06 11:00 AM 2011 Eastern Standard Time " License: This program is free software. It comes without any warranty, " to the extent permitted by applicable law. You can redistribute " it and/or modify it under the terms of the Do What The Fuck You @@ -2746,74 +2746,47 @@ nmap NERDCommenterAppend :call NERDComment(0, "append") " 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('NERDCommenterNest', 'cn') - call s:CreateMaps('NERDCommenterToEOL', 'c$') - call s:CreateMaps('NERDCommenterInvert', 'ci') - call s:CreateMaps('NERDCommenterSexy', 'cs') - call s:CreateMaps('NERDCommenterYank', 'cy') - call s:CreateMaps('NERDCommenterAppend', 'cA') - call s:CreateMaps('NERDCommenterAlignLeft', 'cl') - call s:CreateMaps('NERDCommenterAlignBoth', 'cb') - call s:CreateMaps('NERDCommenterUncomment', 'cu') - - if !hasmapto('NERDCommenterAltDelims', 'n') - nmap ca NERDCommenterAltDelims - endif -endif - - - " Section: Menu item setup {{{1 " =========================================================================== -"check if the user wants the menu to be displayed -if g:NERDMenuMode != 0 - function! s:CreateMenuItems(modes, target, desc, combo) - let menuRoot = get(['', 'comment', '&comment', '&Plugin.&comment'], - \ g:NERDMenuMode, '') - let command = 'menu ' . menuRoot . '.' . escape(a:desc, ' ') - let leader = escape(exists('mapleader') ? mapleader : '\', '\') - if strlen(a:combo) - let command .= '' . leader . a:combo - endif - let command .= ' ' . a:target - let modes = (a:modes == '') ? [''] : split(a:modes, '\zs') - for mode in modes +" Create menu items for the specified modes. If a:combo is not empty, then +" also define mappings and show a:combo in the menu items. +function! s:CreateMenuItems(modes, target, desc, combo) + let menuRoot = get(['', 'comment', '&comment', '&Plugin.&comment'], + \ g:NERDMenuMode, '') + let leader = escape(exists('mapleader') ? mapleader : '\', '\') + let command = 'menu ' . menuRoot . '.' . escape(a:desc, ' ') + if strlen(a:combo) + let command .= '' . leader . a:combo + endif + let command .= ' ' . a:target + for mode in (a:modes == '') ? [''] : split(a:modes, '\zs') + if g:NERDCreateDefaultMappings + \ && strlen(a:combo) && !hasmapto(a:target, mode) + exec mode . 'map ' . a:combo . ' ' . a:target + endif + "check if the user wants the menu to be displayed + if g:NERDMenuMode != 0 exec mode . command - endfor - endfunction - call s:CreateMenuItems('nv', 'NERDCommenterComment', 'Comment', 'cc') - call s:CreateMenuItems('nv', 'NERDCommenterToggle', 'Toggle', 'c') - call s:CreateMenuItems('nv', 'NERDCommenterMinimal', 'Minimal', 'cm') - call s:CreateMenuItems('nv', 'NERDCommenterNest', 'Nested', 'cn') - call s:CreateMenuItems('n', 'NERDCommenterToEOL', 'To EOL', 'c$') - call s:CreateMenuItems('nv', 'NERDCommenterInvert', 'Invert', 'ci') - call s:CreateMenuItems('nv', 'NERDCommenterSexy', 'Sexy', 'cs') - call s:CreateMenuItems('nv', 'NERDCommenterYank', 'Yank then comment', 'cy') - call s:CreateMenuItems('n', 'NERDCommenterAppend', 'Append', 'cA') - call s:CreateMenuItems('', ':', '-Sep-', '') - call s:CreateMenuItems('nv', 'NERDCommenterAlignLeft', 'Left aligned', 'cl') - call s:CreateMenuItems('nv', 'NERDCommenterAlignBoth', 'Left and right aligned', 'cb') - call s:CreateMenuItems('', ':', '-Sep2-', '') - call s:CreateMenuItems('nv', 'NERDCommenterUncomment', 'Uncomment', 'cu') - call s:CreateMenuItems('n', 'NERDCommenterAltDelims', 'Switch Delimiters', 'ca') - call s:CreateMenuItems('i', 'NERDCommenterInInsert', 'Insert Comment Here', '') - call s:CreateMenuItems('', ':', '-Sep3-', '') - call s:CreateMenuItems('', ':help NERDCommenterContents', 'Help', '') -endif + endif + endfor +endfunction +call s:CreateMenuItems('nv', 'NERDCommenterComment', 'Comment', 'cc') +call s:CreateMenuItems('nv', 'NERDCommenterToggle', 'Toggle', 'c') +call s:CreateMenuItems('nv', 'NERDCommenterMinimal', 'Minimal', 'cm') +call s:CreateMenuItems('nv', 'NERDCommenterNest', 'Nested', 'cn') +call s:CreateMenuItems('n', 'NERDCommenterToEOL', 'To EOL', 'c$') +call s:CreateMenuItems('nv', 'NERDCommenterInvert', 'Invert', 'ci') +call s:CreateMenuItems('nv', 'NERDCommenterSexy', 'Sexy', 'cs') +call s:CreateMenuItems('nv', 'NERDCommenterYank', 'Yank then comment', 'cy') +call s:CreateMenuItems('n', 'NERDCommenterAppend', 'Append', 'cA') +call s:CreateMenuItems('', ':', '-Sep-', '') +call s:CreateMenuItems('nv', 'NERDCommenterAlignLeft', 'Left aligned', 'cl') +call s:CreateMenuItems('nv', 'NERDCommenterAlignBoth', 'Left and right aligned', 'cb') +call s:CreateMenuItems('', ':', '-Sep2-', '') +call s:CreateMenuItems('nv', 'NERDCommenterUncomment', 'Uncomment', 'cu') +call s:CreateMenuItems('n', 'NERDCommenterAltDelims', 'Switch Delimiters', 'ca') +call s:CreateMenuItems('i', 'NERDCommenterInInsert', 'Insert Comment Here', '') +call s:CreateMenuItems('', ':', '-Sep3-', '') +call s:CreateMenuItems('', ':help NERDCommenterContents', 'Help', '') " vim: set foldmethod=marker : From 68cfa2f3c5947878235ad955a637a51805a251d7 Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Tue, 6 Dec 2011 11:33:56 -0500 Subject: [PATCH 06/12] Changed s:CreateMenuItems() to the shorter s:CreateMaps(). --- plugin/NERD_commenter.vim | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index c8b5349..fab722c 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -2751,7 +2751,7 @@ inoremap NERDCommenterInInsert :call NERDComment( " Create menu items for the specified modes. If a:combo is not empty, then " also define mappings and show a:combo in the menu items. -function! s:CreateMenuItems(modes, target, desc, combo) +function! s:CreateMaps(modes, target, desc, combo) let menuRoot = get(['', 'comment', '&comment', '&Plugin.&comment'], \ g:NERDMenuMode, '') let leader = escape(exists('mapleader') ? mapleader : '\', '\') @@ -2771,22 +2771,22 @@ function! s:CreateMenuItems(modes, target, desc, combo) endif endfor endfunction -call s:CreateMenuItems('nv', 'NERDCommenterComment', 'Comment', 'cc') -call s:CreateMenuItems('nv', 'NERDCommenterToggle', 'Toggle', 'c') -call s:CreateMenuItems('nv', 'NERDCommenterMinimal', 'Minimal', 'cm') -call s:CreateMenuItems('nv', 'NERDCommenterNest', 'Nested', 'cn') -call s:CreateMenuItems('n', 'NERDCommenterToEOL', 'To EOL', 'c$') -call s:CreateMenuItems('nv', 'NERDCommenterInvert', 'Invert', 'ci') -call s:CreateMenuItems('nv', 'NERDCommenterSexy', 'Sexy', 'cs') -call s:CreateMenuItems('nv', 'NERDCommenterYank', 'Yank then comment', 'cy') -call s:CreateMenuItems('n', 'NERDCommenterAppend', 'Append', 'cA') -call s:CreateMenuItems('', ':', '-Sep-', '') -call s:CreateMenuItems('nv', 'NERDCommenterAlignLeft', 'Left aligned', 'cl') -call s:CreateMenuItems('nv', 'NERDCommenterAlignBoth', 'Left and right aligned', 'cb') -call s:CreateMenuItems('', ':', '-Sep2-', '') -call s:CreateMenuItems('nv', 'NERDCommenterUncomment', 'Uncomment', 'cu') -call s:CreateMenuItems('n', 'NERDCommenterAltDelims', 'Switch Delimiters', 'ca') -call s:CreateMenuItems('i', 'NERDCommenterInInsert', 'Insert Comment Here', '') -call s:CreateMenuItems('', ':', '-Sep3-', '') -call s:CreateMenuItems('', ':help NERDCommenterContents', 'Help', '') +call s:CreateMaps('nv', 'NERDCommenterComment', 'Comment', 'cc') +call s:CreateMaps('nv', 'NERDCommenterToggle', 'Toggle', 'c') +call s:CreateMaps('nv', 'NERDCommenterMinimal', 'Minimal', 'cm') +call s:CreateMaps('nv', 'NERDCommenterNest', 'Nested', 'cn') +call s:CreateMaps('n', 'NERDCommenterToEOL', 'To EOL', 'c$') +call s:CreateMaps('nv', 'NERDCommenterInvert', 'Invert', 'ci') +call s:CreateMaps('nv', 'NERDCommenterSexy', 'Sexy', 'cs') +call s:CreateMaps('nv', 'NERDCommenterYank', 'Yank then comment', 'cy') +call s:CreateMaps('n', 'NERDCommenterAppend', 'Append', 'cA') +call s:CreateMaps('', ':', '-Sep-', '') +call s:CreateMaps('nv', 'NERDCommenterAlignLeft', 'Left aligned', 'cl') +call s:CreateMaps('nv', 'NERDCommenterAlignBoth', 'Left and right aligned', 'cb') +call s:CreateMaps('', ':', '-Sep2-', '') +call s:CreateMaps('nv', 'NERDCommenterUncomment', 'Uncomment', 'cu') +call s:CreateMaps('n', 'NERDCommenterAltDelims', 'Switch Delimiters', 'ca') +call s:CreateMaps('i', 'NERDCommenterInInsert', 'Insert Comment Here', '') +call s:CreateMaps('', ':', '-Sep3-', '') +call s:CreateMaps('', ':help NERDCommenterContents', 'Help', '') " vim: set foldmethod=marker : From a3ecc6dab512f20c2b52b786e766a7ec3c570317 Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Mon, 12 Dec 2011 08:18:47 -0500 Subject: [PATCH 07/12] Changed :vmap and :vmenu to :xmap and :xmenu. --- plugin/NERD_commenter.vim | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index ca8a999..3d63452 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -3,7 +3,7 @@ " Description: vim global plugin that provides easy code commenting " Maintainer: Martin Grenfell " Version: 2.3.0 -" Last Change: Tue Dec 06 11:00 AM 2011 Eastern Standard Time +" Last Change: Mon Dec 12 08:00 AM 2011 EST " License: This program is free software. It comes without any warranty, " to the extent permitted by applicable law. You can redistribute " it and/or modify it under the terms of the Do What The Fuck You @@ -2772,20 +2772,20 @@ function! s:CreateMaps(modes, target, desc, combo) endif endfor endfunction -call s:CreateMaps('nv', 'NERDCommenterComment', 'Comment', 'cc') -call s:CreateMaps('nv', 'NERDCommenterToggle', 'Toggle', 'c') -call s:CreateMaps('nv', 'NERDCommenterMinimal', 'Minimal', 'cm') -call s:CreateMaps('nv', 'NERDCommenterNest', 'Nested', 'cn') +call s:CreateMaps('nx', 'NERDCommenterComment', 'Comment', 'cc') +call s:CreateMaps('nx', 'NERDCommenterToggle', 'Toggle', 'c') +call s:CreateMaps('nx', 'NERDCommenterMinimal', 'Minimal', 'cm') +call s:CreateMaps('nx', 'NERDCommenterNest', 'Nested', 'cn') call s:CreateMaps('n', 'NERDCommenterToEOL', 'To EOL', 'c$') -call s:CreateMaps('nv', 'NERDCommenterInvert', 'Invert', 'ci') -call s:CreateMaps('nv', 'NERDCommenterSexy', 'Sexy', 'cs') -call s:CreateMaps('nv', 'NERDCommenterYank', 'Yank then comment', 'cy') +call s:CreateMaps('nx', 'NERDCommenterInvert', 'Invert', 'ci') +call s:CreateMaps('nx', 'NERDCommenterSexy', 'Sexy', 'cs') +call s:CreateMaps('nx', 'NERDCommenterYank', 'Yank then comment', 'cy') call s:CreateMaps('n', 'NERDCommenterAppend', 'Append', 'cA') call s:CreateMaps('', ':', '-Sep-', '') -call s:CreateMaps('nv', 'NERDCommenterAlignLeft', 'Left aligned', 'cl') -call s:CreateMaps('nv', 'NERDCommenterAlignBoth', 'Left and right aligned', 'cb') +call s:CreateMaps('nx', 'NERDCommenterAlignLeft', 'Left aligned', 'cl') +call s:CreateMaps('nx', 'NERDCommenterAlignBoth', 'Left and right aligned', 'cb') call s:CreateMaps('', ':', '-Sep2-', '') -call s:CreateMaps('nv', 'NERDCommenterUncomment', 'Uncomment', 'cu') +call s:CreateMaps('nx', 'NERDCommenterUncomment', 'Uncomment', 'cu') call s:CreateMaps('n', 'NERDCommenterAltDelims', 'Switch Delimiters', 'ca') call s:CreateMaps('i', 'NERDCommenterInInsert', 'Insert Comment Here', '') call s:CreateMaps('', ':', '-Sep3-', '') From 22e798edf5f00b3cdd96e62140112824146e786a Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Mon, 12 Dec 2011 10:13:28 -0500 Subject: [PATCH 08/12] Replaced a loop with a call to extend(). --- plugin/NERD_commenter.vim | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 3d63452..ae9026f 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -3,7 +3,7 @@ " Description: vim global plugin that provides easy code commenting " Maintainer: Martin Grenfell " Version: 2.3.0 -" Last Change: Mon Dec 12 08:00 AM 2011 EST +" Last Change: Mon Dec 12 10:00 AM 2011 EST " License: This program is free software. It comes without any warranty, " to the extent permitted by applicable law. You can redistribute " it and/or modify it under the terms of the Do What The Fuck You @@ -62,10 +62,6 @@ call s:InitVariable("g:NERDRemoveExtraSpaces", 0) call s:InitVariable("g:NERDRPlace", "<]") call s:InitVariable("g:NERDSpaceDelims", 0) -if !exists("g:NERDCustomDelimiters") - let g:NERDCustomDelimiters = {} -endif - let s:NERDFileNameEscape="[]#*$%'\" ?`!&();<>\\" let s:delimiterMap = { @@ -391,10 +387,9 @@ let s:delimiterMap = { \ 'z8a': { 'left': ';' } \ } -"merge in the custom delimiters -for ft in keys(g:NERDCustomDelimiters) - let s:delimiterMap[ft] = g:NERDCustomDelimiters[ft] -endfor +if exists("g:NERDCustomDelimiters") + call extend(s:delimiterMap, g:NERDCustomDelimiters) +endif " Section: Comment mapping functions, autocommands and commands {{{1 " ============================================================================ From f198e9ffce00e2981f638217253ec3077bad69b9 Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Mon, 12 Dec 2011 10:30:17 -0500 Subject: [PATCH 09/12] Replaced raw CTRL-V with \ --- plugin/NERD_commenter.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index ae9026f..005ee02 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -1049,7 +1049,7 @@ function! NERDComment(isVisual, type) range let forceNested = (a:type == 'nested' || g:NERDDefaultNesting) if a:type == 'norm' || a:type == 'nested' - if a:isVisual && visualmode() == "" + if a:isVisual && visualmode() == "\" call s:CommentBlock(firstLine, lastLine, firstCol, lastCol, forceNested) elseif a:isVisual && visualmode() == "v" && (g:NERDCommentWholeLinesInVMode==0 || (g:NERDCommentWholeLinesInVMode==2 && s:HasMultipartDelims())) call s:CommentRegion(firstLine, firstCol, lastLine, lastCol, forceNested) From 5dc223d8a6b67abd358428c3db32e4c94bb43161 Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Mon, 12 Dec 2011 11:10:19 -0500 Subject: [PATCH 10/12] Changed arguments to NerdComment() to make it easier to call from CreateMaps(). --- plugin/NERD_commenter.vim | 104 +++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 005ee02..eff63d1 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -3,7 +3,7 @@ " Description: vim global plugin that provides easy code commenting " Maintainer: Martin Grenfell " Version: 2.3.0 -" Last Change: Mon Dec 12 10:00 AM 2011 EST +" Last Change: Mon Dec 12 11:00 AM 2011 EST " License: This program is free software. It comes without any warranty, " to the extent permitted by applicable law. You can redistribute " it and/or modify it under the terms of the Do What The Fuck You @@ -1016,16 +1016,16 @@ function s:InvertComment(firstLine, lastLine) endwhile endfunction -" Function: NERDComment(isVisual, type) function {{{2 +" Function: s:NERDComment(mode, type) function {{{2 " This function is a Wrapper for the main commenting functions " " Args: -" -isVisual: a flag indicating whether the comment is requested in visual -" mode or not -" -type: the type of commenting requested. Can be 'sexy', 'invert', -" 'minimal', 'toggle', 'alignLeft', 'alignBoth', 'norm', -" 'nested', 'toEOL', 'append', 'insert', 'uncomment', 'yank' -function! NERDComment(isVisual, type) range +" -mode: a character indicating the mode in which the comment is requested: +" 'n' for Normal mode, 'v' for Visual mode +" -type: the type of commenting requested. Can be 'Sexy', 'Invert', +" 'Minimal', 'Toggle', 'AlignLeft', 'AlignBoth', 'Norm', +" 'Nested', 'ToEOL', 'Append', 'Insert', 'Uncomment', 'Yank' +function! s:NERDComment(mode, type) range " we want case sensitivity when commenting let oldIgnoreCase = &ignorecase set noignorecase @@ -1034,7 +1034,7 @@ function! NERDComment(isVisual, type) range call s:NerdEcho("filetype plugins should be enabled. See :help NERDComInstallation and :help :filetype-plugin-on", 0) endif - if a:isVisual + if a:mode == "v" let firstLine = line("'<") let lastLine = line("'>") let firstCol = col("'<") @@ -1044,32 +1044,32 @@ function! NERDComment(isVisual, type) range let lastLine = a:lastline endif - let countWasGiven = (a:isVisual == 0 && firstLine != lastLine) + let countWasGiven = (a:mode != "v" && firstLine != lastLine) - let forceNested = (a:type == 'nested' || g:NERDDefaultNesting) + let forceNested = (a:type == 'Nested' || g:NERDDefaultNesting) - if a:type == 'norm' || a:type == 'nested' - if a:isVisual && visualmode() == "\" + if a:type == 'Norm' || a:type == 'Nested' + if a:mode == "v" && visualmode() == "\" call s:CommentBlock(firstLine, lastLine, firstCol, lastCol, forceNested) - elseif a:isVisual && visualmode() == "v" && (g:NERDCommentWholeLinesInVMode==0 || (g:NERDCommentWholeLinesInVMode==2 && s:HasMultipartDelims())) + elseif a:mode == "v" && visualmode() == "v" && (g:NERDCommentWholeLinesInVMode==0 || (g:NERDCommentWholeLinesInVMode==2 && s:HasMultipartDelims())) call s:CommentRegion(firstLine, firstCol, lastLine, lastCol, forceNested) else call s:CommentLines(forceNested, "none", firstLine, lastLine) endif - elseif a:type == 'alignLeft' || a:type == 'alignBoth' + elseif a:type == 'AlignLeft' || a:type == 'AlignBoth' let align = "none" - if a:type == "alignLeft" + if a:type == "AlignLeft" let align = "left" - elseif a:type == "alignBoth" + elseif a:type == "AlignBoth" let align = "both" endif call s:CommentLines(forceNested, align, firstLine, lastLine) - elseif a:type == 'invert' + elseif a:type == 'Invert' call s:InvertComment(firstLine, lastLine) - elseif a:type == 'sexy' + elseif a:type == 'Sexy' try call s:CommentLinesSexy(firstLine, lastLine) catch /NERDCommenter.Delimiters/ @@ -1078,7 +1078,7 @@ function! NERDComment(isVisual, type) range call s:NerdEcho("Sexy comment aborted. Nested sexy cannot be nested", 0) endtry - elseif a:type == 'toggle' + elseif a:type == 'Toggle' let theLine = getline(firstLine) if s:IsInSexyComment(firstLine) || s:IsCommentedFromStartOfLine(s:Left(), theLine) || s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine) @@ -1087,7 +1087,7 @@ function! NERDComment(isVisual, type) range call s:CommentLinesToggle(forceNested, firstLine, lastLine) endif - elseif a:type == 'minimal' + elseif a:type == 'Minimal' try call s:CommentLinesMinimal(firstLine, lastLine) catch /NERDCommenter.Delimiters/ @@ -1096,29 +1096,29 @@ function! NERDComment(isVisual, type) range call s:NerdEcho("Place holders are required but disabled.", 0) endtry - elseif a:type == 'toEOL' + elseif a:type == 'ToEOL' call s:SaveScreenState() call s:CommentBlock(firstLine, firstLine, col("."), col("$")-1, 1) call s:RestoreScreenState() - elseif a:type == 'append' + elseif a:type == 'Append' call s:AppendCommentToLine() - elseif a:type == 'insert' + elseif a:type == 'Insert' call s:PlaceDelimitersAndInsBetween() - elseif a:type == 'uncomment' + elseif a:type == 'Uncomment' call s:UncommentLines(firstLine, lastLine) - elseif a:type == 'yank' - if a:isVisual + elseif a:type == 'Yank' + if a:mode == "v" normal! gvy elseif countWasGiven execute firstLine .','. lastLine .'yank' else normal! yy endif - execute firstLine .','. lastLine .'call NERDComment('. a:isVisual .', "norm")' + execute firstLine .','. lastLine .'call s:NERDComment('. a:mode .', "Norm")' endif let &ignorecase = oldIgnoreCase @@ -2694,53 +2694,53 @@ endfunction nnoremap NERDCommenterAltDelims :call SwitchToAlternativeDelimiters(1) " comment out lines -nnoremap NERDCommenterComment :call NERDComment(0, "norm") -vnoremap NERDCommenterComment :call NERDComment(1, "norm") +nnoremap NERDCommenterComment :call NERDComment("n", "Norm") +vnoremap NERDCommenterComment :call NERDComment("v", "Norm") " toggle comments -nnoremap NERDCommenterToggle :call NERDComment(0, "toggle") -vnoremap NERDCommenterToggle :call NERDComment(1, "toggle") +nnoremap NERDCommenterToggle :call NERDComment("n", "Toggle") +vnoremap NERDCommenterToggle :call NERDComment("v", "Toggle") " minimal comments -nnoremap NERDCommenterMinimal :call NERDComment(0, "minimal") -vnoremap NERDCommenterMinimal :call NERDComment(1, "minimal") +nnoremap NERDCommenterMinimal :call NERDComment("n", "Minimal") +vnoremap NERDCommenterMinimal :call NERDComment("v", "Minimal") " sexy comments -nnoremap NERDCommenterSexy :call NERDComment(0, "sexy") -vnoremap NERDCommenterSexy :call NERDComment(1, "sexy") +nnoremap NERDCommenterSexy :call NERDComment("n", "Sexy") +vnoremap NERDCommenterSexy :call NERDComment("v", "Sexy") " invert comments -nnoremap NERDCommenterInvert :call NERDComment(0, "invert") -vnoremap NERDCommenterInvert :call NERDComment(1, "invert") +nnoremap NERDCommenterInvert :call NERDComment("n", "Invert") +vnoremap NERDCommenterInvert :call NERDComment("v", "Invert") " yank then comment -nmap NERDCommenterYank :call NERDComment(0, "yank") -vmap NERDCommenterYank :call NERDComment(1, "yank") +nmap NERDCommenterYank :call NERDComment("n", "Yank") +vmap NERDCommenterYank :call NERDComment("v", "Yank") " left aligned comments -nnoremap NERDCommenterAlignLeft :call NERDComment(0, "alignLeft") -vnoremap NERDCommenterAlignLeft :call NERDComment(1, "alignLeft") +nnoremap NERDCommenterAlignLeft :call NERDComment("n", "AlignLeft") +vnoremap NERDCommenterAlignLeft :call NERDComment("v", "AlignLeft") " left and right aligned comments -nnoremap NERDCommenterAlignBoth :call NERDComment(0, "alignBoth") -vnoremap NERDCommenterAlignBoth :call NERDComment(1, "alignBoth") +nnoremap NERDCommenterAlignBoth :call NERDComment("n", "AlignBoth") +vnoremap NERDCommenterAlignBoth :call NERDComment("v", "AlignBoth") " nested comments -nnoremap NERDCommenterNest :call NERDComment(0, "nested") -vnoremap NERDCommenterNest :call NERDComment(1, "nested") +nnoremap NERDCommenterNest :call NERDComment("n", "Nested") +vnoremap NERDCommenterNest :call NERDComment("v", "Nested") " uncomment -nnoremap NERDCommenterUncomment :call NERDComment(0, "uncomment") -vnoremap NERDCommenterUncomment :call NERDComment(1, "uncomment") +nnoremap NERDCommenterUncomment :call NERDComment("n", "Uncomment") +vnoremap NERDCommenterUncomment :call NERDComment("v", "Uncomment") " comment till the end of the line -nnoremap NERDCommenterToEOL :call NERDComment(0, "toEOL") +nnoremap NERDCommenterToEOL :call NERDComment("n", "ToEOL") " append comments -nmap NERDCommenterAppend :call NERDComment(0, "append") +nmap NERDCommenterAppend :call NERDComment("n", "Append") " insert comments -inoremap NERDCommenterInInsert :call NERDComment(0, "insert") +inoremap NERDCommenterInsert :call NERDComment("n", "Insert") " Section: Menu item setup {{{1 " =========================================================================== @@ -2782,7 +2782,7 @@ call s:CreateMaps('nx', 'NERDCommenterAlignBoth', 'Left and right aligned', 'cb call s:CreateMaps('', ':', '-Sep2-', '') call s:CreateMaps('nx', 'NERDCommenterUncomment', 'Uncomment', 'cu') call s:CreateMaps('n', 'NERDCommenterAltDelims', 'Switch Delimiters', 'ca') -call s:CreateMaps('i', 'NERDCommenterInInsert', 'Insert Comment Here', '') +call s:CreateMaps('i', 'NERDCommenterInsert', 'Insert Comment Here', '') call s:CreateMaps('', ':', '-Sep3-', '') call s:CreateMaps('', ':help NERDCommenterContents', 'Help', '') " vim: set foldmethod=marker : From 0bffc1a1193cca5ed51d3175f8e56688e683a8f6 Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Mon, 12 Dec 2011 22:28:48 -0500 Subject: [PATCH 11/12] Moved the mappings into s:CreateMaps(). --- plugin/NERD_commenter.vim | 71 ++++++--------------------------------- 1 file changed, 10 insertions(+), 61 deletions(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index eff63d1..3318011 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -3,7 +3,7 @@ " Description: vim global plugin that provides easy code commenting " Maintainer: Martin Grenfell " Version: 2.3.0 -" Last Change: Mon Dec 12 11:00 AM 2011 EST +" Last Change: Mon Dec 12 10:00 PM 2011 EST " License: This program is free software. It comes without any warranty, " to the extent permitted by applicable law. You can redistribute " it and/or modify it under the terms of the Do What The Fuck You @@ -1023,7 +1023,7 @@ endfunction " -mode: a character indicating the mode in which the comment is requested: " 'n' for Normal mode, 'v' for Visual mode " -type: the type of commenting requested. Can be 'Sexy', 'Invert', -" 'Minimal', 'Toggle', 'AlignLeft', 'AlignBoth', 'Norm', +" 'Minimal', 'Toggle', 'AlignLeft', 'AlignBoth', 'Comment', " 'Nested', 'ToEOL', 'Append', 'Insert', 'Uncomment', 'Yank' function! s:NERDComment(mode, type) range " we want case sensitivity when commenting @@ -1048,7 +1048,7 @@ function! s:NERDComment(mode, type) range let forceNested = (a:type == 'Nested' || g:NERDDefaultNesting) - if a:type == 'Norm' || a:type == 'Nested' + if a:type == 'Comment' || a:type == 'Nested' if a:mode == "v" && visualmode() == "\" call s:CommentBlock(firstLine, lastLine, firstCol, lastCol, forceNested) elseif a:mode == "v" && visualmode() == "v" && (g:NERDCommentWholeLinesInVMode==0 || (g:NERDCommentWholeLinesInVMode==2 && s:HasMultipartDelims())) @@ -1118,7 +1118,7 @@ function! s:NERDComment(mode, type) range else normal! yy endif - execute firstLine .','. lastLine .'call s:NERDComment('. a:mode .', "Norm")' + execute firstLine .','. lastLine .'call s:NERDComment("'. a:mode .'", "Comment")' endif let &ignorecase = oldIgnoreCase @@ -2687,62 +2687,7 @@ function s:UntabbedCol(line, col) let lineTabsToSpaces = substitute(lineTruncated, '\t', s:TabSpace(), 'g') return strlen(lineTabsToSpaces) endfunction -" Section: Comment mapping setup {{{1 -" =========================================================================== - -" switch to/from alternative delimiters -nnoremap NERDCommenterAltDelims :call SwitchToAlternativeDelimiters(1) - -" comment out lines -nnoremap NERDCommenterComment :call NERDComment("n", "Norm") -vnoremap NERDCommenterComment :call NERDComment("v", "Norm") - -" toggle comments -nnoremap NERDCommenterToggle :call NERDComment("n", "Toggle") -vnoremap NERDCommenterToggle :call NERDComment("v", "Toggle") - -" minimal comments -nnoremap NERDCommenterMinimal :call NERDComment("n", "Minimal") -vnoremap NERDCommenterMinimal :call NERDComment("v", "Minimal") - -" sexy comments -nnoremap NERDCommenterSexy :call NERDComment("n", "Sexy") -vnoremap NERDCommenterSexy :call NERDComment("v", "Sexy") - -" invert comments -nnoremap NERDCommenterInvert :call NERDComment("n", "Invert") -vnoremap NERDCommenterInvert :call NERDComment("v", "Invert") - -" yank then comment -nmap NERDCommenterYank :call NERDComment("n", "Yank") -vmap NERDCommenterYank :call NERDComment("v", "Yank") - -" left aligned comments -nnoremap NERDCommenterAlignLeft :call NERDComment("n", "AlignLeft") -vnoremap NERDCommenterAlignLeft :call NERDComment("v", "AlignLeft") - -" left and right aligned comments -nnoremap NERDCommenterAlignBoth :call NERDComment("n", "AlignBoth") -vnoremap NERDCommenterAlignBoth :call NERDComment("v", "AlignBoth") - -" nested comments -nnoremap NERDCommenterNest :call NERDComment("n", "Nested") -vnoremap NERDCommenterNest :call NERDComment("v", "Nested") - -" uncomment -nnoremap NERDCommenterUncomment :call NERDComment("n", "Uncomment") -vnoremap NERDCommenterUncomment :call NERDComment("v", "Uncomment") - -" comment till the end of the line -nnoremap NERDCommenterToEOL :call NERDComment("n", "ToEOL") - -" append comments -nmap NERDCommenterAppend :call NERDComment("n", "Append") - -" insert comments -inoremap NERDCommenterInsert :call NERDComment("n", "Insert") - -" Section: Menu item setup {{{1 +" Section: Comment mapping and menu item setup {{{1 " =========================================================================== " Create menu items for the specified modes. If a:combo is not empty, then @@ -2757,6 +2702,7 @@ function! s:CreateMaps(modes, target, desc, combo) endif let command .= ' ' . a:target for mode in (a:modes == '') ? [''] : split(a:modes, '\zs') + exec mode . 'noremap ' . a:target . ' :call NERDComment("' . mode . '", "' . substitute(a:target, 'NERDCommenter', '', '') . '")' if g:NERDCreateDefaultMappings \ && strlen(a:combo) && !hasmapto(a:target, mode) exec mode . 'map ' . a:combo . ' ' . a:target @@ -2770,7 +2716,7 @@ endfunction call s:CreateMaps('nx', 'NERDCommenterComment', 'Comment', 'cc') call s:CreateMaps('nx', 'NERDCommenterToggle', 'Toggle', 'c') call s:CreateMaps('nx', 'NERDCommenterMinimal', 'Minimal', 'cm') -call s:CreateMaps('nx', 'NERDCommenterNest', 'Nested', 'cn') +call s:CreateMaps('nx', 'NERDCommenterNested', 'Nested', 'cn') call s:CreateMaps('n', 'NERDCommenterToEOL', 'To EOL', 'c$') call s:CreateMaps('nx', 'NERDCommenterInvert', 'Invert', 'ci') call s:CreateMaps('nx', 'NERDCommenterSexy', 'Sexy', 'cs') @@ -2785,4 +2731,7 @@ call s:CreateMaps('n', 'NERDCommenterAltDelims', 'Switch Delimiters', 'ca') call s:CreateMaps('i', 'NERDCommenterInsert', 'Insert Comment Here', '') call s:CreateMaps('', ':', '-Sep3-', '') call s:CreateMaps('', ':help NERDCommenterContents', 'Help', '') + +" switch to/from alternative delimiters (does not use wrapper function) +nnoremap NERDCommenterAltDelims :call SwitchToAlternativeDelimiters(1) " vim: set foldmethod=marker : From 785ad99c0b51f0a9307490f522c85cacb8269053 Mon Sep 17 00:00:00 2001 From: Benji Fisher Date: Wed, 14 Dec 2011 10:39:27 -0500 Subject: [PATCH 12/12] Various fixes, simplifications, improvements to s:NERDComment() and s:CreateMaps(). Updated docs. --- doc/NERD_commenter.txt | 4 +- plugin/NERD_commenter.vim | 80 ++++++++++++++++++++++----------------- 2 files changed, 47 insertions(+), 37 deletions(-) diff --git a/doc/NERD_commenter.txt b/doc/NERD_commenter.txt index f10c021..0170d2a 100644 --- a/doc/NERD_commenter.txt +++ b/doc/NERD_commenter.txt @@ -162,7 +162,7 @@ lines were selected in visual-line mode. 3.2.2 Nested comment map *NERDComNestedComment* Default mapping: [count]||cn -Mapped to: NERDCommenterNest +Mapped to: NERDCommenterNested Applicable modes: normal visual visual-line visual-block. Performs nested commenting. Works the same as ||cc except that if a line @@ -288,7 +288,7 @@ to insert mode between the new delimiters. 3.2.10 Insert comment map *NERDComInsertComment* Default mapping: disabled by default. -Map it to: NERDCommenterInInsert +Map it to: NERDCommenterInsert Applicable modes: insert. Adds comment delimiters at the current cursor position and inserts diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 3318011..efefbfe 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -3,7 +3,7 @@ " Description: vim global plugin that provides easy code commenting " Maintainer: Martin Grenfell " Version: 2.3.0 -" Last Change: Mon Dec 12 10:00 PM 2011 EST +" Last Change: Wed Dec 14 08:00 AM 2011 EST " License: This program is free software. It comes without any warranty, " to the extent permitted by applicable law. You can redistribute " it and/or modify it under the terms of the Do What The Fuck You @@ -34,7 +34,7 @@ let loaded_nerd_comments = 1 " 1 if the var is set, 0 otherwise function s:InitVariable(var, value) if !exists(a:var) - exec 'let ' . a:var . ' = ' . "'" . a:value . "'" + execute 'let ' . a:var . ' = ' . "'" . a:value . "'" return 1 endif return 0 @@ -1021,11 +1021,12 @@ endfunction " " Args: " -mode: a character indicating the mode in which the comment is requested: -" 'n' for Normal mode, 'v' for Visual mode +" 'n' for Normal mode, 'x' for Visual mode " -type: the type of commenting requested. Can be 'Sexy', 'Invert', " 'Minimal', 'Toggle', 'AlignLeft', 'AlignBoth', 'Comment', " 'Nested', 'ToEOL', 'Append', 'Insert', 'Uncomment', 'Yank' function! s:NERDComment(mode, type) range + let isVisual = a:mode =~ '[vsx]' " we want case sensitivity when commenting let oldIgnoreCase = &ignorecase set noignorecase @@ -1034,7 +1035,7 @@ function! s:NERDComment(mode, type) range call s:NerdEcho("filetype plugins should be enabled. See :help NERDComInstallation and :help :filetype-plugin-on", 0) endif - if a:mode == "v" + if isVisual let firstLine = line("'<") let lastLine = line("'>") let firstCol = col("'<") @@ -1044,14 +1045,14 @@ function! s:NERDComment(mode, type) range let lastLine = a:lastline endif - let countWasGiven = (a:mode != "v" && firstLine != lastLine) + let countWasGiven = (!isVisual && firstLine != lastLine) let forceNested = (a:type == 'Nested' || g:NERDDefaultNesting) if a:type == 'Comment' || a:type == 'Nested' - if a:mode == "v" && visualmode() == "\" + if isVisual && visualmode() == "\" call s:CommentBlock(firstLine, lastLine, firstCol, lastCol, forceNested) - elseif a:mode == "v" && visualmode() == "v" && (g:NERDCommentWholeLinesInVMode==0 || (g:NERDCommentWholeLinesInVMode==2 && s:HasMultipartDelims())) + elseif isVisual && visualmode() == "v" && (g:NERDCommentWholeLinesInVMode==0 || (g:NERDCommentWholeLinesInVMode==2 && s:HasMultipartDelims())) call s:CommentRegion(firstLine, firstCol, lastLine, lastCol, forceNested) else call s:CommentLines(forceNested, "none", firstLine, lastLine) @@ -1111,7 +1112,7 @@ function! s:NERDComment(mode, type) range call s:UncommentLines(firstLine, lastLine) elseif a:type == 'Yank' - if a:mode == "v" + if isVisual normal! gvy elseif countWasGiven execute firstLine .','. lastLine .'yank' @@ -2693,43 +2694,52 @@ endfunction " Create menu items for the specified modes. If a:combo is not empty, then " also define mappings and show a:combo in the menu items. function! s:CreateMaps(modes, target, desc, combo) + " Build up a map command like + " 'noremap NERDCommenterComment :call NERDComment("n", "Comment")' + let plug = 'NERDCommenter' . a:target + let plug_start = 'noremap ' . plug . ' :call NERDComment("' + let plug_end = '", "' . a:target . '")' + " Build up a menu command like + " 'menu comment.Comment\\cc NERDCommenterComment' let menuRoot = get(['', 'comment', '&comment', '&Plugin.&comment'], \ g:NERDMenuMode, '') - let leader = escape(exists('mapleader') ? mapleader : '\', '\') - let command = 'menu ' . menuRoot . '.' . escape(a:desc, ' ') + let menu_command = 'menu ' . menuRoot . '.' . escape(a:desc, ' ') if strlen(a:combo) - let command .= '' . leader . a:combo + let leader = exists('mapleader') ? mapleader : '\' + let menu_command .= '' . escape(leader, '\') . a:combo endif - let command .= ' ' . a:target + let menu_command .= ' ' . (strlen(a:combo) ? plug : a:target) + " Execute the commands built above for each requested mode. for mode in (a:modes == '') ? [''] : split(a:modes, '\zs') - exec mode . 'noremap ' . a:target . ' :call NERDComment("' . mode . '", "' . substitute(a:target, 'NERDCommenter', '', '') . '")' - if g:NERDCreateDefaultMappings - \ && strlen(a:combo) && !hasmapto(a:target, mode) - exec mode . 'map ' . a:combo . ' ' . a:target + if strlen(a:combo) + execute mode . plug_start . mode . plug_end + if g:NERDCreateDefaultMappings && !hasmapto(plug, mode) + execute mode . 'map ' . a:combo . ' ' . plug + endif endif - "check if the user wants the menu to be displayed + " Check if the user wants the menu to be displayed. if g:NERDMenuMode != 0 - exec mode . command + execute mode . menu_command endif endfor endfunction -call s:CreateMaps('nx', 'NERDCommenterComment', 'Comment', 'cc') -call s:CreateMaps('nx', 'NERDCommenterToggle', 'Toggle', 'c') -call s:CreateMaps('nx', 'NERDCommenterMinimal', 'Minimal', 'cm') -call s:CreateMaps('nx', 'NERDCommenterNested', 'Nested', 'cn') -call s:CreateMaps('n', 'NERDCommenterToEOL', 'To EOL', 'c$') -call s:CreateMaps('nx', 'NERDCommenterInvert', 'Invert', 'ci') -call s:CreateMaps('nx', 'NERDCommenterSexy', 'Sexy', 'cs') -call s:CreateMaps('nx', 'NERDCommenterYank', 'Yank then comment', 'cy') -call s:CreateMaps('n', 'NERDCommenterAppend', 'Append', 'cA') -call s:CreateMaps('', ':', '-Sep-', '') -call s:CreateMaps('nx', 'NERDCommenterAlignLeft', 'Left aligned', 'cl') -call s:CreateMaps('nx', 'NERDCommenterAlignBoth', 'Left and right aligned', 'cb') -call s:CreateMaps('', ':', '-Sep2-', '') -call s:CreateMaps('nx', 'NERDCommenterUncomment', 'Uncomment', 'cu') -call s:CreateMaps('n', 'NERDCommenterAltDelims', 'Switch Delimiters', 'ca') -call s:CreateMaps('i', 'NERDCommenterInsert', 'Insert Comment Here', '') -call s:CreateMaps('', ':', '-Sep3-', '') +call s:CreateMaps('nx', 'Comment', 'Comment', 'cc') +call s:CreateMaps('nx', 'Toggle', 'Toggle', 'c') +call s:CreateMaps('nx', 'Minimal', 'Minimal', 'cm') +call s:CreateMaps('nx', 'Nested', 'Nested', 'cn') +call s:CreateMaps('n', 'ToEOL', 'To EOL', 'c$') +call s:CreateMaps('nx', 'Invert', 'Invert', 'ci') +call s:CreateMaps('nx', 'Sexy', 'Sexy', 'cs') +call s:CreateMaps('nx', 'Yank', 'Yank then comment', 'cy') +call s:CreateMaps('n', 'Append', 'Append', 'cA') +call s:CreateMaps('', ':', '-Sep-', '') +call s:CreateMaps('nx', 'AlignLeft', 'Left aligned', 'cl') +call s:CreateMaps('nx', 'AlignBoth', 'Left and right aligned', 'cb') +call s:CreateMaps('', ':', '-Sep2-', '') +call s:CreateMaps('nx', 'Uncomment', 'Uncomment', 'cu') +call s:CreateMaps('n', 'AltDelims', 'Switch Delimiters', 'ca') +call s:CreateMaps('i', 'Insert', 'Insert Comment Here', '') +call s:CreateMaps('', ':', '-Sep3-', '') call s:CreateMaps('', ':help NERDCommenterContents', 'Help', '') " switch to/from alternative delimiters (does not use wrapper function)