Let's say I have single Vim tab displaying 9 buffers (equally separated, like a table 3x3). Currently, to get from the top left window to the bottom right one, I have to press 3, Ctrl+W, J, and then 3, Ctrl+W, L. This is cumbersome and I would like to just be able to press Ctrl+9 to go to the 9th window and Ctrl+3 to go to the 3rd window, etc. Is there any easy way I can map something like this in Vim?
相关问题
- Emacs shell: save commit message
- How to change the first two uppercase characters o
- Insert text into current buffer from function
- Hot reload on save
- Substituting zero-width match in vim script
相关文章
- 如何让 vim 支持 .cshtml 文件的代码高亮
- window端口父进程PID查询
- Auto-save in VIM as you type
- How can I use gcc's -I command to add recursiv
- Vim: overloaded mapping for multiple modes
- How to use relative line numbering universally in
- How to copy the value of a vim option to a registe
- Can you get the parent GTK window from a widget?
I like to move around with the arrow keys.
I map ctr+direction to move to the next window partition in that direction.
You cant jump directly from one window to another but I find that it makes it very easy to move between windows
Not exactly what you're looking for, but if you're using a terminal that supports it, you can set the following options:
and click on a buffer to switch to it. Yes, with the mouse.
A bunch of other mouse behavior works too - you can click to move the insertion point, drag to select text or resize splits, and use the scroll wheel.
Ermmm... I'm pretty sure that this will not keep window layout as it is, but I use
to go to system.h,
to go to
MyLargeNamedClassSingleton.cpp
buf
will do autocomplete (possibly menucompletion if so configured) so you can doto list what files could match the
part
you typed. Beats the crap out of navigating buffers all around.But I understand, this doesn't answer your specific question of course :)
There's a much simpler solution than using the mouse or hard-set movement mappings; they will break if the window numberings are different from what you have in mind for a 3x3 matrix, or if you decide to work with less than 9 windows. Here's how:
Include the following in your
.vimrc
:Now you can just press
<Leader><number>
and be taken to the window number you want. I wouldn't recommend going beyond 9, because IMO, the utility of having multiple viewports follows a Rayleigh distribution and quickly becomes useless with too many viewports in one window.It will be helpful if you have the window number displayed in your
statusline
to aid you in quickly figuring out which window you're on and which window you want to go to. To do that, use this little function and add it accordingly in yourstatusline
.See it in action in your
statusline
:Note that the above line will replace your
statusline
. It was just meant for illustration purposes, to show how to call the function. You should place it where ever you think is appropriate in yourstatusline
. Here's what mine looks like:EDIT:
romainl asked for my status line in the comments, so here it is:
The last line should be a single line (be careful if your setup automatically breaks it into multiple lines). I know there are ways to keep it organized with incremental string joins in each step, but I'm too lazy to change it. :) The
GitBranch()
function (with other git capabilities) is provided by the git.vim plugin. There's a bug in it as noted here and I use the fork with the bug fix. However, I'm leaving both links and the blog here to give credit to all.Also, note that I use a dark background, so you might have to change the colours around a bit if you are using a light scheme (and also to suit your tastes).
Better, more general answer:
Use countCtrl+wCtrl+w to jump to the count window below/right of the current one.
For example, if you're in the top left of a 3x3 grid and want to jump to the bottom left you'd use 7Ctrl+wCtrl+w.
Specific 3x3 grid answer:
If you're always using a 3x3 layout you could try these mappings for the numpad, which always jump to the top left and then move the appropriate amount from there, with the key's position on the keypad jumping to the window's with 'equivalent' position on the screen:
Edited: turns out c-w c-w goes to the top left at the start automatically. The explicit 1 is required in the first mapping, as c-w c-w without a count toggles between the current and the previously selected window.
(The Ctrl-W t mapping always goes to the top-left most window, the Ctrl-W b mapping always goes to the bottom-rightmost).
Alternatively you could map each number to jump to the Nth window, so k6 would be 6 c-w c-w, rather than trying to lay out the keys as on screen.
I prefer use standard vim keys(jkhl).
There is a trick if you notice that the first two maps can jump clock wise or the reverse, rather than just jumping up or down.
And you can also switch to any window directly with
<Number><C-J>
, for example,2<C-J>
will go to the 2nd window.