vim windows and tabs

Tabs are great, I don't know what I would do without tabs, they are everywhere, your browser has them, your editor has them, even your webmail has them ( see yahoo mail ). Well I just discovered vim has them too.

Before windows and tabs

I don't know why I never thought of this before. I was always opening each file in it's own vim session, but that's hard to work with, you can't copy/paste from one file to another using vim commands ( my, y`y, P ) , I used the mouse for that ( not the best choice ). And to switch from one session to another I had to always do CTRL-Z ( to put current session in background ) then fg x to put another session in foreground. That was until I discovered screen split.

Multiple windows

With vim you can split the screen vertically or horizontally and open a different, same or new file in each screen.

Pplit the screen horizontally - :sp filename or :new [filename]

Split the screen vertically - :vsp filename or :vne[w] [filename]

If you use :sp/:vsp with no filename specified then the current screen will be split in half and it's content copied to both screens.

If you use :new/:vne with no filename then it will just create a new empty window.

Move to the next with : CTRL-W j or CTRL-W <down arrow>

Move to the previous window with: CTRL-W k or CTRL-W <up arrow>

You can also jump more then one window by using a number after CTRL-W. For example CTRL-W 3 j will take you to the third window from your current position.

This was great for visually comparing sections of files or to do copy/paste , but you're limited by the screen size. If you split your screen in 10 you're not going to see much from any file.

The Tabs

To open a new tab :tabnew [filename]

You can move between tabs with CTRL-PageDown and CTRL-PageUp or type a number before CTRL-PageDown or CTRL-PageUp and you'll jump that number of pages.

You want to close all tabs except the current tab? :tabo

Close current tab - :tabc

Close n'th tab: :tabc n

There are a few other commands for working with tabs but it's likely you'll never remember all of them so I'm not going to write about them. there's always vim built in documentation for that.

Never underestimate the power of vim!

Do you know good vim tips and tricks ? Care to share in the comments?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.