How can I make fzf.vim split the window evenly when I use ctrl-x or ctrl-v?

60 views Asked by At

When using the fzf plugin in vim, my configuration is as follows

let g:fzf_action = {
  \ 'ctrl-e': 'edit',
  \ 'ctrl-t': 'tab split',
  \ 'ctrl-x': 'split'),
  \ 'ctrl-v': 'vsplit' }

I want to use ctrl-x to split the current window horizontally and open the selected file in the new window, but I have a problem. The new window is not 50% of the original window’s width. I tried using 20split or 30split, but they are not exact 50% splits. I also wrote a function to do this, but it does not work as expected.

function! s:SplitWithFile(file) abort
  execute "split" . shellescape(a:file)
  execute "wincmd l"
  execute "normal <c-w>="
endfunction

let g:fzf_action = {
  \ 'ctrl-e': 'edit',
  \ 'ctrl-t': 'tab split',
  \ 'ctrl-x': function('s:SplitWithFile'),
  \ 'ctrl-v': 'vsplit' }

How can I achieve ctrl-x or ctrl-v and split the window evenly?

0

There are 0 answers