3

When I have split windows in Vim, I can resize the windows using :resize +1/-1. I wanted to add a shortcut for it that worked like split windows in terminator. In terminator, if I have two windows on top of each other, CTRL Shift Up / Down moves the separator between the two windows, meaning, if I'm in the top window and press CTRL Shift Down, the top window increases. On the other hand, if I'm in the bottom window, CTRL Shift Down decreases the bottom window. So, it truly moves the separator.

With split windows in vim, I tried to remap like this:

:nnoremap <silent> <c-Up> :resize -1<CR>
:nnoremap <silent> <c-Down> :resize +1<CR>

This works fine if I'm on the top window (pressing CTRL UP decreases the size of the window and CTRL Down increases the size). But when I move to the bottom window it behaves correctly but it has a weird effect (CTRL UP also decreases the size of the window). So, I can't simulate moving the separator.

Is it possible o run a command depending on which window I'm located at?

Adriano_Pinaffo
  • 1,429
  • 4
  • 23
  • 46

2 Answers2

3

Your code wasn't that wrong just needed a little changes. Now you can resize all the panes in both horizontal and vertical way:

:nnoremap <silent> <c-Up> :resize -1<CR>
:nnoremap <silent> <c-Down> :resize +1<CR>
:nnoremap <silent> <c-left> :vertical resize -1<CR>
:nnoremap <silent> <c-right> :vertical resize +1<CR>
SdSaati
  • 798
  • 9
  • 18
1

You can define a function in .vimrc

function! MoveSeparator(PlusMinus)
    let num=tabpagewinnr(tabpagenr())
    let pm=a:PlusMinus
    if  num == "2"
        let pm = pm == '+' ? '-' : '+'
    end
    exec "resize " . pm . "1"
endfunction

nnoremap <silent> <C-UP>   :call MoveSeparator("-")<CR>
nnoremap <silent> <C-DOWN> :call MoveSeparator("+")<CR>
Philippe
  • 20,025
  • 2
  • 23
  • 32
  • Thanks, this works perfectly if I have only two windows. But the moment I add one more, things go crazy. I'm not very familiar with this "vim language" but I will try to work on it using `winlayout()`, `win_id2tabwin()` and `:resize`. But first I will have to learn about these vim syntaxes, but your function was already a start for me, thanks. – Adriano_Pinaffo Apr 12 '20 at 14:37
  • Right.—-— Done. – Adriano_Pinaffo Apr 12 '20 at 15:41