From cc5e49a9a9d81e8f22356b8f23ae118aa126bebf Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Sat, 24 Nov 2018 01:00:02 +0530 Subject: Fix #133: Add nnn-picker.vim plugin --- scripts/vim-plugin/nnn-picker.vim | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 scripts/vim-plugin/nnn-picker.vim (limited to 'scripts') diff --git a/scripts/vim-plugin/nnn-picker.vim b/scripts/vim-plugin/nnn-picker.vim new file mode 100644 index 0000000..3390db0 --- /dev/null +++ b/scripts/vim-plugin/nnn-picker.vim @@ -0,0 +1,45 @@ +" vim plugin to use nnn as a file picker +" Closely follows and inspired by the vim_file_chooser plugin for ranger. +" +" Author: Arun Prakash Jana +" Email: engineerarun@gmail.com +" Homepage: https://github.com/jarun/nnn +" Copyright © 2018 Arun Prakash Jana +" +" Usage: +" Copy this file to the vim plugin directory. +" To open nnn as a file picker in vim, use the command ":NnnPicker" or ":Np" +" or the key-binding "n". Once you select one or more files and quit +" nnn, vim will open the first selected file and add the remaining files to +" the arg list/buffer list. +" If no file is explicitly selected, the last selected entry is picked. + +function! NnnPicker() + let temp = tempname() + if has("gui_running") + exec 'silent !xterm -e nnn -p ' . shellescape(temp) + else + exec 'silent !nnn -p ' . shellescape(temp) + endif + if !filereadable(temp) + redraw! + " Nothing to read. + return + endif + let names = readfile(temp) + if empty(names) + redraw! + " Nothing to open. + return + endif + " Edit the first item. + exec 'edit ' . fnameescape(names[0]) + " Add any remaining items to the arg list/buffer list. + for name in names[1:] + exec 'argadd ' . fnameescape(name) + endfor + redraw! +endfunction +command! -bar NnnPicker call NnnPicker() +nnoremap n :NnnPicker +command! -nargs=* -complete=file Np :call NnnPicker() -- cgit v1.2.3-70-g09d2