Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to effectively work with multiple files in Vim

Tags:

vim

vi

I've started using Vim to develop Perl scripts and am starting to find it very powerful.

One thing I like is to be able to open multiple files at once with:

vi main.pl maintenance.pl 

and then hop between them with:

:n :prev 

and see which file are open with:

:args 

And to add a file, I can say:

:n test.pl 

which I expect would then be added to my list of files, but instead it wipes out my current file list and when I type :args I only have test.pl open.

So how can I add and remove files in my args list?

like image 376
Edward Tanguay Avatar asked Sep 10 '08 09:09

Edward Tanguay


People also ask

How do I navigate multiple files in Vim?

Using windows. Ctrl-W w to switch between open windows, and Ctrl-W h (or j or k or l ) to navigate through open windows. Ctrl-W c to close the current window, and Ctrl-W o to close all windows except the current one. Starting vim with a -o or -O flag opens each file in its own split.

Can you open multiple files in Vim?

Opening Multiple Files in VimYou can open multiple files at the start of the Vim editing session from the command line, or at any time from inside the Vim editing session.

How do I open multiple files in Vim vertically?

Suppose you have opened a file on Vim editor and you want to split it vertically. To achieve this: Enter command mode by pressing the ESC button. Press the keyboard combination Ctrl + w , followed by the letter 'v' .

How do I go to the next file in Gvim?

After starting vim with a list of files, you can move to the next file by entering :next or :n for short. :wnext is short for write current changes and then move to next file; :wn is an abbreviation for :wnext .


1 Answers

Why not use tabs (introduced in Vim 7)? You can switch between tabs with :tabn and :tabp, With :tabe <filepath> you can add a new tab; and with a regular :q or :wq you close a tab. If you map :tabn and :tabp to your F7/F8 keys you can easily switch between files.

If there are not that many files or you don't have Vim 7 you can also split your screen in multiple files: :sp <filepath>. Then you can switch between splitscreens with Ctrl+W and then an arrow key in the direction you want to move (or instead of arrow keys, w for next and W for previous splitscreen)

like image 101
fijter Avatar answered Oct 04 '22 00:10

fijter