54. Advanced Text Editor - Vim's Last Line Mode
Contents
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:
|
|
Switch to the Next File
With the :prev command, we can switch to the next file’s window:
|
|
After executing the next command:
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:
|
|
Moving Cursor to Line N
We can move the cursor to the N line by :N command:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
References VIM Documentation
Author Dong Chen
LastMod Tue Mar 26 2019