Skip to content

Commit 199087a

Browse files
committed
Add a string that marks inserted comments
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();
1 parent be79030 commit 199087a

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

doc/commentary.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ gcu
2626
*:Commentary*
2727
:[range]Commentary Comment or uncomment [range] lines
2828

29+
30+
*g:commentary_marker*
31+
g:commentary_marker A string that marks comments inserted by commentary.
32+
This marker is inserted immediately after the comment
33+
string. Useful if commentary is only used to disable
34+
code (rather than inserting explanatory comments).
35+
36+
For example, >
37+
let g:commentary_marker = '~'
38+
< will comment >
39+
f();
40+
< into >
41+
//~ f();
42+
<
43+
2944
The |User| CommentaryPost autocommand fires after a successful operation and
3045
can be used for advanced customization.
3146

plugin/commentary.vim

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ if exists("g:loaded_commentary") || &cp || v:version < 700
88
endif
99
let g:loaded_commentary = 1
1010

11+
if !exists("g:commentary_marker")
12+
let g:commentary_marker = ''
13+
endif
14+
1115
function! s:surroundings() abort
16+
" Ensure whitespace around %s and postfix comment leader with ~ to make auto
17+
" commented code easier to find.
1218
return split(get(b:, 'commentary_format', substitute(substitute(
13-
\ &commentstring, '\S\zs%s',' %s','') ,'%s\ze\S', '%s ', '')), '%s', 1)
19+
\ &commentstring, '\S\zs%s', g:commentary_marker.' %s','') ,'%s\ze\S', '%s ', '')), '%s', 1)
1420
endfunction
1521

1622
function! s:strip_white_space(l,r,line) abort

0 commit comments

Comments
 (0)