Vim Flex: Power Moves

part 1

Dejanu Alex
3 min readJan 18, 2024

When it comes to text editing, Vim is capable of unlocking the most efficient way to edit text.

Vi IMproved as the name suggests is an extended and enhanced version of Vi, and a configurable task-centric open-source text editor.

Without further ado…

Open a file by specifying the name of the file e.g. vim file_name.txt (if file_name.txt does not exist it will be created), alternatively, in a terminal, you can type vim to launch it.

By default, Vim will start in normal mode (used to perform commands e.g. copy, delete, or indent text).

Normal mode 101

You can navigate (move the cursor) using the following keys:

h   move one character left
j move one row down
k move one row up
l move one character right

To quickly go through the file:

  • Press ESC key and at the prompt the following command :set nu in order to display the line numbers in the left margin.
  • Press G to move to the last line of the file.
  • Press gg to move to the first line of the file.
  • Let’s say you want to move to the line 21 , simply just type 21gg to get there.
  • Press $ to move to the end of the line.
  • Press 0 to move to the beginning of the line.
Navigate

To enter in insert mode from normal mode just press i , now the text you type will be inserted.

Insert mode 101

Alternatively to have more control when you insert text:

  • Press I to insert at the START of the line.
  • Press A to insert after the END of the line.
  • Press S to delete the line and start inserting in place of it (SUBSTITUTE line) or alternatively cc (CHANGE line)
  • Type cw (CHANGE WORD) to delete from the cursor to the end of the word or ciw (CHANGE INSIDE WORD) to delete the entire word if the cursor is in the middle of the word.
Inserting

Searching 101

If you want to search, go to normal mode and:

  • Search forward using the forward slash /
  • Search backward using the question mark ?
  • Once you’ve established the search direction, search for hits using n (next) e.g. search for the word editor .
  • Press ESC key and at the prompt the following command :set hlsearchin order to have highlighted matches.

Last but not least, you can customize Vim settings using vimrc file (on Unix-based systems, the file is named .vimrc, while on Windows systems it is named _vimrc ), e.g. to show the line number or text wrapping by default or just add:

" Show line numbers:
set number

" Always wrap long lines:
set wrap

If you’re unsure about vimrc location use vim --version to find out:

This bearly scratches the surface…but hopefully, these small tips should get you started delving into the more advanced features of Vim.

--

--

Dejanu Alex
Dejanu Alex

Written by Dejanu Alex

Seasoned DevOps engineer — Jack of all trades master of None

No responses yet