From 5a7410af869c92e91a690996cec02c07bd8a1780 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 24 Jun 2025 08:46:23 +0100 Subject: [PATCH] etc/vim/source/map.vim --- etc/vim/source/map.vim | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/etc/vim/source/map.vim b/etc/vim/source/map.vim index 6400264b..77e8540e 100644 --- a/etc/vim/source/map.vim +++ b/etc/vim/source/map.vim @@ -43,16 +43,21 @@ func!MapHelp() endfunc function! InsertMultiline(multiline_text) abort - " Split the input at newlines, handling both Unix (\n) and Windows (\r\n) formats - let lines = split(a:multiline_text, '\r\n\|\n') - - " Replace current line with first line - call setline('.', lines[0]) - - " Append remaining lines if they exist - if len(lines) > 1 - call append('.', lines[1:]) - endif + + " Split the input at newlines, handling both Unix (\n) and Windows (\r\n) formats + let lines = split(a:multiline_text, '\r\n\|\n') + " Handle empty input gracefully + if empty(lines) + let lines = [''] + endif + + " Replace current line with first line + call setline('.', lines[0]) + + " Append remaining lines if they exist + if len(lines) > 1 + call append('.', lines[1:]) + endif endfunction func! CommentMeNow() @@ -98,7 +103,6 @@ func! CommentToggle() " NB 12.12.22: Toggle current line between commented / not commented if ( g:mimeComment->get(FileType()) == '0') let comment = '#' - " NB 12.12.22 return Err('No comment defined for filetype '.FileType()) else let comment = g:mimeComment->get(FileType()) endif @@ -122,8 +126,6 @@ func! CommentToggle() " " Add comment " - " NB 11.12.22 let v = '' - " NB 11.12.22 let v = '' " Beginning of line let new_line = substitute(curr_line,'^\([\t ]*\)','\1'.comment[0].' '.CommentMeNow().' ','') " End of line @@ -133,6 +135,11 @@ func! CommentToggle() "let new_line = substitute(new_line,'\n',"\n",'g') endif + " NB 24.06.25 if (empty(new_line)) + " NB 24.06.25 let new_line = '' + " NB 24.06.25 endif + + "echo new_line call InsertMultiline(new_line) " NB 09.06.25 call setline('.',new_line) endfunc -- 2.47.3