var cms_l = split(escape(cms, '*.'), '\s*%s\s*')
var first_col = indent(lnum1)
- var start_col = getpos("'[")[2]
+ var start_col = getpos("'[")[2] - 1
if len(cms_l) == 1 && lnum1 == lnum2 && first_col < start_col
- var line_start = getline(lnum1)[0 : max([0, start_col - 2])]
- var line_end = getline(lnum1)[start_col - 1 : -1]
- line_end = line_end =~# $'^\s*{cms_l[0]}' ?
- \ substitute(line_end, $'^\s*\zs{cms_l[0]}', '', '') :
- \ printf(substitute(cms, '%s\@!', '%%', 'g'), line_end)
+ var line_start = getline(lnum1)[0 : start_col - 1]
+ var line_end = getline(lnum1)[start_col : -1]
+ line_end = line_end =~ $'^\s*{cms_l[0]}' ?
+ \ substitute(line_end, $'^\s*\zs{cms_l[0]}\s\ze\s*', line_end =~ '^\s' ? ' ' : '', '') :
+ \ printf(substitute(cms, '%s\@!', '%%', ''), line_end)
setline(lnum1, line_start .. line_end)
return ''
endif
-*comment.txt* For Vim version 9.1. Last change: 2024 Sep 30
+*comment.txt* For Vim version 9.1. Last change: 2024 Oct 01
VIM REFERENCE MANUAL
a comment marker, the line will be un-commented, if it doesn't, the line will
be commented out. Blank and empty lines are ignored.
+The value of 'commentstring' is the same for the entire buffer and determined
+by its filetype (|filetypes|). To adapt it within the buffer for embedded
+languages, you can use a plug-in such as
+https://github.com/suy/vim-context-commentstring.
+
The comment marker will always be padded with blanks whether or not the
'commentstring' value contains whitespace around "%s".