From: Nicolas Boisselier Date: Tue, 21 Mar 2023 00:01:18 +0000 (+0100) Subject: Add global MapHelp X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=c8b2100c5b290714dc0fb63b6245c09954989ebb;p=nb.git Add global MapHelp --- diff --git a/etc/vim/source/comment.vim b/etc/vim/source/comment.vim deleted file mode 100644 index 4b1cd942..00000000 --- a/etc/vim/source/comment.vim +++ /dev/null @@ -1,95 +0,0 @@ -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" -" Functions -" NB 12.12.22: Functions to comment texts -" -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -if exists("_loaded_comment") - finish -endif -let _loaded_comment = 1 - - -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" Global -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -let $USER_INITIALS = system('printf "%s" ${USER_INITIALS:-`whoami`}') -func! CommentMeNow() - return $USER_INITIALS . ' ' . strftime('%d.%m.%y') -endfunc - -func! CommentSubSpecialChar(text) -" NB 12.12.22: Substitute specials char like \n in an array - let i = 0 - let val = '' - for val in a:text - let a:text[i] = substitute(val,'\\n',"\n",'') - let i += 1 - endfor -endfunc - -func! CommentNewLine() -" NB 12.12.22: Create a new line of comment - 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 - let comment = split(comment,'\s\+') - call CommentSubSpecialChar(comment) - - " Beginning of line - let new_line = comment[0].' '.CommentMeNow().': foo ' - - " End of line - if ( len(comment)>1 ) - let new_line = new_line . comment[1] - endif - - exec "normal! o".new_line."\?foo\cw " - exec "startinsert" - " exec "cw" -endfunc - -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 - - let comment = split(comment,'\s\+') - " call CommentSubSpecialChar(comment) - - let curr_line = getline('.') - " - " Wipe out existing comment - " - " Beginning of line - let new_line = substitute(curr_line,'^\([\t ]*\)'.comment[0].' [^ ]\+ \d\d\.\d\d\.\d\d:\? ','\1','') - " End of line - if ( len(comment)>1 ) - let new_line = substitute(new_line,'\s*'.comment[1].'\s*$','','') - endif - - if new_line == curr_line - " - " 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 - if ( len(comment)>1 ) - let new_line = substitute(new_line,'\s*$',' '.comment[1],'') - endif - " let new_line = substitute(new_line,'\\n',"\n",'') - endif - - call setline('.',new_line) -endfunc - diff --git a/etc/vim/source/map.vim b/etc/vim/source/map.vim index 3ede5843..edc86842 100644 --- a/etc/vim/source/map.vim +++ b/etc/vim/source/map.vim @@ -8,6 +8,104 @@ " See: http://vimdoc.sourceforge.net/htmldoc/insert.html " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +let MapHelp = [] +func!MapHelp() + let i=0 + let line=['',''] + let fcount='' + for line in g:MapHelp + if len(line[0]) > fcount + let fcount = len(line[0]) + endif + " echo len(line[0]) + endfor + " echo fcount + + let fmt=" %-" . fcount . "s : %s" + echo "Help:\n" + for line in g:MapHelp + echo printf(fmt,line[0],line[1]) + endfor +endfunc + +func! CommentMeNow() + return $USER_INITIALS . ' ' . strftime('%d.%m.%y') +endfunc + +func! CommentSubSpecialChar(text) +" NB 12.12.22: Substitute specials char like \n in an array + let i = 0 + let val = '' + for val in a:text + let a:text[i] = substitute(val,'\\n',"\n",'') + let i += 1 + endfor +endfunc + +func! CommentNewLine() +" NB 12.12.22: Create a new line of comment + 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 + let comment = split(comment,'\s\+') + call CommentSubSpecialChar(comment) + + " Beginning of line + let new_line = comment[0].' '.CommentMeNow().': foo ' + + " End of line + if ( len(comment)>1 ) + let new_line = new_line . comment[1] + endif + + exec "normal! o".new_line."\?foo\cw " + exec "startinsert" + " exec "cw" +endfunc + +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 + + let comment = split(comment,'\s\+') + " call CommentSubSpecialChar(comment) + + let curr_line = getline('.') + " + " Wipe out existing comment + " + " Beginning of line + let new_line = substitute(curr_line,'^\([\t ]*\)'.comment[0].' [^ ]\+ \d\d\.\d\d\.\d\d:\? ','\1','') + " End of line + if ( len(comment)>1 ) + let new_line = substitute(new_line,'\s*'.comment[1].'\s*$','','') + endif + + if new_line == curr_line + " + " 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 + if ( len(comment)>1 ) + let new_line = substitute(new_line,'\s*$',' '.comment[1],'') + endif + " let new_line = substitute(new_line,'\\n',"\n",'') + endif + + call setline('.',new_line) +endfunc """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " @@ -20,14 +118,17 @@ map :bp """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " F1 - Last Cmd +call add(MapHelp,['F1, Alt+x','Last shell command executed']) map :! map x :! """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " F2 - Script, formated text verification +call add(MapHelp,['F2','Check syntaxe']) map :call FileCheckSyntaxe() """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " F5 - Comment +call add(MapHelp,['F5','Add / Delete comment']) map :call CommentNewLine() vmap :call CommentToggle() diff --git a/etc/vim/source/option.vim b/etc/vim/source/option.vim index 5cf9dce1..c5c4ebc5 100644 --- a/etc/vim/source/option.vim +++ b/etc/vim/source/option.vim @@ -8,6 +8,8 @@ " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +let $USER_INITIALS = system('printf "%s" ${USER_INITIALS:-`whoami`}') + """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Syntax highlighting only for enhanced-vi """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""