How can I launch fzf inside vim and open the selected file on a split window? I don't want to install any plugin.
I tried
:!a=$(ls | fzf) && vsplit $a
How can I launch fzf inside vim and open the selected file on a split window? I don't want to install any plugin.
I tried
:!a=$(ls | fzf) && vsplit $a
Since fzf needs access to the console, you will need to run it as a foreground command and there isn't really a good way for you to do that and capture the output from fzf (the filename) in Vim through a pipe. So using a temporary file to store the filename is the easiest approach here.
A simple solution is:
function! SelectFile()
let tmp = tempname()
execute '!ls | fzf >'.tmp
let fname = readfile(tmp)[0]
silent execute '!rm '.tmp
execute 'vsplit '.fname
endfunction
Then use it with:
:call SelectFile()
(Or create a key mapping or a user command for it.)
Using the Vim :terminal to run fzf inside it (instead of shelling out with :!) is also a good option.
In any case, the real best approach here is to just use one of the excellent Vim plug-ins, either the simple bare-bones one which is included with fzf itself and probably also the more complete fzf.vim which builds on the low-level plug-in to deliver powerful features you'll benefit from having around.