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?
Asked
Active
Viewed 1,540 times
4
D. Ben Knoble
- 26,070
- 3
- 29
- 65
eyal karni
- 1,106
- 9
- 33
2 Answers
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_Hfor more information.You can use
:topleftto modify your:vscommand 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
:vsto 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:topleft :vsplit, no need to switch to:vert. Also<C-w>Hon its own after:vs, no need to switch to<C-w>vfor that to work either. But it's still an answer, please post it as such. – filbranden Aug 24 '19 at 15:44:topleftwas 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>vinstead 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: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