Monday, November 16, 2009

open multiple files in tabs, vim 7 can do that.

open multiple files in tabs, vim 7 can do that.

Remember last time when I open multiple files using vim, it will be loaded and store at the back buffer, in order to bring it to front, you need to first save your current file with :w then :bn for next :bp for previous. But seems vim 7 support tabs, I would like to open multiple files in tab for each file.

vim -p file1 file2 file3

But we might forget to specified -p and open files in the old manner, which my key maps to utilized tab become useless. I realize that if open one file with -p doesn’t have much different without -p, therefore, I play a trick. I set an alias in .bashrc ( .bashrc at home directory).

Insert this into .bashrc:

alias vi="vim -p"

alias allows me to change the way of calling vim, when I type vi, bash shell will replace vi command with vim -p. Therefore, now i can open multiple files in tabs like

vi file1 file2 file3

Important: after changing the .bashrc, terminal have to be restart to see the effects.

#

To move to next tab use

:tabn

to previous tab

:tabp

#
Max Says:
February 8th, 2008 at 2:47 pm

It’s better to use gt and gT to move forward and backwards in the tabs, respectfully. That way you don’t have to enter command mode.
#
LegionZero Says:
July 18th, 2009 at 7:39 am

“”Important: after changing the .bashrc, terminal have to be restart to see the effects.”"

if you are like me and don’t like to restart do:

$ source ~/.bashrc

that way any changes you’ve made to your .basrc file will be loaded on the fly.

Jason Machacek Says:
November 11th, 2009 at 5:24 am

I like to put this in my .vimrc file:

nmap <C-H> :tabprev<CR>
nmap <C-L> :tabnext<CR>

That way you can quickly switch between tabs with CTRL+H and CTRL+L.

No comments: