How to switch between multiple files in UNIX while using VI editor?
I'm new to UNIX. I am using VI editor to code for C programming. If I open multiple files at a time using VI editor like,
I can edit the first file only. If I press ":wq", it shows me that there are: "6 more files to edit"
How can I switch between those files?
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.
For Linux Red-Hat VI version 7.2.411 use :n and :N to switch next and previous.
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.
:e# where # is the file number
:b# is working in vi editor to open particular file, when multiple files are opened, # means numbers here