4

I use :vs to open a window. If I want this window to be the leftmost window, no matter what the currently active window is, how can I do it?

D. Ben Knoble
  • 26,070
  • 3
  • 29
  • 65
eyal karni
  • 1,106
  • 9
  • 33
  • 3
    You cannot really change the behavior of :vs to do what you want. I myself just do <C-w>v<C-w>H. But more single-minded way would be :vert topleft split – 3N4N Aug 24 '19 at 11:32
  • 2
    @klaus This is an answer, please turn it into one. You can use :topleft :vsplit, no need to switch to :vert. Also <C-w>H on its own after :vs, no need to switch to <C-w>v for that to work either. But it's still an answer, please post it as such. – filbranden Aug 24 '19 at 15:44
  • 1
    @filbranden, thanks. I posted an answer, including your suggestions. I actually didn't know :topleft was a {cmd} modifier, maybe cause it is only and specifically useful for splitting windows; and I personally do that with keybindings, not commands. That's why I suggested <C-w>v instead of :vs: it wasn't an answer and I was talking about my personal workflow. Anyway, thanks for the suggestions, and please, if you have time, check if the answer is correct. – 3N4N Aug 24 '19 at 16:26
  • 1
    @klaus Yes it was good. I edited it to remove the references to :vert (that's not really relevant here), rephrased it a little bit and added links to the help pages. Let me know if you disagree with any of the edits. Thanks for answering! – filbranden Aug 24 '19 at 16:53

2 Answers2

6

You can use a couple of methods to achieve the same end result as your request.

  • You can just open a vertical split and then move it to leftmost position using Controlw + ShiftH (note that the "h" is uppercase.) See :help CTRL-W_H for more information.

  • You can use :topleft to modify your :vs command to open the window in the leftmost position. You can use the following command for that:

    :topleft vs
    
filbranden
  • 28,785
  • 3
  • 26
  • 71
3N4N
  • 5,684
  • 18
  • 45
0

This is for the far right, but same idea.

function! CloseVspIfNeed()
    "let x = tabpagebuflist()
    "if len(x)==1
    "vsp
    "endif
    for k in getwininfo()
        if k['winrow']<=2 && k['wincol']>1
            "look no further
            let id=k['winid']
            call win_gotoid(id)
            :close
        endif
    endfor
endfunction

You might want to do :

set splitright
call CloseVspIfNeed()
vnew

to replace the window at the far right with new one.

eyal karni
  • 1,106
  • 9
  • 33