Skip to content

The bundled Vim script plugin "lf.vim" only works in terminal vim not neovim. Why ? #2614

Description

@m040601

Apologies if this has been clarified before or explained somewhere else. I cant find it.

TLDR:

  • Why is it that this script lf.vim only works in vim but not neovim ? Is it
  • Would it be possible to upgrade it to also work in neovim ?

I'm looking for a simple solution for using lf BOTH from vim or neovim. I like
simplicity and have an aversion to installing extra stuff and wasting time
customizing too much.

According to the lf wiki, "Integrations.md"

The bundled Vim script plugin `etc/lf.vim` only works in terminal vim and provides only a basic `:LF` command.
There are a number of vim plugins providing more features which can be used in gvim and neovim as well:
.....

On my system, Archlinux, the official package "lf" installs these two files,

lf /usr/share/vim/vimfiles/ftdetect/lf.vim
lf /usr/share/vim/vimfiles/syntax/lf.vim
  • They are exactly the same file. Why ?
  • They are under "vimfiles/syntax" and "vimfiles/ftdetect" not in "/etc/lf.vim" as stated in the wiki. Why ?

Also on my system, Archlinux, the official "vim" or "neovim" packages install,

vim:

/usr/share/vim/vim92/ftplugin/lf.vim
/usr/share/vim/vim92/indent/lf.vim
/usr/share/vim/vim92/syntax/lf.vim

neovim:

/usr/share/nvim/runtime/ftplugin/lf.vim
/usr/share/nvim/runtime/indent/lf.vim
/usr/share/nvim/runtime/syntax/lf.vim

That "vim92/syntax/lf.vim" or "nvim/runtime/syntax/lf.vim" are for the syntax highlighting. They have nothing to do
with the lf package installed "/vim/vimfiles/syntax/lf.vim". They are different
files.

Anyway.

I tested it in vim. I did what the lf wiki says, and added to my .vimrc,

"     let lfvim = "/usr/share/vim/vimfiles/ftdetect/lf.vim"
"     if filereadable(lfvim)
"         exec "source " . lfvim
"     endif
"     nnoremap <leader>l :LF<cr>

It works perfectly. It is simple and it is enough for me. It comes already shipped with lf. I do not need or want more.

The only issue is, it only works for vim, not neovim.

Would it be possible to change that situation ?

Thanks in advance.

Additionally, and to avoid confusion and misunderstandings with the syntax
files, wouldnt it be more sensible for lf to rename that shipped script file
"lf.vim" ? Maybe something like "lfopen.vim" or "open_with_lf.vim" ?

Activity

  1. valoq commented on Jun 11, 2026

    @valoq
    Contributor

    The bundled lf.vim opens lf with "silent !lf", which works in Vim because :! gives lf the terminal, but Neovim's :! is noninteractive
    that's why it only works in Vim.

    You can try this version of lf.vim

    function! s:LfOpen(temp)
        if !filereadable(a:temp)
            redraw!
            return
        endif
        let names = readfile(a:temp)
        if empty(names)
            redraw!
            return
        endif
        exec 'edit ' . fnameescape(names[0])
        for name in names[1:]
            exec 'argadd ' . fnameescape(name)
        endfor
        redraw!
    endfunction
    
    function! s:LfExit(temp, job, code, event)
        tabclose
        call s:LfOpen(a:temp)
    endfunction
    
    function! LF()
        let temp = tempname()
        let cmd = 'lf -selection-path=' . shellescape(temp)
        if has('nvim')
            " neovim's :! is not interactive, so run lf in a terminal buffer
            tabedit
            call termopen(cmd, {'on_exit': function('s:LfExit', [temp])})
            startinsert
        else
            exec 'silent !' . cmd
            call s:LfOpen(temp)
        endif
    endfunction
    command! -bar LF call LF()
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions