OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

Switching Between Files

To switch from one file to the next, use this ex command:



:n

:n


To move back to the previous file use:



:N

:N


While we can move from one file to another, vi enforces a policy that prevents us from switching files if the current file has unsaved changes. To force vi to switch files and abandon your changes, add an exclamation point (!) to the command.

In addition to the switching method described above, vim (and some versions of vi) also provide some ex commands that make multiple files easier to manage. We can view a list of files being edited with the :buffers command. Doing so will display a list of the files at the bottom of the display:


:buffers

1 %a "foo.txt"

2 "ls-output.txt"

line 1

line 0

:buffers

1 %a "foo.txt"

2 "ls-output.txt"


Press ENTER or type command to continue

Press ENTER or type command to continue


image

To switch to another buffer (file), type :buffer followed by the number of the buffer you wish to edit. For example, to switch from buffer 1 which contains the file foo.txt to buffer 2 containing the file ls-output.txt we would type this:


:buffer 2

:buffer 2


and our screen now displays the second file.


Top OS Cloud Computing at OnWorks: