My build of nnn with minor changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nnn-picker.vim 1.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. " vim plugin to use nnn as a file picker
  2. " Closely follows and inspired by the vim_file_chooser plugin for ranger.
  3. "
  4. " Author: Arun Prakash Jana
  5. " Email: engineerarun@gmail.com
  6. " Homepage: https://github.com/jarun/nnn
  7. " Copyright © 2018 Arun Prakash Jana
  8. "
  9. " Usage:
  10. " Copy this file to the vim plugin directory.
  11. " To open nnn as a file picker in vim, use the command ":NnnPicker" or ":Np"
  12. " or the key-binding "<leader>n". Once you select one or more files and quit
  13. " nnn, vim will open the first selected file and add the remaining files to
  14. " the arg list/buffer list.
  15. " If no file is explicitly selected, the last selected entry is picked.
  16. function! NnnPicker()
  17. let temp = tempname()
  18. if has("gui_running")
  19. exec 'silent !xterm -e nnn -p ' . shellescape(temp)
  20. else
  21. exec 'silent !nnn -p ' . shellescape(temp)
  22. endif
  23. if !filereadable(temp)
  24. redraw!
  25. " Nothing to read.
  26. return
  27. endif
  28. let names = readfile(temp)
  29. if empty(names)
  30. redraw!
  31. " Nothing to open.
  32. return
  33. endif
  34. " Edit the first item.
  35. exec 'edit ' . fnameescape(names[0])
  36. " Add any remaining items to the arg list/buffer list.
  37. for name in names[1:]
  38. exec 'argadd ' . fnameescape(name)
  39. endfor
  40. redraw!
  41. endfunction
  42. command! -bar NnnPicker call NnnPicker()
  43. nnoremap <leader>n :<C-U>NnnPicker<CR>
  44. command! -nargs=* -complete=file Np :call NnnPicker()