FactorPad
Build a Better Process

Learn Four Ways to Open Vim and Start Editing Faster

To learn how to code you need a fast text editor like Vim. Here are four ways to open Vim and get started.
  1. For an existing file - type vim filename where filename is the name of an existing file.
  2. For a non-existing file - type vim newfile where newfile is the name of the file you would like to create.
  3. Open Vim without a file - type vim.
  4. Open a file from within Vim - use Command Mode with :e filename.
face pic by Paul Alan Davis, CFA
Updated: February 25, 2021
That's the fast answer. To learn more about modes and the vim man page see the examples below.

Outline Back Tip Next

/ factorpad.com / tech / vim / reference / open-vim.html


An ad-free and cookie-free website.


Open a File and Start with Vim to Learn How to Code Faster

A tutorial on the beginning operations of the Vim text editor.

Video Tutorial

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)

Video Script

Beginner

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.

Note: Follow along on your system to learn faster

Example 1 - Open Vim with an Existing File

In our first case, we will open the editor with an existing file, as shown here using Linux.

$ vim filename

This opens what is called a buffer and goes right to Normal Mode.

1 This is a two-line text file used for several illustrations 2 and saved as "filename". ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ "filename" 2L, 85C 1,1 All

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 the file, 2L, 85C means 2 lines and 85 characters, 1,1 refers to the position of the cursor and All is the position in the file.

Example 2 - Open and Create a New File

In the second case we will open Vim and a new file at the same time from the command line.

$ vim newfile

Below is what the empty file looks like.

1 _ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ "newfile" [New File] 0,0-1 All

Once you enter Insert Mode and start editing, the information at the bottom left will disappear and be replaced with -- INSERT --.

Example 3 - Open and Create a New File

In the third example we will open Vim from the command line without a filename.

$ vim

Here is what the standard opening screen looks like.

1 _ ~ ~ ~ ~ VIM - Vi IMproved ~ ~ Version 7.4.576 ~ by Bram Moolenaar et al. ~ Modified by pkg-vim-maintainers@lists.alioth.debian.org ~ Vim is open source and freely distributable ~ ~ Help poor children in Uganda! ~ type :help iccf<Enter> for information ~ ~ type :q<Enter> to exit ~ type :help<Enter> or <F1> for on-line help ~ type :help version7<Enter> for version info ~ ~ 0,0-1 All

Once you enter Insert Mode the welcome screen will disappear and you will be editing a new unnamed file.

Example 4 - Open a File From Within Vim

In the fourth example, we can open a file from within Vim using Command Mode by entering :e filename.

For Those Seeking More Knowledge

Intermediate

The Vim Man Page - Name, Synopsis and Description

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.

$ man vim

The top of the file looks like this.

VIM(1) General Commands Manual VIM(1) NAME vim - Vi IMproved, a programmers text editor SYNOPSIS vim [options] [file ..] vim [options] - vim [options] -t tag vim [options] -q [errorfile] ex view gvim gview evim eview rvim rview rgvim rgview DESCRIPTION Vim is a text editor that is upwards compatible to Vi. It can be used to edit all kinds of plain text. It is especially useful for editing programs. There are a lot of enhancements above Vi: multi level undo, multi windows and buffers, syntax highlighting, command line editing, filename completion, on-line help, visual selection, etc.. See ":help vi_diff.txt" for a summary of the differences between Vim and Vi. While running Vim a lot of help can be obtained from the on-line help system, with the ":help" command. See the ON-LINE HELP section below. Most often Vim is started to edit a single file with the command vim file More generally Vim is started with: vim [options] [filelist] If the filelist is missing, the editor will start with an empty buffer. Otherwise exactly one out of the following four may be used to choose one or more files to be edited.

Linux documentation using man is standardized and many of the same sections exist for the thousands of commands, or programs, that run on the system. Among those are: NAME, SYNOPSIS, 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 and Arguments

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.

OPTIONS The options may be given in any order, before or after filenames. Options without an argument can be combined after a single dash. +[num] For the first file the cursor will be positioned on line "num". If "num" is missing, the cursor will be positioned on the last line. -C Compatible. Set the 'compatible' option. This will make Vim behave mostly like Vi, even though a .vimrc file exists. -R Read-only mode. The 'readonly' option will be set. You can still edit the buffer, but will be prevented from accidently overwriting a file. If you do want to overwrite a file, add an exclamation mark to the Ex command, as in ":w!". The -R option also implies the -n option (see below). The 'readonly' option can be reset with ":set noro". See ":help 'readonly'". -h Give a bit of help about the command line arguments and options. After this Vim exits. --help Give a help message and exit, just like "-h". --version Print version information and exit.

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.

$ vim +2 filename

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.

$ vim -C filename

Multiple options can be used at once, so this would open the same file at line 2 and open in read-only mode.

$ vim +2 -R filename

And finally, to see a shortened summary of man to refresh your memory, you could use either -h or alternatively --help.

$ vim -h

The --version option shows the version number, as it does with many other commands in Linux.


Vim Questions and Answers

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.


Related Vim Commands and Procedures


What's Next?

Our YouTube Channel is growing. Subscribe and follow so you don't miss new content.

Outline Back Tip Next

/ factorpad.com / tech / vim / reference / open-vim.html


open vim
learn how to code
vim open file
vim editor
learn vim
start vim
vim examples
free editor
vim examples
vim options
vim new file
man vim
open file within vim
vim buffers
vim open at line number

A newly-updated free resource. Connect and refer a friend today.