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:

1
vim vim_file vim_file2
img

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:

1
:next
img

Switch to the next file

After executing the next command:

img

After switching to the next file

Quit All Opened Files

1
:qa
img

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:

1
:q
img

Quit file without saving the change

Moving Cursor to Line N

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

1
:6    # This will move cursor to line 6
img

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:

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

Delete the seventh line and move the cursor over

Replacement

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
:1,3s/dolor/dooooloooor/gi    # This replaces all the matched content from line one to line three
img

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:

1
:set number
img

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:

1
2
/ma    # Search for ma first
:set ignorecase
img

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:

1
:set nohlsearch
img

Won't highlight the matched content

References VIM Documentation

Buy me a coffeeBuy me a coffee