InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Vim tutorials

  • Character toggle case
  • Go back to last edited line
  • Move to matching bracket
  • Multiline search replace with confirmation
  • Open vim at previous location
  • Vim mini cheat sheet
  • Vim redo (undo of last undo)
  • show line numbers
 
  • Home
  • > Tutorials
  • > Vim

Vim mini cheat sheet – handy commands reference

By admin | Last updated on Mar 16, 2016

I use vi quite frequently (Ubuntu/Centos Linux and Mac) for many of my editing needs in addition of couple of other editors (eclipse, intellij, etc). It becomes quite hard to read the manual every now and then when we use very few commands (probably 10-20 or so) on a daily basic. Here are some commands which I used very often.

Terminology
[ESC] Escape key
[CTR] Control key

VI – Search

Normal search (Case sensitive)

[ESC]/foo

Backward search (Case sensitive)

[ESC]?foo

Case insensitive search

[ESC]/foo\c
(\c can come anywhere)

VI – Undo/Redo

Undo

[ESC]u

Redo (can cancel an undo also)

[CTR]r

VI – editing

Insert before a char

[ESC]i

Append after a char

[ESC]a

Delete current line

[ESC]dd

Delete multiple lines

Delete 300 lines (or whatever is left till end) starting from current

[ESC]30dd

Delete current word

Delete current word. If you are in the middle of the word then it deletes the word partially.

[ESC]dw

VI – saving, etc.

Save the file

[ESC]:w

Save file as

[ESC]:w /path/to/file
(Use w! to override)

Quit without saving file

[ESC]:q!

Reload file undoing all unsaved changes

[ESC]:e!

VI – search replace and regular expressions (regex)

Simple global search replace

Simple global (all entries in a line) search replace for all lines from 1 to 10 (use $ for end)

[ESC]:1,10s/foo/bar/g

Remove beginning spaces

Remove 2 beginning spaces from all lines from 10th to last line

[ESC]:10,$s/^  //

Interactive global search replace

Simple interactive global search replace and get prompted for each replacement

[ESC]:1,$s/foo/bar/gc
(This will ask you before replacing each match. Flags: g=>all entries on a line, c=>prompt before replacing)

Suggested posts:

  1. Using WordPress custom field for displaying code
  2. Docker – how to rerun a container with different flags
  3. CSS flexbox – align div vertically and horizontally in center
  4. CSS flex-basis
  5. Memcache – how to dump all keys and values on command line
  6. Alexa rank – how reliable is it?
  7. Linux screen – quick start guide
  8. Docker how to add a user to group docker on Linux
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Tutorials, Vim
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress