Reserve the NVIDIA GH200 Grace Hopper™ Superchip at Vultr today.
Vim is one of the most powerful and popular Linux text editors accessible through a command-line interface. It is an improved version of the old Unix editor âviâ pre-installed on most Linux distributions.
Similar to other command-line-based text editors, it is easy to use and offers more functionality with standard features such as syntax highlighting, search, split editing, multi-level undo/redo, among others.
On Debian and Ubuntu, install Vim with
$ sudo apt install vim
yum on Redhat Enterprise Linux (RHEL) based systems like CentOS, Rocky Linux, Alma Linux.
$ sudo yum install vim
On OpenBSD, FreeBSD, install with
$ doas pkg_add vim
On Arch Linux, use
$ sudo pacman -S vim
Vim offers four modes of operation, the normal, insert, visual, and command-line modes, with different functions accessible with each.
In this mode, basic operations like copying, pasting, changing, and deleting text can be achieved.
Press ESC on your keyboard to enter normal mode.
This mode allows you to edit files, and insert new text in the editor. In this mode, every keyboard character you enter will be added to the file.
There are several ways to enter insert mode, and these are:
i - Enter insert mode.
I - Insert at the start of the current line
A - Insert at the end of the current line.
a - Insert below the current cursor position.
Visual selection, highlighting, manipulation of text, and all normal mode commands can be used in this mode.
To enter visual mode, use
v for basic cursor selections, then:
V â To enter visual line mode with an entire line selected.
Ctrl + v â Enter visual block mode with double text selection expandable to multiple lines.
This mode allows you to issue function commands using a colon
After the colon
:, add a command to execute any function in the editor. Below are some of the most common commands to manage files:
:q â quit Vim if no changes are made to the file.
:q! â quit Vim and discard any changes made to the file.
:w â Save changes.
:wq â Save and exit the file.
:bnâ Edit the next file.
:bp â Edit the previous file.
To open files, simply run
vim with the filename as an argument.
$ vim [file_name]
Also, you can open multiple files, and use
bp navigation commands to switch between files.
$ vim [file_name] [file_name] [file_name]
insert mode by pressing
i to edit the file and enter text.
Other editing functions can be performed in normal mode, such as deleting, copying, and pasting text with single or double-character commands.
y â copy text in a single direction
yy â copy the entire line of text
P â paste above the current line
p â paste below the current line
x â Delete a character
d â Delete a character to the next cursor direction
dd â Delete an entire line
DD â Delete an entire line and create empty space
u â Undo the previous operation
Ctrl + r â Redo the previous action
c â Change text in the next cursor direction, Vim will switch to insert mode, enter the replacement text
C â Replace text on an entire line and create empty space, Vim will switch to insert mode for new text.
r â Replace a character
J â Join the current line to the line below. This is important when replacing empty space
:split file_name â Horizontally split Vim with another filename
:vsplit file_name â Vertically split Vim with another filename
CTRL + ww â Switch between windows in split mode
Itâs possible to navigate in Vim using keyboard arrow keys, but with navigation commands available in normal mode, you can swiftly move the cursor around, and below are the common keys.
h â Move the cursor left.
l â Move the cursor right.
k â Move the cursor up.
j â Move the cursor down.
:[Number] â Move to the line number
0 â Switch to the start of the line.
$ â Switch to the last character on a line.
:$ â Jump to the last line in the file.
gg â Jump to the top of the file.
G â Jump to the bottom of the file.
w - Switch to the next word.
b - Jump back one word.
e - Switch to the end of a word.
:/SEARCH_TERM â Move to the text matching the search term
n â Move to the next match of the search term
You have successfully installed Vim on your cloud server. For further documentation, run
vimtutor in your server console for more powerful techniques on how to use the text editor.