How to switch between multiple files in UNIX while using VI editor?
Next file: :n
Previous file: :p
, :N
or :prev
depending on which vi implementation you're using.
Here's a typical cheat sheet which has a section "Files" on this topic.
AIX's vi has it's own commands; it took me a while to find this information because the answers in this question didn't have it already, so I'll add this answer.
Neither :p
, :N
, nor :prev
work to go to the previous file, you need to use one of the variations of the :n ---
command.
The :n
for moving to the next file is the same
Use :n file_name
to move to a certain file (Can open new files this way too) (To go to the previous file, just do this with the previous file's name
Use :n list of file names
to define a new list of files to edit (In this case, the files list
, of
, file
, and names
would be opened in series using :n
after running :n list of file names
Other useful results from the man pages
:e File Edits the specified file. If you are using this subcommand from the ex editor, you do not need to type the : (colon). :e! Re-edits the current file and discards all changes. :e + File Edits the specified file starting at the end. :e + Number File Edits the specified file starting at the specified line number. :e # Edits the alternate file. The alternate file is usually the previous file name before accessing another file with a :e command. However, if changes are pending on the current file when a new file is called, the new file becomes the alternate file. This subcommand is the same as the Ctrl-A subcommand. Ctrl-G Shows the current file name, current line number, number of lines in the file, and percentage of the way through the file where the cursor is located.