My build of nnn with minor changes
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

67 lines
1.8 KiB

  1. " vim/neovim 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/neovim plugin directory.
  11. " To open nnn as a file picker in vim/neovim, use the command ":NnnPicker" or
  12. " ":Np" or the key-binding "<leader>n". Once you select one or more files and
  13. " quit nnn, vim/neovim will open the first selected file and add the remaining
  14. " files to the arg list/buffer list. If no file is explicitly selected, the
  15. " last selected entry is picked.
  16. let s:temp = ""
  17. fun! s:T_OnExit(job_id, code, event) dict
  18. if a:code == 0
  19. bd!
  20. call s:evaluate_temp()
  21. endif
  22. endfun
  23. fun! s:evaluate_temp()
  24. if !filereadable(s:temp)
  25. echoerr 'Temp file ' . s:temp . 'not readable!'
  26. redraw!
  27. " Nothing to read.
  28. return
  29. endif
  30. let names = readfile(s:temp)
  31. if empty(names)
  32. redraw!
  33. " Nothing to open.
  34. return
  35. endif
  36. " Edit the first item.
  37. exec 'edit ' . fnameescape(names[0])
  38. " Add any remaining items to the arg list/buffer list.
  39. for name in names[1:]
  40. exec 'argadd ' . fnameescape(name)
  41. endfor
  42. redraw!
  43. endfun
  44. function! NnnPicker()
  45. let s:temp = tempname()
  46. let l:cmd = 'nnn -p ' . shellescape(s:temp)
  47. if has("nvim")
  48. enew
  49. call termopen(l:cmd, {'on_exit': function('s:T_OnExit')}) | startinsert
  50. elseif has("gui_running")
  51. exec 'silent !xterm -e ' . l:cmd
  52. call s:evaluate_temp()
  53. else
  54. exec 'silent !' . l:cmd
  55. call s:evaluate_temp()
  56. endif
  57. endfunction
  58. command! -bar NnnPicker call NnnPicker()
  59. nnoremap <leader>n :<C-U>NnnPicker<CR>
  60. command! -nargs=* -complete=file Np :call NnnPicker()