Vim: Editing Multiple Files

Open a neovim or vim by typing vim or nvim on command prompt and it will show initial state with no file being edited.

Edit an existing file by typing :edit <path to file> then press enter. We can type partial path then press tab to show list to choose from.

Or edit a new file as you like.

Press enter and enter insert command to type in to buffer.

Press escape to return to normal mode.

Write to file by using :w then press enter.

Lets split the window, type :split then enter.

Move to other window by pressing Ctrl-w then w. Cursor will move to bottom window.

edit newfile2.txt on bottom window and save it.

lets close bottom window by typing :close then enter. This action will leave only the top window showing newfile1.txt. Close command will close active window, the one with the cursor.

Lets show vim buffer list. A windows showing a buffer of a file can be closed but the buffer still exist and can be called again to active window.

Type :ls then enter.

Lets choose to show newfile2.txt to the active window.

Type :b 2 then enter.

Or type partial name and use tab to autocomplete.

After command done, active window will show the content of newfile2.txt.

That’s all about splitting window, buffer list and switching buffer.


Leave a Reply

Your email address will not be published. Required fields are marked *