Hion Coding - Blogs share everything
  • HOME
  • ABOUT
  • POSTS
  • CONTACT
  • TOOLS
    CÂU HỎI VÕ ĐÀI TỐI THƯỢNG CONVERT IMAGE TO WEBP
Basic Vim commands - For getting started

Basic Vim commands - For getting started

Hion Coding - Blogs share everything
Admin Hion Coding Blogs vochilong.work@gmail.com
3rd January 2024

Linux

Basic Vim commands - For getting started

Refer: Basic Vim commands - For getting started

Preamble
I remember the first time I met Vim. That was when I started graduating and going to work when I was asked to use an operating system that I had never used before, Ubuntu Linux. This was the first time I needed to use the Linux operating system regularly, so when I was using Windows and switched to Ubuntu, I was no different from a first grader, overwhelmed.
Later, when working, I occasionally used it and saw people using Vim to edit files without a mouse and felt "wow... really skilled", which also made me more curious about it.

What is Vim?
Vim - short for Vi IMproved is a clone, with some additions, of Bill Joy's vi editor for Unix. It was written by Bram Moolenaar based on the source code of a port of the Stevie editor to the Amiga and first released in 1991. Vim is used very strongly in the CLI (command-line interface). Linux uses a lot of configuration files, you will often need to edit them and vim is a great tool to do that. Also alternatives to vim are nano's command-line editor.

Install Vim on Linux

sudo apt update
sudo apt-get install vim

 

Vim has two modes.

1. Insert mode (Where you can just type like a normal text editor. Press i for insert mode)

2. Command mode (Where you give commands to the editor to get things done . Press ESC for command mode)

Most of them below are in command mode

  • x - to delete the unwanted character
     
  • :set number - For show number file
     
  • :<LINE_NUMBER> - For goto number line file
     
  • :$ - For goto end-line file
     
  • :/<SEARCH_KEYWORD> - For search keyword
     
  • u - to undo the last command and U to undo the whole line
     
  • CTRL-R to redo
     
  • A - to append text at the end
     
  • :wq - to save and exit
     
  • :q! - to trash all changes
     
  • dw - move the cursor to the beginning of the word to delete that word
     
  • 2w - to move the cursor two words forward.
     
  • 3e - to move the cursor to the end of the third word forward.
     
  • 0 (zero) to move to the start of the line.
     
  • d2w - which deletes 2 words .. number can be changed for deleting the number of consecutive words like d3w
     
  • dd to delete the line and 2dd to delete to line. The number can be changed to delete the number of consecutive words

The format for a change command is: operator [number] motion
-operator - is what to do, such as d for delete
- [number] - is an optional count to repeat the motion
- motion - moves over the text to operate on, such as w (word),
$ (to the end of the line), etc.

  • p - puts the previously deleted text after the cursor(Type dd to delete the line and store it in a Vim register. and p to put the line)

  • r - to replace the letter e.g press re to replace the letter with e

  • ce - to change until the end of a word (place the cursor on the u in lubw it will delete ubw )

  • ce - deletes the word and places you in Insert mode

  • G - to move you to the bottom of the file.

  • gg - to move you to the start of the file.
    Type the number of the line you were on and then G

  • % to find a matching ),], or }

  • :s/old/new/g to substitute 'new' for 'old' where g is globally

  • :/<SEARCH_KEYWORD> search n to find the next occurrence and N to search in the opposite direction

  • ? forward search

  • :! to run the shell commands like :!dir, :!ls

  • :w - TEST (where TEST is the filename you chose.). Save the file

  • v - starts visual mode for selecting the lines and you can perform operations on that like d delete

  • :r - Filename will insert the content into the current file

  • R - to replace more than one character

  • y - operator to copy text using v visual mode and p to paste it

  • yw - (copy) Yanks one word

  • o - opens a line below the cursor and start Insert mode.

  • O - opens a line above the cursor.

  • a - inserts text after the cursor.

  • A - inserts text after the end of the line.

  • e - command moves to the end of a word.

  • y - operator yanks (copies) text, p puts (pastes) it.

  • R - enters Replace mode until <ESC> is pressed.

  • ctrl-w to jump from one window to another

type a command :e and press ctrl+D to list all the command names starts with :e and press tab to complete the command

Related protips:

Basic Vim commands - For getting started

Thank you !!! Good luck !!! Hion Coding ~~~
 


The list of articles is being updated!!!
Hion Coding - Blogs share everything


© 2025 Hion Coding DMCA.com Protection Status