vifm / vifm.vim

Vim plugin that allows use of vifm as a file picker
335 stars 19 forks source link

Leave vifm file selector open after opening a file #36

Closed mroavi closed 4 years ago

mroavi commented 4 years ago

I'm really happy using vifm as my file selector instead of NERDTree, which is also nice, but not as powerful. There is one functionality that I miss though. I would like vifm to stay open after opening a file (with the enter key) using the vifm file selector. I'm opening the vifm file selector using :leftabove vertical 40Vifm. This means that I should also be able to switch focus between the vifm file selector and the opened file. Is this possible to do at the current moment?

xaizek commented 4 years ago

Is this possible to do at the current moment?

It's not. Path to selected file is written on exiting vifm, which makes it problematic to select a file without restarting vifm. I've tried running this in vifm:

:!vim --servername $VIM_SERVERNAME --remote +'windo l' %c

but it doesn't open file where I'd expect.

mroavi commented 4 years ago

I managed to open something in the right with :!vim --servername NEW --remote-tab-silent %f & but it completely messed up vifm.

xaizek commented 4 years ago

If opening it in a tab will do, then use that. For me it looks like Vim behaves weirdly, the buffer appears empty until I enter insert mode in it.

mroavi commented 4 years ago

I've spent a few more hours on this issue but I still haven't managed to make it work. I tried to use the info on this link to see if I could open files using vifm in an adjacent tmux pane. Also no luck. Do you think this could work with this approach?

I also have another idea: would it be possible to open a file using vifm not in the current but in the other pane?

xaizek commented 4 years ago

if I could open files using vifm in an adjacent tmux pane. Also no luck. Do you think this could work with this approach?

Were you trying to do this from a :Vifm window? Vifm run like that acts differently as it's in a "file-picking mode". Since you don't need it to pick a single file anyway, you should run it using :term vifm. Otherwise, it should work. If it doesn't, explain what goes wrong.

I also have another idea: would it be possible to open a file using vifm not in the current but in the other pane?

If you want Vim to run inside vifm's pane, then it's not possible. There is no builtin terminal.

mroavi commented 4 years ago

I finally managed to get it working with vim's client-server functionality. Here is how in case anybody is interested:

  1. Start tmux with two side-by-side panes.
  2. Start vifm in the left pane.
  3. Start a vim server in the right pane: $ vim --servername svim
  4. From vifm, open the currently selected file in the vim server: :!vim --servername svim --remote-tab %f
  5. You can go one step further by remapping enter in your vifmrc file to run this command by default: nnoremap <cr> :!vim --servername svim --remote-tab %f<cr>

Works amazing.

my-vim-based-ide-3

I made a story in Medium out of this: https://medium.com/@mroavi/my-vim-based-ide-d8524bd0147c?sk=c225ec064ca14f0e327a1bbbaad3a40e