From 60269d647d663c5fc5d59bd1605397b701741993 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Thu, 8 Feb 2018 15:48:18 +0100 Subject: [PATCH] vim: Add autohl and array converter plugins --- .vim/plugin/autohl.vim | 22 ++++++++++++++++++++++ .vim/plugin/convert.vim | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 .vim/plugin/autohl.vim create mode 100644 .vim/plugin/convert.vim diff --git a/.vim/plugin/autohl.vim b/.vim/plugin/autohl.vim new file mode 100644 index 0000000..eeb9d71 --- /dev/null +++ b/.vim/plugin/autohl.vim @@ -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()set hlsendif +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(''), '\').'\>' + augroup end + setl updatetime=500 + echo 'Highlight current word: ON' + return 1 + endif +endfunction diff --git a/.vim/plugin/convert.vim b/.vim/plugin/convert.vim new file mode 100644 index 0000000..d30ebf6 --- /dev/null +++ b/.vim/plugin/convert.vim @@ -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 , 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 , call ToArrayFunction() + +