From 8e1355e6c49d27c3cc225b006d37fe095bfeb895 Mon Sep 17 00:00:00 2001 From: mirsella Date: Fri, 24 Jul 2020 11:49:41 +0200 Subject: [PATCH 1/2] added option to replace nerdcommenter leader key with the option g:NERDLeaderKey you can set a custom nerdcommenter leader key, to replace the default one which is 'c'. we can set in vimrc : `let g:NERDLeaderKey = 'v'` to use 'v' instead of 'c'. now we can use `vc` to comment and `vu` to uncomment. all default keybinding work as far as i tested --- plugin/NERD_commenter.vim | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/plugin/NERD_commenter.vim b/plugin/NERD_commenter.vim index 5d32d38f..eabd8444 100644 --- a/plugin/NERD_commenter.vim +++ b/plugin/NERD_commenter.vim @@ -3168,21 +3168,27 @@ function! s:CreateMaps(modes, target, desc, combo) endif endfor endfunction -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') + +" check if custom NERDLeaderKey is used, and set it to 'c' if not set +if !exists('g:NERDLeaderKey') || type('g:NERDLeaderKey') != 1 + let g:NERDLeaderKey = 'c' +endif + +call s:CreateMaps('nx', 'Comment', 'Comment', g:NERDLeaderKey . 'c') +call s:CreateMaps('nx', 'Toggle', 'Toggle', g:NERDLeaderKey . '') +call s:CreateMaps('nx', 'Minimal', 'Minimal', g:NERDLeaderKey . 'm') +call s:CreateMaps('nx', 'Nested', 'Nested', g:NERDLeaderKey . 'n') +call s:CreateMaps('n', 'ToEOL', 'To EOL', g:NERDLeaderKey . '$') +call s:CreateMaps('nx', 'Invert', 'Invert', g:NERDLeaderKey . 'i') +call s:CreateMaps('nx', 'Sexy', 'Sexy', g:NERDLeaderKey . 's') +call s:CreateMaps('nx', 'Yank', 'Yank then comment', g:NERDLeaderKey . 'y') +call s:CreateMaps('n', 'Append', 'Append', g:NERDLeaderKey . 'A') 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('nx', 'AlignLeft', 'Left aligned', g:NERDLeaderKey . 'l') +call s:CreateMaps('nx', 'AlignBoth', 'Left and right aligned', g:NERDLeaderKey . 'b') call s:CreateMaps('', ':', '-Sep2-', '') -call s:CreateMaps('nx', 'Uncomment', 'Uncomment', 'cu') -call s:CreateMaps('n', 'AltDelims', 'Switch Delimiters', 'ca') +call s:CreateMaps('nx', 'Uncomment', 'Uncomment', g:NERDLeaderKey . 'u') +call s:CreateMaps('n', 'AltDelims', 'Switch Delimiters', g:NERDLeaderKey . 'a') call s:CreateMaps('i', 'Insert', 'Insert Comment Here', '') call s:CreateMaps('', ':', '-Sep3-', '') call s:CreateMaps('', ':help NERDCommenterContents', 'Help', '') From bd712e9444107e3f795e009481a6cbcd418c2ee3 Mon Sep 17 00:00:00 2001 From: mirsella Date: Fri, 24 Jul 2020 11:57:22 +0200 Subject: [PATCH 2/2] update README.md updated readme to see show the g:NERDLeaderKey options --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 59962867..901260a6 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,9 @@ Please see the vim help system for full documentation of all options: `:help ner Several settings can be added to your vimrc to change the default behavior. Some examples: ```vim +" Change nerdcommenter leader key. default is 'c' +let g:NERDLeaderKey = 'v' " v is for the example, you can set anything + " Add spaces after comment delimiters by default let g:NERDSpaceDelims = 1