It is true that learning Vi/Vim – a well-known text editor in the Linux ecosystem, is not as easy as learning Nano or Emacs, as it requires a little effort which is worthwhile.
Many people are afraid of learning it, but seriously, for no important reasons. In this short article, intended for Vi/Vim text editor newbies, we’ll learn a few basic commands; how to save a file after writing or modifying its content.
Step 2: Make and save modifications in Vim. Reopen the file by typing vim HelloWorld.java and pressing the Enter key. Insert mode is where you can make changes to a file. First, hit Esc to make sure you are in Normal mode, then press i to go into Insert mode. (Yes, that is the letter i.) In the lower-left, you should see - INSERT -. Another way to open a file is to start the editor and type:e filename, where filename is the name of the file you want to open. Save a File in Vim / Vi # The command to save a file in Vim is:w. To save the file without exiting the editor, switch back to normal mode by pressing Esc, type:w and hit Enter.
Suggested Read:10 Reasons Why You Should Use Vi/Vim Text Editor in Linux
In most of the today’s Linux distributions, Vi/Vim editor comes with pre-installed, if not install the full version of Vim (Debian systems provide vim-tiny with less features), simply run this command:
Note: To use it’s latest features, install Vim 8.0.
Save In Vim Mac Os
To open or create a file using Vim, run the following command, then press i
to insert text into it (insert mode):
Once you have modified a file, press [Esc]
shift to the command mode and press :w
and hit [Enter]
as shown below.
Vim Save Macro In .vimrc
To save the file and exit at the same time, you can use the ESC
and :x
key and hit [Enter]
. Optionally, press [Esc]
and type Shift + Z Z
to save and exit the file.
Vim Mac Os
To save the file content to a new file named newname, use :w newname
or :x newname
and hit [Enter]
.
Save Vim Macro
From here, you can now move over to learn common Vi/Vim tips and tricks, understand the different modes and so much more:
That’s it! In an upcoming article, we’ll show you how to exit Vim text editor with simple commands. Remember to drop your comments via the feedback form below.