vim: Add autohl and array converter plugins

This commit is contained in:
Mathieu Maret 2018-02-08 15:48:18 +01:00
parent 84b4b258a0
commit 60269d647d
2 changed files with 44 additions and 0 deletions

22
.vim/plugin/autohl.vim Normal file
View File

@ -0,0 +1,22 @@
" Highlight all instances of word under cursor, when idle.
" Useful when studying strange source code.
" Type z/ to toggle highlighting on/off.
nnoremap z/ :if AutoHighlightToggle()<Bar>set hls<Bar>endif<CR>
function! AutoHighlightToggle()
let @/ = ''
if exists('#auto_highlight')
au! auto_highlight
augroup! auto_highlight
setl updatetime=4000
echo 'Highlight current word: off'
return 0
else
augroup auto_highlight
au!
au CursorHold * let @/ = '\V\<'.escape(expand('<cword>'), '\').'\>'
augroup end
setl updatetime=500
echo 'Highlight current word: ON'
return 1
endif
endfunction

22
.vim/plugin/convert.vim Normal file
View File

@ -0,0 +1,22 @@
" convert rows of numbers or text (as if pasted from excel column) to a tuple
function! ToTupleFunction() range
silent execute a:firstline . "," . a:lastline . "s/^/'/"
silent execute a:firstline . "," . a:lastline . "s/$/',/"
silent execute a:firstline . "," . a:lastline . "join"
silent execute "normal I("
silent execute "normal $xa)"
silent execute "normal ggVGYY"
endfunction
command! -range ToTuple <line1>,<line2> call ToTupleFunction()
" convert rows of numbers or text (as if pasted from excel column) to an array
function! ToArrayFunction() range
silent execute a:firstline . "," . a:lastline . "s/^/'/"
silent execute a:firstline . "," . a:lastline . "s/$/',/"
silent execute a:firstline . "," . a:lastline . "join"
silent execute "normal I["
silent execute "normal $xa]"
endfunction
command! -range ToArray <line1>,<line2> call ToArrayFunction()