Through the last line mode of vim, we can easily execute some commands, such as switching between files, saving files, moving the cursor, deleting and replacing text and so on.

Switching Between Opened Files

Here are some file switching commands in last line mode:

Option Meaning
:prev Switch to the previous file.
:next Switch to the next file.
:first Switch to the first file.
:last Switch to the last file.
:qa Quit all opened files.

Let’s open the previously created two files at the same time:

vim vim_file vim_file2

Open two files at the same time

Switch to the Next File

With the :prev command, we can switch to the next file’s window:


Switch to the next file

After executing the next command:


After switching to the next file

Quit All Opened Files


Quit all opened files

Save and Quit

Here are some quit and save commands in last line mode:

Option Meaning
:q Quit only.
:q! Forced quit.
:w Save only.
:w! Forced save.
:wq Save and quit, this is equivalent to :x.

Quit Opened File

We can use the :q command to exit the file directly:


Quit file without saving the change

Moving Cursor to Line N

We can move the cursor to the N line by :N command:

:6    # This will move cursor to line 6

Move cursor to line 6

Delete Lines

Here are some delete commands in last line mode:

Option Meaning
:. Delete current line.
:$ Delete last line.
:+N Delete next N lines.
:$-N Delete last N lines.
:N Delete line N.
:N1,N2d Delete from line N1 to line N2.

Let’s delete the seventh row and move the cursor to the deleted row:

:7d    # This will remove the seventh line and move the cursor to deleted line

Delete the seventh line and move the cursor over


Here are two options at the end of the command:

Option Meaning
g Replace all matching content,ot just the first matched content of each row.
i Ignore case-sensitivity.

Let’s replace dolor with dooooloooor:

:1,3s/dolor/dooooloooor/gi    # This replaces all the matched content from line one to line three

Replace dolor with dooooloooor from line one to line three

Show Line Numbers

Here are some line number related commands:

Option Meaning
:set number Show line numbers, this is equivalent to :set nu
:setnonu Hide line numbers.

Let’s show the line numbers:

:set number

Show line numbers

Searching Case Sensitivity

Here are some case sensitivity related commands:

Option Meaning
:set ignorecase Case sensitive when searching for content, this is equivalent to :set ic
:set noic Case insensitive when searching for content.

Let’s turn off case sensitivity:

/ma    # Search for ma first
:set ignorecase

Searching both upper and lower case content

Turn On or Off the Highlight Search

Here are some highlighting related commands:

Option Meaning
:set hlsearch Highlight the matched content.
:set nohlsearch Don’t highlight the matched content.

Let’s turn off the highlight:

:set nohlsearch

Won't highlight the matched content

References VIM Documentation

Buy me a coffeeBuy me a coffee