vim: "extend" window into next window - vim

Let's say I have this layout in vim:
+-----+-----+-----+
| | | |
| a | | |
| | | |
+-----+ c | d |
| | | |
| b | | |
| | | |
+-----+-----+-----+
is it possible to end up with this layout:
+-----+-----+-----+
| | | |
| a | c | |
| | | |
+-----+-----+ d |
| | |
| b | |
| | |
+-----+-----+-----+
like an "extend right" command ?
PS. Don't tell me to use ctrl-w J on b then ctrl-w L on d, my layout is actually more complex then this. I'm really looking for an "extend right" command if it exists.

This is hard to implement as a feature since there can be a lot of edge case scenarios to consider, also why vim doesn't do this natively.
If you don't like the option of using ctrl-w J on b then ctrl-w L on d then the simplest approach would be to close the c split and then open a new vertical split on a and open the buffer / file within it that you desired.

This is brittle, but probably better than nothing!
function! ExtendRight()
let l:start=winnr()
exe "normal \<c-w>l"
let l:shrink=bufnr('%')
close
exe "normal " . l:start . "\<c-w>w"
exe "normal \<c-w>k"
vsplit
exe "b " . l:shrink
endfunction
You can map it with nnoremap <c-w>e :call ExtendRight()<CR>.

Related

Moving a split Vim window to the other half of the screen

Let's say we have 3 buffers (A, B, C) open in Vim arranged as follows
-----------------------------------------
| | |
| | |
| | |
| A | |
| | |
| | |
|------------------| B |
| | |
| | |
| C | |
| | |
| | |
-----------------------------------------
and we want to rearrange it as
-----------------------------------------
| | |
| | |
| | |
| | B |
| | |
| | |
| A |--------------------|
| | |
| | |
| | C |
| | |
| | |
-----------------------------------------
I know I can do this by closing C and reopening it after splitting B. Is there a simple way to do this where I don't have to close buffers and I can rearrange the windows directly?
You wouldn't "close" the buffer C, only the window that displays it.
Vim has dedicated normal mode commands for:
switching a window and the next one in a row or column,
rotating the whole window layout,
pushing a window to the far top, far right, far bottom, and far left,
but it doesn't have one for moving a window to an arbitrary point so, assuming the window you want to move has the focus, the command should look like this:
:q|winc w|sp c
which is not too shabby. You might be able to find a plugin that provides the level of control you are after on https://www.vim.org.

Vim: How to open new vertical split for file under cursor

I know gf opens the file under cursor, and CTRL-w f opens the file under cursor in a new split window.
I'm probably being greedy but, how do you open it in a new vertical window?
From normal mode, you could type C-w f C-w L or C-w v gf, and from the command-line you could execute :wincmd f | wincmd L or :vert wincmd f.
They are not strictly equivalent, though.
With C-w f C-w L and :wincmd f | wincmd L, the height of your vertical viewport will be maximized no matter the current layout. So, for example, if you have a horizontal viewport below, its width should be decreased:
+-----------------+ +--------+-------+
| path/to/fileC | | | |
| | → | | |
| fileA | | fileA | fileC |
+-----------------+ +--------+ |
| | | | |
| fileB | | fileB | |
+-----------------+ +--------+-------+
With C-w v gf and :vert wincmd f, the height of your vertical viewport should be the same as the current one, and thus it shouldn't affect the horizontal viewport below:
+-----------------+ +--------+-------+
| path/to/fileC | | | |
| | → | | |
| fileA | | fileA | fileC |
+-----------------+ +--------+-------+
| | | |
| fileB | | fileB |
+-----------------+ +----------------+

Expand vim split

I've have splits open in vim which look like:
----------------
| A | B | C |
----------------
| D | E |
----------------
I'd like to expand the C split such that my splits look like:
----------------
| A | B | |
----------| C |
| D | E | |
----------------
Is there an easy way to do this?
Press <C-W>L in window C. See :h CTRL-W_L.

is there a way to move vim windows in this way?

I have four windows like this:
| | | |
| A | | |
|_________| C | D |
| B | | |
| | | |
So, how can I change them into this way?
| | |
| A | C |
|_________|______|
| B | D |
| | |
the
ctrl+W/J/K/L
thing is always moving the window to the far other side, I can't use them to do this.
Thanks!
what I can think of is two steps:
move cursor to C, press C-W c to close the window
move cursor to D, press :sp #<enter>
The idea is, close one window(buffer), and reopen it in right place (by sp or vs).
glad to know if there is easier way.

How to move vertical split window to horizontal split, when there is an existing horizontal split?

In Vim I tend to open buffers in new vertical splits (with the occasional horizontal split). I keep my code to 80 chars wide, so this works pretty well on large monitors.
I often end up with this window arrangement:
---------------------
| | | | |
| | | | |
------ | A | B |
| | | | |
| | | | |
---------------------
At four or five columns wide, it can start getting a bit too narrow, so then I want to move the windows around so it looks like this:
----------------
| | | A |
| | | |
------ ------
| | | B |
| | | |
----------------
As far as I know, this is impossible to do by moving the windows in Vim.
The only way to get that window arrangement I've found, is to close window A, and then re-open A as a new horizontal split from window B.
Is that correct, or is there a way to move/re-arrange windows like that in Vim? Maybe a plugin?
I'm yet to find anything, so I thought I would ask because I find the opening/closing of windows anoying and breaks my flow.
FWIW, I find the Ctrl-W + J / Ctrl-W + K shortcuts useless, because they make the new horizontal split as wide as the whole screen, rather than splitting with the neighbouring window. I.e. Ctrl-W + J would give me this:
----------------
| | | |
| | | |
------ | A |
| | | |
| | | |
----------------
| |
| B |
----------------
Which is generally never what I want.
If anyone has some ideas, let me know!
There's a plugin that can do exactly what you want. Here's the link : https://github.com/fabi1cazenave/suckless.vim.

Resources