Repository: ptzz/lf.vim
Branch: master
Commit: 80a2ef0b1632
Files: 3
Total size: 8.1 KB
Directory structure:
gitextract_m0ibae45/
├── README.md
├── autoload/
│ └── floaterm/
│ └── wrapper/
│ └── lf.vim
└── plugin/
└── lf.vim
================================================
FILE CONTENTS
================================================
================================================
FILE: README.md
================================================
lf.vim
======
[lf](https://github.com/gokcehan/lf) integration in vim and neovim

Installation
------------
Install it with your favorite plugin manager. Example with vim-plug:
Plug 'ptzz/lf.vim'
Then, add the vim-floaterm dependency:
Plug 'voldikss/vim-floaterm'
**Note:** lf.vim should be loaded before vim-floaterm to override vim-floaterm's lf wrapper.
To install with vim pack you would need to enforce the loading order, by making both packages optional:
~$ ls .vim/pack/plugins/opt/
lf.vim vim-floaterm
And adding them manually in `.vimrc`:
packadd! vim-floaterm
packadd! lf.vim
**Note:** for [some](https://stackoverflow.com/questions/67930489/native-vim-plugin-load-order) [reason](https://github.com/vim/vim/issues/7056) the loading is reversed
How to use it
-------------
The default shortcut for opening lf is `<leader>f` (\f by default).
To disable the default key mapping, add this line in your .vimrc or init.vim: `let g:lf_map_keys = 0`.
Then you can add a new mapping with this line: `map <leader>f :Lf<CR>`.
To set the floating window width and height, set `g:lf_width` and `g:lf_height` accordingly. If not found, it will default to `g:floaterm_width` and `g:floaterm_height`.
The command for opening lf in the current file's directory is `:Lf`.
When opening (default 'l' and '\<right\>') a file from the lf window,
vim will open the selected file in the current window. To open the selected
file in a new tab instead use `:LfNewTab`.
(Note that the lf `open` command is required to return to the originating vim session.
E.g. the `edit` command opens a new process of $EDITOR.)
For opening lf in the current workspace, run `:LfWorkingDirectory`.
Vim will open the selected file in the current window.
`:LfWorkingDirectoryNewTab` will open the selected file in a new tab instead.
For changing the current directory via lf, run `:Lfcd`or run `:Lflcd` for the current window.
List of commands:
```vim
" Change directory with lf via cd or lcd
Lfcd
Lflcd
Lf " Open current file by default
LfCurrentFile " Default Lf behaviour
LfCurrentDirectory
LfWorkingDirectory
" Always open in new tabs
LfNewTab
LfCurrentFileNewTab
LfCurrentDirectoryNewTab
LfWorkingDirectoryNewTab
" Open tab if it exists or in new tab if it does not
LfCurrentFileExistingOrNewTab
LfCurrentDirectoryExistingOrNewTab
LfWorkingDirectoryExistingOrNewTab
```
The old way to make vim open the selected file in a new tab was to add
`let g:lf_open_new_tab = 1` in your .vimrc or init.vim. That way is still
supported but deprecated.
### Opening lf instead of netrw when you open a directory
If you want to see vim opening lf when you open a directory (ex: nvim ./dir or :edit ./dir), please add this in your .(n)vimrc.
```vim
let g:NERDTreeHijackNetrw = 0 " Add this line if you use NERDTree
let g:lf_replace_netrw = 1 " Open lf when vim opens a directory
```
### Setting a custom lf command
By default lf is opened with the command `lf` but you can set an other custom command by setting the `g:lf_command_override` variable in your .(n)vimrc.
For instance if you want to display the hidden files by default you can write:
```vim
let g:lf_command_override = 'lf -command "set hidden"'
```
================================================
FILE: autoload/floaterm/wrapper/lf.vim
================================================
function! floaterm#wrapper#lf#(cmd, jobopts, ...) abort
let lf_tmpfile = tempname()
let lastdir_tmpfile = tempname()
let original_dir = getcwd()
lcd %:p:h
let cmdlist = split(a:cmd)
if exists('g:lf_command_override')
let s:lf_command = g:lf_command_override
else
let s:lf_command = 'lf'
endif
let cmd = s:lf_command . ' ' . '-last-dir-path=' . fnameescape(lastdir_tmpfile) . ' -selection-path=' . fnameescape(lf_tmpfile)
if len(cmdlist) > 1
let cmd .= ' ' . join(cmdlist[1:], ' ')
else
let cmd .= ' "' . getcwd() . '"'
endif
exe "lcd " . original_dir
let cmd = [&shell, &shellcmdflag, cmd]
let a:jobopts.on_exit = funcref('LfCallback', [lf_tmpfile, lastdir_tmpfile])
return [v:false, cmd]
endfunction
================================================
FILE: plugin/lf.vim
================================================
" Copyright (c) 2015 François Cabrol
"
" MIT License
"
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
" "Software"), to deal in the Software without restriction, including
" without limitation the rights to use, copy, modify, merge, publish,
" distribute, sublicense, and/or sell copies of the Software, and to
" permit persons to whom the Software is furnished to do so, subject to
" the following conditions:
"
" The above copyright notice and this permission notice shall be
" included in all copies or substantial portions of the Software.
"
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
" EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
" NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
" LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
" OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
" WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
" ================ Lf =======================
function! OpenLfIn(path, edit_cmd)
let currentPath = shellescape(isdirectory(a:path) ? fnamemodify(expand(a:path), ":p:h") : expand(a:path))
let s:edit_cmd = a:edit_cmd
if exists(":FloatermNew")
exec 'FloatermNew' . ' --height=' . string(get(g:, 'lf_height', g:floaterm_height)) .
\ ' --width=' . string(get(g:, 'lf_width', g:floaterm_width)) .
\ ' --title=lf --titleposition=center lf -- ' . currentPath
else
echoerr "Failed to open a floating terminal. Make sure `voldikss/vim-floaterm` is installed."
endif
endfun
function! LfCallback(lf_tmpfile, lastdir_tmpfile, ...) abort
let edit_cmd = get(s:, 'edit_cmd', 'default')
if (edit_cmd == 'cd' || edit_cmd == 'lcd') && filereadable(a:lastdir_tmpfile)
let lastdir = readfile(a:lastdir_tmpfile, '', 1)[0]
if lastdir != getcwd()
exec edit_cmd . ' ' . lastdir
return
endif
elseif filereadable(a:lf_tmpfile)
let filenames = readfile(a:lf_tmpfile)
if !empty(filenames)
if has('nvim')
call floaterm#window#hide(bufnr('%'))
endif
let locations = []
let floaterm_opener = edit_cmd != 'default' ? s:edit_cmd : g:floaterm_opener
for filename in filenames
let dict = {'filename': fnamemodify(fnameescape(filename), ':p')}
call add(locations, dict)
endfor
call floaterm#util#open(locations, floaterm_opener)
unlet! s:edit_cmd
endif
else
let lf_exit_code = a:2
if lf_exit_code != 0
echoerr 'lf returned non-zero exit code ' . lf_exit_code
return
endif
endif
endfunction
" For backwards-compatibility (deprecated)
if exists('g:lf_open_new_tab') && g:lf_open_new_tab
let s:default_edit_cmd='tabedit'
else
let s:default_edit_cmd='edit'
endif
command! Lfcd call OpenLfIn(".", 'cd')
command! Lflcd call OpenLfIn(".", 'lcd')
command! LfCurrentFile call OpenLfIn("%", s:default_edit_cmd)
command! LfCurrentDirectory call OpenLfIn("%:p:h", s:default_edit_cmd)
command! LfWorkingDirectory call OpenLfIn(".", s:default_edit_cmd)
command! Lf LfCurrentFile
" To open the selected file in a new tab
command! LfCurrentFileNewTab call OpenLfIn("%", 'tabedit')
command! LfCurrentFileExistingOrNewTab call OpenLfIn("%", 'tab drop')
command! LfCurrentDirectoryNewTab call OpenLfIn("%:p:h", 'tabedit')
command! LfCurrentDirectoryExistingOrNewTab call OpenLfIn("%:p:h", 'tab drop')
command! LfWorkingDirectoryNewTab call OpenLfIn(".", 'tabedit')
command! LfWorkingDirectoryExistingOrNewTab call OpenLfIn(".", 'tab drop')
command! LfNewTab LfCurrentDirectoryNewTab
" For retro-compatibility
function! OpenLf()
Lf
endfunction
" To open lf when vim load a directory
if exists('g:lf_replace_netrw') && g:lf_replace_netrw
augroup ReplaceNetrwByLfVim
autocmd VimEnter * silent! autocmd! FileExplorer
autocmd BufEnter * let s:buf_path = expand("%") | if isdirectory(s:buf_path) | bdelete! | call timer_start(100, {->OpenLfIn(s:buf_path, s:default_edit_cmd)}) | endif
augroup END
endif
if !exists('g:lf_map_keys') || g:lf_map_keys
map <leader>f :Lf<CR>
endif
gitextract_m0ibae45/
├── README.md
├── autoload/
│ └── floaterm/
│ └── wrapper/
│ └── lf.vim
└── plugin/
└── lf.vim
Condensed preview — 3 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (9K chars).
[
{
"path": "README.md",
"chars": 3357,
"preview": "lf.vim\n======\n\n[lf](https://github.com/gokcehan/lf) integration in vim and neovim\n\n abort\n let lf_tmpfile = tempname()\n let lastdir_tmpfile = tempname()"
},
{
"path": "plugin/lf.vim",
"chars": 4233,
"preview": "\" Copyright (c) 2015 François Cabrol\n\"\n\" MIT License\n\"\n\" Permission is hereby granted, free of charge, to any person obt"
}
]
About this extraction
This page contains the full source code of the ptzz/lf.vim GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 3 files (8.1 KB), approximately 2.5k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.