0

Let's say I have a grid of 3x2 windows open and I am focused on the bottom right one. I want to switch to the one on the bottom left with one command, not move left twice. Vice versa as well. There's <C-W>t and <C-W>b which switch to the top or bottom windows, but I want to move to the far left and right. H and L moves the position of the window, when I want to switch which window focus.

1
  • 1
    All the commands for moving the cursor to another window are listed under :help window-move-cursor, including the ones you give as example: <C-w>t for the top-left window and <C-w>b for the bottom-right window. There obviously is no equivalent for the top-right and bottom-left windows so the only possibilities that don't imply writing a lot of fragile vimscript are those provided by @friedrich. If those don't suit you, look for a plugin that solves your problem.
    – romainl
    Commented May 15 at 14:37

2 Answers 2

0

In Vim, you often prepend a count to your commands. This is no exception. Use <C-W>2h to move two windows to the left, giving your bottom left window focus.

You can also click the respective window with the mouse; assuming you have :set mouse to any working value.

0

:wincmd can take a count, and even $ is accepted.

As such, :$wincmd l/$wincmd j and :$wincmd j/k seem to be a good start. From there any mapping where you combine them should do.

e.g.

:nnoremap <silent> <c-w>B :<c-u>$wincmd j<cr>:$wincmd h<cr>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.