Skip to content

Commit 5348669

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(); Support a b: version because some filetypes (like dosbatch or python's black) require whitespace after their commentstring.
1 parent 71c3322 commit 5348669

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

doc/commentary.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ gcu
2929
*:Commentary*
3030
:[range]Commentary Comment or uncomment [range] lines
3131

32+
33+
*g:commentary_marker*
34+
g:commentary_marker A string that marks comments inserted by commentary.
35+
This marker is inserted immediately after the comment
36+
string. Useful if commentary is only used to disable
37+
code (rather than inserting explanatory comments).
38+
39+
For example, >
40+
let g:commentary_marker = '~'
41+
< will comment >
42+
f();
43+
< into >
44+
//~ f();
45+
<
46+
Use |b:commentary_marker| for a buffer-local override.
47+
3248
The |User| CommentaryPost autocommand fires after a successful operation and
3349
can be used for advanced customization.
3450

plugin/commentary.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@ if exists("g:loaded_commentary") || v:version < 703
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
1216
" Get commentstring with %s and whitespace padding.
1317
let cms = substitute(substitute(substitute(
1418
\ &commentstring, '^$', '%s', ''), '\S\zs%s',' %s', '') ,'%s\ze\S', '%s ', '')
19+
" Postfix comment leader with marker to make auto commented code easier to find.
20+
let marker = get(b:, 'commentary_marker', g:commentary_marker)
21+
let cms = substitute(cms, '\S\zs\s*%s', marker ..'&','')
1522
let fmt = get(b:, 'commentary_format', cms)
1623
return split(fmt, '%s', 1)
1724
endfunction

0 commit comments

Comments
 (0)