Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update lf.vim to work with Neovim and in GUI and use fallbacks #1798

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update lf.vim
  • Loading branch information
Konfekt authored Sep 13, 2024
commit ff4717a00f61883f90c1a4c10357c641aae6a9e7
26 changes: 15 additions & 11 deletions etc/lf.vim
Original file line number Diff line number Diff line change
@@ -13,28 +13,28 @@
" nnoremap <leader>l :LF<cr>
"

let s:temp = tempname()
if executable('lf')
command! -bar LF call FilePicker('lf', '-selection-path')
command! -nargs=? -bar -complete=dir FilePicker call FilePicker('lf', '-selection-path', s:temp, <q-args>)
elseif executable('ranger')
" The option --choosefiles was added in ranger 1.5.1.
" Use --choosefile with ranger 1.4.2 through 1.5.0 instead.
command! -bar LF call FilePicker('ranger', '--choosefiles')
command! -nargs=? -bar -complete=dir FilePicker call FilePicker('ranger', '--choosefiles='..s:temp, '--selectfile', <q-args>)
elseif executable('nnn')
command! -bar LF call FilePicker('nnn', '-P')
command! -nargs=? -bar -complete=dir FilePicker call FilePicker('nnn', '-p', s:temp, <q-args>)
endif

if exists(':LF') == 2
" From https://github.com/philFernandez/rangerFilePicker.vim/blob/master/plugin/rangerFilePicker.vim
let s:temp = tempname()

if exists(':FilePicker') == 2
function! FilePicker(...)
let cmd = a:000 + [s:temp]
let path = a:000[-1]
let cmd = a:000[:-2] + (empty(path) ?
\ [filereadable(expand('%')) ? expand('%:p') : '.'] : [path])
if has('nvim')
enew
call termopen(cmd, { 'on_exit': function('s:open') })
else
if has('gui_running')
if has('terminal')
" exec 'terminal' join(cmd) | call s:open()
call term_start(cmd, {'exit_cb': function('s:term_close'), 'curwin': 1})
else
echomsg 'GUI is running but terminal is not supported.'
@@ -48,13 +48,17 @@ if exists(':LF') == 2
if has('gui_running') && has('terminal')
function! s:term_close(job_id, event)
if a:event == 'exit'
bwipeout!
call s:open()
endif
endfunction
endif

function! s:open(...)
if !filereadable(s:temp)
" if &buftype ==# 'terminal'
" bwipeout!
" endif
redraw!
" Nothing to read.
return
@@ -66,10 +70,10 @@ if exists(':LF') == 2
return
endif
" Edit the first item.
exec 'edit ' . fnameescape(names[0])
exec 'edit' fnameescape(names[0])
" Add any remaning items to the arg list/buffer list.
for name in names[1:]
exec 'argadd ' . fnameescape(name)
exec 'argadd' fnameescape(name)
endfor
redraw!
endfunction