vim-lf

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 503d2cd245f3a97abb35496ecdb7bf1c8138ee4b
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Tue, 14 Apr 2020 19:26:04 +0200

Initial commit

Diffstat:
A.gitignore | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aautoload/lf.vim | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aplugin/lf.vim | 3+++
3 files changed, 115 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,58 @@ + +# Created by https://www.gitignore.io/api/macos,vim +# Edit at https://www.gitignore.io/?templates=macos,vim + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Vim ### +# Swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +*~ + +# Auto-generated tag files +tags + +# Persistent undo +[._]*.un~ + +# Coc configuration directory +.vim + +# End of https://www.gitignore.io/api/macos,vim diff --git a/autoload/lf.vim b/autoload/lf.vim @@ -0,0 +1,54 @@ +function! lf#LF(path, edit_cmd) + let oldguioptions = &guioptions + let s:oldlaststatus = &laststatus + let s:choice_file_path = tempname() + let s:edit_cmd = a:edit_cmd + try + if has('nvim') + set laststatus=0 + let currentPath = expand(a:path) + let lfCallback = { 'name': 'lf', 'edit_cmd': a:edit_cmd } + function! lfCallback.on_exit(job_id, code, event) + if a:code == 0 + if exists(":Bclose") + silent! Bclose! + else + echoerr "Failed to close buffer, make sure the `rbgrouleff/bclose.vim` plugin is installed" + endif + endif + try + if filereadable(s:choice_file_path) + for f in readfile(s:choice_file_path) + exec self.edit_cmd . f + endfor + call delete(s:choice_file_path) + endif + endtry + let &laststatus=s:oldlaststatus + endfunction + enew + call termopen('lf -selection-path=' . s:choice_file_path . ' "' . currentPath . '"', lfCallback) + startinsert + else + function! s:EditCallback() + if filereadable(s:choice_file_path) + for f in readfile(s:choice_file_path) + exec s:edit_cmd . f + endfor + call delete(s:choice_file_path) + endif + redraw! + " reset the filetype to fix the issue that happens + " when opening lf on VimEnter (with `vim .`) + filetype detect + endfunction + set guioptions+=! " Make it work with MacVim + let currentPath = expand(a:path) + let buf = term_start(["lf", '-selection-path='.s:choice_file_path, '"'.currentPath.'"'], #{hidden: 1, term_finish: 'close'}) + let winid = popup_dialog(buf, #{minwidth: 150, minheight: 20, highlight: 'Normal'}) + let bufn = winbufnr(winid) + exe 'autocmd! BufWinLeave <buffer='.bufn.'> call s:EditCallback()' + endif + endtry + let &guioptions=oldguioptions +endfunction diff --git a/plugin/lf.vim b/plugin/lf.vim @@ -0,0 +1,3 @@ +command! -nargs=+ LF call lf#LF(<f-args>) +nnoremap <Plug>LfEdit :LF % edit<CR> +nnoremap <Plug>LfSplit :LF % split<CR>