Published in


Vim Editor in Linux & Commands

Vim is a free and open-source, screen-based text editor program for Unix. It is an advanced highly configured text editor built to enable efficient text editing. Vim text editor is developed by Bram Moolenaar. It supports most file types and the vim editor is also known as a programmer’s editor.

Installation of Vim in Linux System

To install vim on Linux like Ubuntu run this command:

sudo apt-get install vim

To install vim on an arch-based distro run this command:

sudo pacman -S vim

You can open the vim terminal by this command:


You can see all commands, and their documentation by help use the following commands :


Exit from the terminal type this command:


To open a file in vim use this command:

vim filename.txt

then the file will open.

For writing into the file:


Changing mode from one to another :

  • Text Entry Commands :
a - Append text in following the current cursor positionA - Append text to the end of current linei - Insert text before the current cursor positionI - Insert text at the beginning of the cursor lineo - Open up a new line following the current line and add text thereO - Open up a new line in front of the current line and add text                  there

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

  • Cursor movement :
h - move cursor leftj - move cursor downk - move cursor upl - move cursor rightH - move to top of screenM - move to the middle of screenL - move to bottom of screenw - jump forwards to the start of a wordW - jump forwards to the start of a word (words can contain punctuation)e - jump forwards to the end of a wordE - jump forwards to the end of a word (words can contain punctuation)b - jump backwards to the start of a wordB - jump backwards to the start of a word (words can contain punctuation)ge - jump backwards to the end of a wordgE - jump backwards to the end of a word (words can contain punctuation)0 - jump to the start of the line^ - jump to the first non-blank character of the line$ - jump to the end of the lineg_ - jump to the last non-blank character of the linegg - go to the first line of the documentG - go to the last line of the document5gg or 5G - go to line 5gd - move to the local declarationgD - move to global declarationtx - jump to before next occurrence of character x
  • Exiting commands in Vim:
:q - To exit without doing anything:q! - To exit without saving  changes:wq - To exit with saving changes
  • Text Deletion Commands:
dd — delete (cut) a line2dd — delete (cut) 2 linesdw — delete (cut) the characters of the word from the cursor position to the start of the next worddiw — delete (cut) word under the cursordaw — delete (cut) word under the cursor and the space after or before itD — delete (cut) to the end of the lined$ — delete (cut) to the end of the linex — delete (cut) character
  • Yank has most of the options of delete:
yy - yank current liney$ - yank to end of current line from cursoryw - yank from cursor to end of current word5yy - yank, for example, 5 lines
  • The paste used after delete or yank to recover lines:
p - paste below cursorP - paste above cursor"2p - paste from buffer 2 (there are 9)u - Undo last changeU - Restore lineJ - Join next line down to the end of the current line

Delete all the lines in vim:

Esc + gg + dG
  • File Manipulation Commands
:w - Write workspace to original file:W - file Write workspace to named file:e - file Start editing a new file:r - file Read contents of a file to the workspace


:/word - To search the word After the cursor uses the backslash key and then write the word and press enter.:n - Use n to move on next matching word:N -Use N to move on previous matching word

Search and Replace:

:s/searchword/replaceword/ - To replace the word in file use s/ command in vim like:s/searchword/replaceword/g - To do replace all occurrence of word use g




Microprediction/Analytics for Everyone! We help volunteers to do analytics/prediction on any data!

Recommended from Medium

Evolution of Promotion Search at Trendyol

“Keep It Simple, Stupid” Give some KISS to your code.

#10 Floating Windows on Android: Tips & Tricks

Hardware issues and a new laptop

Permission manager : RBAC management for Kubernetes


How a church uses reports to improve services and offer support

Floating action button with badge counter

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


More from Medium

Every Linux user should know these commands

Git warning: LF will be replaced by CRLF

Ingesting and processing multiple lines in Linux using an array and loops.

Install Ubuntu inside Windows -WSL2