mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
commit
78614f9fbf
|
@ -1,4 +1,4 @@
|
||||||
" vim plugin to use nnn as a file picker
|
" vim/neovim plugin to use nnn as a file picker
|
||||||
" Closely follows and inspired by the vim_file_chooser plugin for ranger.
|
" Closely follows and inspired by the vim_file_chooser plugin for ranger.
|
||||||
"
|
"
|
||||||
" Author: Arun Prakash Jana
|
" Author: Arun Prakash Jana
|
||||||
|
@ -7,26 +7,30 @@
|
||||||
" Copyright © 2018 Arun Prakash Jana
|
" Copyright © 2018 Arun Prakash Jana
|
||||||
"
|
"
|
||||||
" Usage:
|
" Usage:
|
||||||
" Copy this file to the vim plugin directory.
|
" Copy this file to the vim/neovim plugin directory.
|
||||||
" To open nnn as a file picker in vim, use the command ":NnnPicker" or ":Np"
|
" To open nnn as a file picker in vim/neovim, use the command ":NnnPicker" or
|
||||||
" or the key-binding "<leader>n". Once you select one or more files and quit
|
" ":Np" or the key-binding "<leader>n". Once you select one or more files and
|
||||||
" nnn, vim will open the first selected file and add the remaining files to
|
" quit nnn, vim/neovim will open the first selected file and add the remaining
|
||||||
" the arg list/buffer list.
|
" files to the arg list/buffer list. If no file is explicitly selected, the
|
||||||
" If no file is explicitly selected, the last selected entry is picked.
|
" last selected entry is picked.
|
||||||
|
|
||||||
function! NnnPicker()
|
let s:temp = ""
|
||||||
let temp = tempname()
|
|
||||||
if has("gui_running")
|
fun! s:T_OnExit(job_id, code, event) dict
|
||||||
exec 'silent !xterm -e nnn -p ' . shellescape(temp)
|
if a:code == 0
|
||||||
else
|
bd!
|
||||||
exec 'silent !nnn -p ' . shellescape(temp)
|
call s:evaluate_temp()
|
||||||
endif
|
endif
|
||||||
if !filereadable(temp)
|
endfun
|
||||||
|
|
||||||
|
fun! s:evaluate_temp()
|
||||||
|
if !filereadable(s:temp)
|
||||||
|
echoerr 'Temp file ' . s:temp . 'not readable!'
|
||||||
redraw!
|
redraw!
|
||||||
" Nothing to read.
|
" Nothing to read.
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
let names = readfile(temp)
|
let names = readfile(s:temp)
|
||||||
if empty(names)
|
if empty(names)
|
||||||
redraw!
|
redraw!
|
||||||
" Nothing to open.
|
" Nothing to open.
|
||||||
|
@ -39,7 +43,24 @@ function! NnnPicker()
|
||||||
exec 'argadd ' . fnameescape(name)
|
exec 'argadd ' . fnameescape(name)
|
||||||
endfor
|
endfor
|
||||||
redraw!
|
redraw!
|
||||||
|
endfun
|
||||||
|
|
||||||
|
function! NnnPicker()
|
||||||
|
let s:temp = tempname()
|
||||||
|
let l:cmd = 'nnn -p ' . shellescape(s:temp)
|
||||||
|
|
||||||
|
if has("nvim")
|
||||||
|
enew
|
||||||
|
call termopen(l:cmd, {'on_exit': function('s:T_OnExit')}) | startinsert
|
||||||
|
elseif has("gui_running")
|
||||||
|
exec 'silent !xterm -e ' . l:cmd
|
||||||
|
call s:evaluate_temp()
|
||||||
|
else
|
||||||
|
exec 'silent !' . l:cmd
|
||||||
|
call s:evaluate_temp()
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
command! -bar NnnPicker call NnnPicker()
|
command! -bar NnnPicker call NnnPicker()
|
||||||
nnoremap <leader>n :<C-U>NnnPicker<CR>
|
nnoremap <leader>n :<C-U>NnnPicker<CR>
|
||||||
command! -nargs=* -complete=file Np :call NnnPicker()
|
command! -nargs=* -complete=file Np :call NnnPicker()
|
||||||
|
|
Loading…
Reference in a new issue