By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
IT Infras HolicIT Infras HolicIT Infras Holic
  • News
  • Linux
    • Application
    • SELinux
    • Centos
    • Ubuntu
  • Docker
  • Web Server
    • Kong
    • Nginx
    • Openlitespeed
  • Database
  • Mikrotik
  • Windows
  • Mail
  • Tools
    • 2048
    • Fantasy Forest
    • Hextris
    • Crossword
Search
  • Privacy Policy
© 2024. All Rights Reserved.
Font ResizerAa
IT Infras HolicIT Infras Holic
Font ResizerAa
  • News
  • Linux
  • Docker
  • Web Server
  • Database
  • Mikrotik
  • Windows
  • Mail
  • Tools
Search
  • News
  • Linux
    • Application
    • SELinux
    • Centos
    • Ubuntu
  • Docker
  • Web Server
    • Kong
    • Nginx
    • Openlitespeed
  • Database
  • Mikrotik
  • Windows
  • Mail
  • Tools
    • 2048
    • Fantasy Forest
    • Hextris
    • Crossword
Follow US
© 2022 Foxiz News Network. Ruby Design Company. All Rights Reserved.
IT Infras Holic > Blog > Linux > Vim Cheat Sheet
Linux

Vim Cheat Sheet

writer
Share
6 Min Read
SHARE

Vim Cheat Sheet

The Vim editor is a command-line based tool that’s an enhanced version of the venerable vi editor. Despite the abundance of graphical rich text editors, familiarity with Vim will help every Linux user – from an experienced system administrator to a newbie Raspberry Pi user.

Contents
Vim Cheat SheetMainNavigation keys (Vim Cheat Sheet)Navigate around the documentInsert text (Vim Cheat Sheet)Special insertsDelete text (Vim Cheat Sheet)Simple replace text (Vim Cheat Sheet)Copy/Paste text (Vim Cheat Sheet)Undo/Redo operation (Vim Cheat Sheet)Search and Replace keysBookmarksSelect textModify selected textSave and quit

One important thing to note when using Vim, is that the function of a key depends on the “mode” the editor is in. For example, pressing the alphabet “j” will move the cursor down one line in the “command mode”. You’ll have to switch to the “insert mode” to make the keys input the character they represent.

Vim Cheat Sheet

Shortcut Keys Function

Main

Escape key Gets out of the current mode into the “command mode”. All keys are bound of commands.
i “Insert mode” for inserting text. Keys behave as expected.
: “Last-line mode” where Vim expects you to enter a command such as to save the document.

Navigation keys (Vim Cheat Sheet)

h moves the cursor one character to the left.
j or Ctrl + J moves the cursor down one line.
k or Ctrl + P moves the cursor up one line.
l moves the cursor one character to the right.
0 moves the cursor to the beginning of the line.
$ moves the cursor to the end of the line.
^ moves the cursor to the first non-empty character of the line
w move forward one word (next alphanumeric word)
W move forward one word (delimited by a white space)
5w move forward five words
b move backward one word (previous alphanumeric word)
B move backward one word (delimited by a white space)
5b move backward five words
G move to the end of the file
gg move to the beginning of the file.

Navigate around the document

( jumps to the previous sentence
) jumps to the next sentence
{ jumps to the previous paragraph
} jumps to the next paragraph
[[ jumps to the previous section
]] jumps to the next section
[] jump to the end of the previous section
][ jump to the end of the next section

Insert text (Vim Cheat Sheet)

a Insert text after the cursor
A Insert text at the end of the line
i Insert text before the cursor
o Begin a new line below the cursor
O Begin a new line above the cursor

Special inserts

:r [filename] Insert the file [filename] below the cursor
:r ![command] Execute [command] and insert its output below the cursor

Delete text (Vim Cheat Sheet)

x delete character at cursor
dw delete a word.
d0 delete to the beginning of a line.
d$ delete to the end of a line.
d) delete to the end of sentence.
dgg delete to the beginning of the file.
dG delete to the end of the file.
dd delete line
3dd delete three lines

Simple replace text (Vim Cheat Sheet)

r{text} Replace the character under the cursor with {text}
R Replace characters instead of inserting them

Copy/Paste text (Vim Cheat Sheet)

yy copy current line into storage buffer
[“x]yy Copy the current lines into register x
p paste storage buffer after current line
P paste storage buffer before current line
[“x]p paste from register x after current line
[“x]P paste from register x before current line

Undo/Redo operation (Vim Cheat Sheet)

u undo the last operation.
Ctrl+r redo the last undo.

Search and Replace keys

/search_text search document for search_text going forward
?search_text search document for search_text going backward
n move to the next instance of the result from the search
N move to the previous instance of the result
:%s/original/replacement Search for the first occurrence of the string “original” and replace it with “replacement”
:%s/original/replacement/g Search and replace all occurrences of the string “original” with “replacement”
:%s/original/replacement/gc Search for all occurrences of the string “original” but ask for confirmation before replacing them with “replacement”

Bookmarks

m {a-z A-Z} Set bookmark {a-z A-Z} at the current cursor position
:marks List all bookmarks
`{a-z A-Z} Jumps to the bookmark {a-z A-Z}

Select text

v Enter visual mode per character
V Enter visual mode per line
Esc Exit visual mode

Modify selected text

~ Switch case
d delete a word.
c change
y yank
> shift right
< shift left
! filter through an external command

Save and quit

:q Quits Vim but fails when file has been changed
:w Save the file
:w new_name Save the file with the new_name filename
:wq Save the file and quit Vim.
:q! Quit Vim without saving the changes to the file.
ZZ Write file, if modified, and quit Vim
ZQ Same as :q! Quits Vim without writing changes

That's the shortcut you can learn on Vim. So Let's memorize all the Vim Keyboard Shortcut !!

You Might Also Like

Monitoring File & Directory Changes using Bash Script

Vulnerability Checker CVE-2024-3094

Unleashing the Potential of Knowledge Management with Wiki.js

How to Install Apache Guacamole with Docker Compose

Unlocking Seamless Remote Access: Exploring the Power of Apache Guacamole

TAGGED: cheat sheet, vi, vim
Share This Article
Facebook Twitter Whatsapp Whatsapp LinkedIn Telegram Copy Link
Previous Article firewalld cheat sheet Firewalld Cheat Sheet
Next Article Semanage Command Not Found Semanage Command Not Found in CentOS 7
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Latest News

bash
Monitoring File & Directory Changes using Bash Script
Linux Application
vulnerability
Vulnerability Checker CVE-2024-3094
Linux
wiki.js
Unleashing the Potential of Knowledge Management with Wiki.js
Application Linux
Install Apache Guacamole
How to Install Apache Guacamole with Docker Compose
Application Linux

You Might also Like

How to Install Cyberpanel on Ubuntu 22.04
OpenlitespeedUbuntuWeb Server

Install Cyberpanel on Ubuntu 22.04

8 Min Read
How to map SFTP as a drive on Windows 10
LinuxWindows

How to map SFTP as a drive on Windows 10

3 Min Read
Follow US
© 2024
activity notes activity notes
Welcome Back!

Sign in to your account

Lost your password?