Switching between split buffers using keystrokes

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Switching between split buffers using keystrokes

Robert Cussons
Dear vim users,

after using the :split command, I often want to switch between two buffers
that I have opened in the same window. I have discovered one way to do this,
quite by accident, which is to use <ctrl> - w, <ctrl> -w. Don't know why this
works but it does the job. However it is not the most winning key combination
for such a common task, does anyone know of a better one?
Thanks,
Rob.
Reply | Threaded
Open this post in threaded view
|

Re: Switching between split buffers using keystrokes

R Sam
You could do CTRL-W and use the arrow keys to move the cursor to the
direction of the split window you are interested in.

You could also do <n> CTRL-W <arrow> where n is the number of moves. For
example 2 CTRL-W <right arrow> would move your cursor two windows to the
right.

Regards
-Sam

On 9/28/05, Robert Cussons <[hidden email]> wrote:

> Dear vim users,
>
> after using the :split command, I often want to switch between two buffers
> that I have opened in the same window. I have discovered one way to do this,
> quite by accident, which is to use <ctrl> - w, <ctrl> -w. Don't know why this
> works but it does the job. However it is not the most winning key combination
> for such a common task, does anyone know of a better one?
> Thanks,
> Rob.
>
Reply | Threaded
Open this post in threaded view
|

Re: Switching between split buffers using keystrokes

Tim Chase-2
In reply to this post by Robert Cussons
> after using the :split command, I often want to switch between
> two buffers that I have opened in the same window. I have
> discovered one way to do this, quite by accident, which is to
> use <ctrl> - w, <ctrl> -w. Don't know why this works but it
> does the job. However it is not the most winning key
> combination for such a common task, does anyone know of a
> better one?

I'm not sure what you'd consider a "better one".  Almost all (if
not *all*) the window commands use ^W as a leader character.
^W^W is the "next window" command.  In addition, with multiple
windows open, you can use ^W followed by h/j/k/l to move to the
window in that direction relative to your current window.  ^Wx
exchanges your current window with the next one.  ^Wr rotates
your windows.  And much, much more!  ("...order now and get this
free set of Gnusu knives, free, Free, FREE!" :)

For more information, check out

        :help windows.txt

If you simply want it as a single keypress, you can do something like

        :nnoremap <f4> <c-w><c-w>

which will reduce the 2.5 keypresses to one.  However, once your
brain gets hard-wired to hit ^W any time you want to do a window
operation, it's just muscle-memory.

-tim




Reply | Threaded
Open this post in threaded view
|

Re: Switching between split buffers using keystrokes

A.J.Mechelynck
In reply to this post by Robert Cussons
----- Original Message -----
From: "Robert Cussons" <[hidden email]>
To: <[hidden email]>
Sent: Wednesday, September 28, 2005 3:26 PM
Subject: Switching between split buffers using keystrokes


> Dear vim users,
>
> after using the :split command, I often want to switch between two buffers
> that I have opened in the same window. I have discovered one way to do
> this,
> quite by accident, which is to use <ctrl> - w, <ctrl> -w. Don't know why
> this
> works but it does the job. However it is not the most winning key
> combination
> for such a common task, does anyone know of a better one?
> Thanks,
> Rob.

To move to next split-window (or from bottom right to top left): Ctrl-W
Ctrl-W or Ctrl-W w

To move to previous split-window (or from top left to bottom right): Ctrl-W
W i.e. Ctrl-w Shift-w

Attention: with a count, either command moves to the nth down from top
right, not to the nth after or before current window.

see ":help CTRL-W_CTRL-W"

If you want to do it with a single keystroke, use a mapping, e.g.

    :map    <F12>    <C-W>w
    :map    <F11>    <C-W>W
    :imap    <F12>    <C-O><C-W>w
    :imap    <F11>    <C-O><C-W>W


Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

RE: Switching between split buffers using keystrokes

Keith W. Roberts
In reply to this post by Robert Cussons
----Original Message----
From: Robert Cussons [mailto:[hidden email]]
Sent: Wednesday, September 28, 2005 6:26 AM
To: [hidden email]
Subject: Switching between split buffers using keystrokes

> Dear vim users,
>
> after using the :split command, I often want to switch between two
> buffers that I have opened in the same window. I have discovered one
> way to do this, quite by accident, which is to use <ctrl> - w, <ctrl>
> -w. Don't know why this works but it does the job. However it is not
> the most winning key combination for such a common task, does anyone
> know of a better one? Thanks, Rob.

I like these:

        " switch to previous window
        nnoremap <F11>  <C-W><C-P>
        inoremap <F11>  <ESC><C-W><C-P>

        " Switch between windows
         noremap <C-Right> <C-W><Right>
         noremap <C-Left> <C-W><Left>
         noremap <C-Up> <C-W><Up>
         noremap <C-Down> <C-W><Down>
        " we need to inoremap to the 'raw' commands (unlike Normal mode)
        inoremap <C-Right> <C-O><C-W>l
        inoremap <C-Left> <C-O><C-W>h
        inoremap <C-Up> <C-O><C-W>k
        inoremap <C-Down> <C-O><C-W>j

-Keith