Spending 8 Hours a Day on the Keyboard? This Article is for You.

In this article, I will discuss the minimum commands that I use daily.

What is Vim

Vim is a program, a text file editor. In almost all Linux distributions, vi is installed (“vim” - “VI iMproved”). It has several modes: “text input”, “editing”, “navigation”, and “text selection”.

Spoiler - How to Exit vi(m)?

:wq - save and exit
:q - exit


Hotkeys

Hotkeys are key combinations. In vi, each separate key can be combined with another, forming a combo of actions. For example, 7dt, - delete (d) 7 times until (t) a comma (,). They are pressed sequentially, not simultaneously.

To enter navigation mode from any mode - esc.

On opening vi, you are greeted by a thick cursor, as if insert mode is activated - command mode and text navigation. At the same time, if you use the 10-finger typing method, your fingers automatically lie on the main navigation keys:

h,j,k,l - left, right, up, down

hjkl

Combined with ctrl:

ctrl+u - scroll up a screenful
ctrl+d - scroll down a screenful

Word navigation:

w - to the beginning of the next word
b - to the beginning of the previous word

wb

Navigation with search:

f+any_character - find, moves the cursor to the first found character in the current line

f0

Command Input Field

shift+: - opens the command input field

In this field, you can, for example, perform a full-text search and replace throughout the document:

%s:regex_to_find:replacement_text - search for regex_to_find and replace with replacement_text, the : delimiter can be any character of your choice

vim_rename

Jump to any line by number:

123 - line number, press enter and the cursor moves to line 123

320_317

It’s convenient when you need to quickly jump to the beginning shift+:,1,enter - moves the cursor to the start

Insert Mode

Enter text input mode with the key:

i - insert, enter text input mode
a - after, place the cursor after the current character and enter text input mode

Commands with shift:

A - put the cursor at the end of the line and enter text input mode

vim_A

Editing Text

d - delete, used in combination with other commands for deletion:

dd - delete the entire line under the cursor

vim_dd

dw - delete to the end of the word under the cursor

vim_dw

db - delete to the beginning of the word under the cursor

vim_db

dt,symbol_to_delete_until - deletes everything until the specified character within the line

df,symbol_to_delete_until - deletes everything to the character, including the character itself

vim_df

x - cuts the current character and places it in memory

vim_x

p - paste, inserts what was in memory at the current cursor position or replaces selected text

with shift:

D - delete to the end of the current line

vim_D combo:

di,bracket symbol { or [ or ( - delete inside the brackets, the cursor must be inside the expression in the brackets

vim_di

Text Selection

v - enter text selection mode

vim_v

After entering selection mode, you can move the cursor to expand the selection area. With shift:

V - enter line-by-line text selection mode

vim_V

C ctrl:

ctrl+v - enter selection mode with arbitrary cursor movement. The cursor can be moved vertically, and the selected block will be a rectangle where one corner is the start of the selection, and the opposite one is where the cursor will be placed

vim_ctrl_v

Commands to modify text can be performed on the selected area.

Selection can be made with combinations:

vi,bracket symbol { or [ or ( - v makes a selection, i indicates that the selection should be made inside the brackets

vim_vi