From: Nicolas Boisselier Date: Tue, 5 Dec 2017 04:46:10 +0000 (+0000) Subject: etc/vim/source/functions.vim X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=2ff1151f8781c1a176c12f903c2aa6c77413edc1;p=nb.git etc/vim/source/functions.vim --- diff --git a/etc/vim/source/functions.vim b/etc/vim/source/functions.vim index 3965efdd..e6990922 100644 --- a/etc/vim/source/functions.vim +++ b/etc/vim/source/functions.vim @@ -291,131 +291,3 @@ func! VS(...) " return system(Cmd) return Cmd endfunc - -func! VimShortcurtsAuto(...) - let Cmd = g:Cmd - let FilePath = expand('%:p') - " return a:1.match(a:1,"_comment_line_toggle") - " f (match(a:1,"_comment_line_toggle")) - if (a:1 == "Wcomment_line_toggle") - " return Cmd - let Cmd = 'cat|' . Cmd - endif - - setlocal paste - - " return (g:Cmd .' auto_' . a:1 . ' ' . FilePath) - return system(g:Cmd .' auto_' . a:1 . ' ' . FilePath) - -endfunc - -func! VimShortcurtsList() -" NB 09.11.11 call input('Entry: ') - let list = system(g:Cmd .' all_choose') - let i = input(list . 'Please choose a number function: ') - - let fct = substitute(list, '^.*\s' . i . '\. \(\w\+\).*$', '\1', '') - return fct - - let items = split(list,"\n\t") - return items - let opt = inputlist(items) -" NB 09.11.11 call setline(lnum, '" zaza ' . getline(lnum)) - " echo items[opt] - " g:nicoInput = items[opt] - return items[opt] -endfunc - - -" Trim -function! StrTrim (string) - let string=a:string - let string = substitute(string, '[\s\t\r\n]\+$', '', '') - return string -endfunction -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" Other function copy from examples -"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -function! CountSpaces(type, ...) - - let sel_save = &selection - let &selection = "inclusive" - let reg_save = @@ - - if a:0 " Invoked from Visual mode, use '< and '> marks. - silent exe "normal! `<" . a:type . "`>y" - - elseif a:type == 'line' - silent exe "normal! '[V']y" - - elseif a:type == 'block' - silent exe "normal! `[\`]y" - - else - silent exe "normal! `[v`]y" - - endif - - echomsg strlen(substitute(@@, '[^ ]', '', 'g')) - - let &selection = sel_save - let @@ = reg_save -endfunction - -" You can call this function with: :10,30call Count_words() -func! Count_words() range - let lnum = a:firstline - let n = 0 - while lnum <= a:lastline - let n = n + len(split(getline(lnum))) - let lnum = lnum + 1 - endwhile - echo lnum - return "found " . n . " words" -endfunction - -" Capitalize the first letter of each word -func! Capitalize() range - for line_number in range(a:firstline, a:lastline) - let line_content = getline(line_number) - let line_content = substitute(line_content, "\\w\\+", "\\u\\0", "g") - call setline(line_number, line_content) - endfor -endfunction - -" Escape special characters in a string for exact matching. -" This is useful to copying strings from the file to the search tool -" Based on this - http://peterodding.com/code/vim/profile/autoload/xolox/escape.vim -function! EscapeString (string) - let string=a:string - " Escape regex characters - let string = escape(string, '^$.*\/~[]') - " Escape the line endings - let string = substitute(string, '\n', '\\n', 'g') - return string -endfunction - -" Get the current visual block for search and replaces -" This function passed the visual block through a string escape function -" Based on this - http://stackoverflow.com/questions/676600/vim-replace-selected-text/677918#677918 -function! GetVisual() range - " Save the current register and clipboard - let reg_save = getreg('"') - let regtype_save = getregtype('"') - let cb_save = &clipboard - set clipboard& - - " Put the current visual selection in the " register - normal! ""gvy - let selection = getreg('"') - - " Put the saved registers and clipboards back - call setreg('"', reg_save, regtype_save) - let &clipboard = cb_save - - "Escape any special characters in the selection - let escaped_selection = EscapeString(selection) - - return escaped_selection -endfunction -