-
-
Notifications
You must be signed in to change notification settings - Fork 577
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
When typing ".." change to upper directory #338
Comments
I was looking for the same thing. What I had in mind was not to type The workaround of course is to exit the fzf context and run :cd .. in vim. |
for the meantime, I am using https://github.com/airblade/vim-rooter
|
When using ":Files" in vim, I would like to change to upper directory using something like ".." or |
If you understand what fzf really is and how it works (it's a generic, context-free text filter running outside of Vim), you'll realize that it's not something we can easily implement with fzf. But you can experiment with " Reloading source on CTRL-P. Requires fd command.
function! Foo(dir)
let tf = tempname()
call writefile(['.'], tf)
call fzf#vim#files(a:dir, {'source': 'fd', 'options': ['--bind', printf('ctrl-p:reload:base="$(cat %s)"/..; echo "$base" > %s; fd . "$base"', shellescape(tf), shellescape(tf))]})
endfunction
command! -nargs=* Foo call Foo(<q-args>) |
Hi there, " Search pattern across repository files
function! FzfExplore(...)
let inpath = substitute(a:1, "'", '', 'g')
if inpath == "" || matchend(inpath, '/') == strlen(inpath)
execute "cd" getcwd() . '/' . inpath
let cwpath = getcwd() . '/'
call fzf#run(fzf#wrap(fzf#vim#with_preview({'source': 'ls -1ap', 'dir': cwpath, 'sink': 'FZFExplore', 'options': ['--prompt', cwpath]})))
else
let file = getcwd() . '/' . inpath
execute "e" file
endif
endfunction
command! -nargs=* FZFExplore call FzfExplore(shellescape(<q-args>)) |
That works great! I wonder what it would take to make it honor the fzf_actions so you can hit ctrl+v or ctrl+s to split instead of |
@junegunn Wouldnt this also work without a temp file? I'm a beginner with vimscript so the following code might not be perfect but it works for me: function! TFile(dir)
if empty(a:dir)
let dir = getcwd()
else
let dir = a:dir
endif
let parentdir = fnamemodify(dir, ':h')
let spec = fzf#wrap(fzf#vim#with_preview({'options': ['--expect', 'ctrl-u'] }))
" hack to retain original sink used by fzf#vim#files
let origspec = copy(spec)
unlet spec.sinklist
unlet spec['sink*']
function spec.sinklist(lines) closure
if len(a:lines) < 2
return
endif
if a:lines[0] == 'ctrl-u'
call TFile(parentdir)
else
call origspec.sinklist(a:lines)
end
endfunction
call fzf#vim#files(dir, spec)
endfunction
command! -nargs=* TFile call TFile(<q-args>) I can now use
|
Batch file for Windows (assuming git is installed)
@echo off
setlocal disabledelayedexpansion
"C:\Program Files\Git\usr\bin\echo.exe" -n \.. >> "%1"
for /f %%l in ('findstr . "%1"') do set base=%%l
fd.exe . "%base%"
endlocal function Files(dir)
var tf = tempname()
call writefile(['.'], tf, 'b')
call fzf#vim#files(dir, {'options': ['--bind', printf('pgup:clear-query+reload:fzf-up %s', shellescape(tf))]})
endfunction
command! -nargs=? -complete=dir Files call Files(<q-args>) |
@unphased I modified the code a bit, to restore the functionality to open in new function! FzfExplore(...)
if a:1 =~ "enter"
return
elseif a:1 =~ "ctrl-t"
execute "tabnew"
elseif a:1 =~ "ctrl-v"
execute "vnew"
elseif a:1 =~ "ctrl-s"
execute "new"
else
let inpath = substitute(a:1, "'", '', 'g')
echo matchend(inpath, '/')
if inpath == "" || matchend(inpath, '/') == strlen(inpath)
execute "cd" getcwd() . '/' . inpath
let cwpath = getcwd() . '/'
let cmd = 'ls -1p; echo ../'
let spec = fzf#vim#with_preview({'source': cmd, 'dir': cwpath, 'sink': 'FZFExplore', 'options': ['--prompt', cwpath, '--expect=ctrl-t,ctrl-v,ctrl-s,enter']})
call fzf#run(fzf#wrap(spec))
else
let file = getcwd() . '/' . inpath
execute "e" file
set acd
endif
endif
endfunction
command! -nargs=* FZFExplore set noacd | call FzfExplore(<q-args>)
|
First at all, thanks and congratulations for all your efforts creating and sharing this tools.
I start to use
fzf
to replacectrl-p
but I still can find a way to achieve/replicate the same behavior when typing 2 dots ".." in order to cd to the upper directory and be capable of searching files outside the main directory of the project.If my project has this structure:
If I open
:Files
within the pathI am bound only to that directory, but would be nice if withing
fzf
by typing..
I could go one level back:By pressing again .. I would go to:
And there I would eazy go to:
Any idea of how to achieve this?
Thanks in advance.
The text was updated successfully, but these errors were encountered: