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

August 16th, 2006 mysurface Posted in alias, Text Manipulation, vi, vim | Hits: 71211 | 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.

12 Responses to “open multiple files in tabs, vim 7 can do that.”

  1. Excuse me, but how do I move from one file to another? Can you please mention that too

  2. To move to next tab use


    to previous tab

  3. 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.

  4. LegionZero Says:

    “”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.

  5. 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.

  6. Whoops, that didn’t come through:

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

  7. I like those tab key mappings, great idea thanks!
    C-H and C-L much easier than gt and gT IMO.

  8. Hi, I have created a blog entry explaining the tab feature in vim and how to use it. Check it out..

  9. Actually, if you just “:set hidden” you can change buffers without saving first. There’s no need to use one buffer per tabpage.

  10. Thank you (and everyone else who posted, too).

  11. 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!

  12. Nick Garwood Says:

    Such a useful tool. Is there a way, when in edit mode, to create a new tab with another file?

Leave a Reply