Can I open two or more files in vim at once?
I have a file with the name First.txt, which I opened that by vim. Now I want to go another file which its name is Second.txt .
How to open Second.txt while I do not close First.txt.
How to switch between them First.txt and Second.txt on the vim?
Solution 1:
You can open a different file in vim with the :o
command, like so:
:o /file/To/Open
This closes your current file and opens /file/To/Open
.
As of vim 7.0 you can use the tabs feature to open multiple files at once. Use vim's :tabnew
command to open a new tab:
:tabnew [filename]
Where [filename]
is an optional file to open in the new tab.
To switch between tabs use any of the following commands:
-
:tabn
- switches to the next tab. -
:tabp
- switches to the previous tab. -
gt
- toggles through all tabs, from left to right. -
gT
- similar togt
but in opposite direction. -
:tabfirst
- switches to the first tab. -
:tablast
- switches to the last tab.
You can also pass multiple files to vim and have it open them in different tabs like so:
vim -p file1 file2 etc
To close a tab, use the :tabclose
command.
For more tab related info see Vim tips: using tabs on Linux.com.