From 3ce1eea2c1102e3f269bd9ef30473dad04d11d7b Mon Sep 17 00:00:00 2001 From: acelya Date: Mon, 23 Nov 2020 19:03:58 +0100 Subject: [PATCH] Add a string that marks inserted comments (#87) --- doc/commentary.txt | 13 +++++++++++++ plugin/commentary.vim | 8 +++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/doc/commentary.txt b/doc/commentary.txt index 01f73da..b53eca7 100644 --- a/doc/commentary.txt +++ b/doc/commentary.txt @@ -29,6 +29,19 @@ gcu *:Commentary* :[range]Commentary Comment or uncomment [range] lines + *g:commentary_marker* +g:commentary_marker A string that marks comments inserted by commentary. + This marker is inserted immediately after the comment + string. Useful if commentary is only used to disable + code (rather than inserting explanatory comments). + + For example, > + let g:commentary_marker = '~' +< will comment > + f(); +< into > + //~ f(); + The |User| CommentaryPost autocommand fires after a successful operation and can be used for advanced customization. diff --git a/plugin/commentary.vim b/plugin/commentary.vim index 2e48e68..304fbb9 100644 --- a/plugin/commentary.vim +++ b/plugin/commentary.vim @@ -8,9 +8,15 @@ if exists("g:loaded_commentary") || v:version < 700 endif let g:loaded_commentary = 1 +if !exists("g:commentary_marker") + let g:commentary_marker = '' +endif + function! commentary#surroundings() abort + " Ensure whitespace around %s and postfix comment leader with ~ to make auto + " commented code easier to find. return split(get(b:, 'commentary_format', substitute(substitute(substitute( - \ &commentstring, '^$', '%s', ''), '\S\zs%s',' %s', '') ,'%s\ze\S', '%s ', '')), '%s', 1) + \ &commentstring, '^$', '%s', ''), '\S\zs%s', g:commentary_marker.' %s', '') ,'%s\ze\S', '%s ', '')), '%s', 1) endfunction function! s:strip_white_space(l,r,line) abort