open multiple files in tabs, vim 7 can do that.
August 16th, 2006 mysurface Posted in alias, Text Manipulation, vi, vim | Hits: 45493 | 12 Comments »
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.







June 21st, 2007 at 7:52 pm
Excuse me, but how do I move from one file to another? Can you please mention that too
June 21st, 2007 at 8:59 pm
To move to next tab use
to previous tab
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.
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.
November 11th, 2009 at 5:24 am
I like to put this in my .vimrc file:
nmap :tabprev
nmap :tabnext
That way you can quickly switch between tabs with CTRL+H and CTRL+L.
November 11th, 2009 at 5:28 am
Whoops, that didn’t come through:
nmap <C-H> :tabprev<CR>
nmap <C-L> :tabnext<CR>
January 8th, 2010 at 12:20 am
I like those tab key mappings, great idea thanks!
C-H and C-L much easier than gt and gT IMO.
January 24th, 2010 at 6:24 pm
Hi, I have created a blog entry explaining the tab feature in vim and how to use it. Check it out.. http://blog.sriunplugged.com/vi/tab-feature-in-vim/
February 25th, 2010 at 6:57 am
Actually, if you just “:set hidden” you can change buffers without saving first. There’s no need to use one buffer per tabpage.
October 12th, 2011 at 10:30 pm
Thank you (and everyone else who posted, too).
January 29th, 2012 at 8:34 am
I actually laughed when I got this to work. I know its something simple, but it is really helpful. Thanks for the post!
also Ctrl-PageUp and Ctrl-PageDown, work to move between tabs. They are the same shortcuts for web browser tabs, Love it!
March 19th, 2013 at 8:50 pm
Such a useful tool. Is there a way, when in edit mode, to create a new tab with another file?