vim filenamewhere filename is the name of an existing file.
vim newfilewhere newfile is the name of the file you would like to create.
An ad-free and cookie-free website.
A tutorial on the beginning operations of the Vim text editor.
If you prefer, this topic is also covered a video.
Videos can be accessed from our Vim Reference Playlist on YouTube.
Open Vim - Four ways to open vim plus man vim and vim options (7:20)
For many functions, as in this case, the Vim editor and the Vi editor behave the same. What makes these editors unique is the concept of modes which makes it fast once you gain a comfort level but can be difficult for the beginner who is eager to learn how to code.
If you are accustomed to other text editors or word processors this will be foreign to you. You will also notice the lack of a menu system. So yes, this will be different from what you're used to but you will eventually be faster and save money because Vim is a free editor.
Also note, when you open Vim you will enter Normal Mode
by default and will not be able to edit the file until you enter
Insert Mode using one of several characters, with
i being the most common.
In our first case, we will open the editor with an existing file, as shown here using Linux.
This opens what is called a buffer and goes right to Normal Mode.
The tilde characters
~ are like
placeholders, meaning they are blank and non-existent lines. If you
don't see line numbering on your system, this is because it is not a
default factory setting and is covered elswhere.
At the bottom
"filename" refers to
2L, 85C means 2 lines and
1,1 refers to the
position of the cursor and
the position in the file.
In the second case we will open Vim and a new file at the same time from the command line.
Below is what the empty file looks like.
Once you enter Insert Mode and start editing, the
information at the bottom left will disappear and
be replaced with
-- INSERT --.
In the third example we will open Vim from the command line without a filename.
Here is what the standard opening screen looks like.
Once you enter Insert Mode the welcome screen will disappear and you will be editing a new unnamed file.
In the fourth example, we can open a file from within Vim using
Command Mode by entering
It is worth taking a few minutes to review the user manual, included
with the free editor, often called a man page to see
other options that can be used when starting
vim from the command line.
The top of the file looks like this.
Linux documentation using
standardized and many of the same sections exist for the thousands of
commands, or programs, that run on the system. Among those are:
DESCRIPTION and OPTIONS.
The SYNOPSIS section describes different ways you can
launch programs from the command line. In the first row, you see
vim [options] [file ..]. Let's
translate this. What is inside the brackets is optional, so entering
vim as we did in example 3 above is
perfectly valid. The
[file ..] means
that optionally you can enter a filename, either existing (example 1
above) or a new file name (example 2 above). Also the
.. inside the brackets means you can
open Vim with multiple files.
Options refer to special tags that are normally preceded by a dash that allow you to change a configuration for that session. Let's look at the OPTIONS section. There are over 60 options available which is a lot, even for Linux command standards, so below is a subset of 6 that are commonly used by intermediate-level users of Vim.
So instead of skipping options altogether as we did above, you could add one or several options that take effect during that session.
This would open the file from example 1 above at line 2.
Using the following code at the command line would open that file from above, except use functionality similar to the Vi editor, which is a precursor to Vim.
Multiple options can be used at once, so this would open the same file at line 2 and open in read-only mode.
And finally, to see a shortened summary of
man to refresh your memory, you could
-h or alternatively
--version option shows the
version number, as it does with many other commands in Linux.
Q: How can you tell which mode you are in?
A: With the default settings, the mode is at the bottom left of the screen.
Our YouTube Channel is growing. Subscribe and follow so you don't miss new content.
No write since last change (Add ! to override)or would like to learn how to quit Vim, click Next.
A newly-updated free resource. Connect and refer a friend today.