From 7505221c76781689c72053a97b92035f26122c4a Mon Sep 17 00:00:00 2001 From: Max Bucknell Date: Mon, 8 Feb 2016 09:01:27 +0000 Subject: [PATCH] Edit pick (bad solution) --- vim/vim.symlink/plugin/pick.vim | 60 +++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 vim/vim.symlink/plugin/pick.vim diff --git a/vim/vim.symlink/plugin/pick.vim b/vim/vim.symlink/plugin/pick.vim new file mode 100644 index 0000000..a28472f --- /dev/null +++ b/vim/vim.symlink/plugin/pick.vim @@ -0,0 +1,60 @@ +if !exists("g:pick_executable") + let g:pick_executable = "pick" +endif + +function! PickCommand(choice_command, pick_args, vim_command) + try + let selection = system(a:choice_command . " | " . g:pick_executable . " " . a:pick_args) + redraw! + if v:shell_error == 0 + try + exec a:vim_command . " " . selection + catch /E325/ + endtry + endif + catch /Vim:Interrupt/ + " Swallow the ^C so that the redraw below happens; otherwise there will be + " leftovers from pick on the screen + redraw! + endtry +endfunction + +function! PickFile() + call PickCommand(s:FileListCommand(), "", ":edit") +endfunction + +function! PickFileVerticalSplit() + call PickCommand(s:FileListCommand(), "", ":vsplit") +endfunction + +function! PickFileSplit() + call PickCommand(s:FileListCommand(), "", ":split") +endfunction + +function! PickFileTab() + call PickCommand(s:FileListCommand(), "", ":tabedit") +endfunction + +function! PickBuffer() + call PickCommand(s:BufferListCommand(), "", ":buffer") +endfunction + +function! PickTag() + call PickCommand(s:TagCommand(), "", ":tag") +endfunction + +function! s:FileListCommand() + return "find * -type f -o -type l" +endfunction + +function! s:BufferListCommand() + let bufnrs = filter(range(1, bufnr("$")), 'buflisted(v:val)') + let buffers = map(bufnrs, 'bufname(v:val)') + return 'echo "' . join(buffers, "\n") . '"' +endfunction + +function! s:TagCommand() + let l:tag_files = join(split(&tags, ","), " ") + + return "cat " . l:tag_files . " 2> /dev/null | awk -F$'\t' '{print $1}' | sort -u | grep -v '^!'" +endfunction