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?
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.
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.
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' .
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 .
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With