VIM Cheat Sheet

By | August 25, 2019

This post may contain affiliate links. Please read my disclosure for more info.
VIM Cheat Sheet

This guide will teach you the basics of VIM and how to get going quickly, and offer you a VIM cheat sheet and other useful resources on where you can learn more.

While VIM can appear hard, it is a really powerful text editor and worth the effort as will save you time in editing large amounts of text.

You will find VIM or vi on most UNIX systems and with Apple OS X. 

How to Run VIM / VI

You can run VIM / VI from the command line or open a file here is the commands:

  1. vi   # This will open vi text editor
  2. vim  # This will open vim text edditor
  3. vi newfile # type a new file name and it will make a blank file ready to save
  4. vim newfile # type a new file name and it will make a blank file ready to save
  5. vi existingfile # type a file name in the current folder to open the text file to edit.
  6. vm  existingfile # type a file name in the current folder to open the text file to edit.

How to quit VIM / VI

esc then : then  q then enter # Will quit file, you may need to add a ! to force close without saving changes.

How to save and quit VIM / VI

esc then : then  wq then enter # This will quit and save changes.

How to enter text into VIM / VI

i # This will turn to input mode you can use the arrow keys and type in text as required.

How to find text in VIM / VI

esc then / then text then enter # This will find word that matches your search use n to go to next result or N to go back.

How to undo and redo in VIM / VI

esc then u # in command mode hit u to undo any change you may keep using u to go back as far as you need.

esc then hold Ctrl + r # in command mode hit Ctrl + u to keep redoing actions you may keep using u to go forward as far as you need.

How to copy and paste lines in VIM / VI

esc then go to line then yy # in command hit yy this will yank the whole line into memory

p # at the desired location to paste hit p to paste the copied line.

Tip: you put a number before yy to cope more line e.g 3yy will copy 3 lines, then p will paste the 3 lines.

Video on using these commands and more

How to learn VIM / VI in a Chrome Game

Goto https://vim-adventures.com/ here you can play a game to teach vim commands, it will take you through the keys by moving a character through an island teaching you all the basics.  

The first level or so is free but will cost $25 for for 6 months access, not worth it IMHO but at lest you can get a start, then move onto the free vimtutor below.

How to learn VIM / VI in Unix

Type vimtutor in unix and hit enter – Yes, vimtutor is literally the name of a program included on your unix system that runs you through a tutorial for vim, it is interactive and fun. 

VIM VI Cheat Sheet

Here is a small vim cheat sheet for the info above you can print out.

Summary

Using VI or VIM can be fun once you handle the basics then the sky’s the limit as there is so much to learn and enhance your day to day work.

For other Linux / Unix related tutorials on my website please click here.

Also please have a look at my YouTube Channel and subscribe for video tutorials as they are released, and if you have any advice for others, requests or questions please leave a comment below.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.