Best Vim Cheat Sheet



  1. Vim Cheat Sheet 4k
  2. Vim Visual Cheat Sheet
  3. Best Vim Cheat Sheets
  4. Vim Shortcuts Cheat Sheet Pdf

Vim is a pretty great text editor, but learning to use it effectively can be a challenge. Even if you keep a quick-reference card or cheatsheet around, it can be difficult to figure out which commands are the most useful. But the truth is, Vim can still be super helpful if all you know is a few commands. So I’ve compiled a few of the Vim commands that I use every day.

  • Quick Start/Cheat Sheet. Vim commands are more of a language than a list of commands you need to use. From the Command Line. Type “vim” into the command line to create a new untitled file; type “vim /path/to/file.name” to open an existing file. (if the file doesn’t exist, this creates it).
  • My Best SPF Check Tools. My Best SSL Check Tools. IP Calculater Web Tools popular. Vi / vim Cheat Sheet. Table of Contents. Vi / vim Cheat Sheet.

Movement

Vim Cheat Sheet. Vim is a free, open-source text editor that comes installed by default with most operating systems. This tool is one of the most popular and powerful text editors that has been the preferred choice of many programmers. Learning to use Vim effectively can be a challenge, as Vim contains a lot of commands, and memorizing each and every command could take time.

h j k l

Best vim cheat sheet 2020

Basic movement keys. A step up from the cursor keys simply because they are already under your fingers. Most useful when prefixed with a number (e.g. if you need to move down by about 10 lines, hit “10j” instead of just holding j until you get there).

b w B W

Move back by token/forward by token/back by word/forward by word. (A token is a sequence of letters, digits, and underscores. For the capital letter variations, a word consists of anything that’s not whitespace.) Faster than holding down a simple directional key.

0 ^ $

Jump to first column/first non-whitespace character/end of line, like Home and End. Faster than moving by words if you’re trying to get to the opposite end of the line.

ctrl+u ctrl+d

Basically Page Up and Page Down, but moves by half a screenful and doesn’t lose your cursor position.

<line-number>G

Jump directly to a specific line number. Most helpful if you also have line numbering enabled (:set number).

H M L

Move to the top/middle/bottom of the screen (i.e. High/Middle/Low). A good first step in getting approximately to where you want to go.

# *

Find the previous/next occurrence of the token under the cursor.

n N

Repeat the last find command forward/backward.

Vim Cheat Sheet 4k

(That’s two back-ticks). Jump back to where you just were. This will jump back and forth between the same two locations if you keep pressing it.

ctrl+o ctrl+i

Move backward/forward through the jump history. Useful if you have followed a chain of method calls and need to get back to where you were.

Editing

In Vim, you spend most of your time in “normal” mode, switching to “insert” mode only when you need to add or change some text. This way, all edits become their own self-contained operations that can be repeated or chained with other operations. Most editing commands may optionally be preceded by a number in order to apply it more than once (e.g. to delete three lines, press 3dd).

i a I A

Enter insert mode (insert at cursor/append after cursor/insert at beginning of line/append to end of line). Press Esc to exit insert mode and return to normal mode. It’s rarely useful to precede one of these commands with a number, but it can come in handy. Need a comma-separated list of eight 1s? Just hit “8i1, <esc>” then delete the trailing comma.

o O

Open new line (below the current line/above the current line). A quick “o<esc>” will add a blank line below the current line, no matter where your cursor is.

cw cW

Correct the token(s)/word(s) following the cursor. Basically combines delete and insert into one step.

Vim

Vim Visual Cheat Sheet

cc

Correct line(s) by clearing and then entering insert mode. Starts inserting at the current indent level.

dd

Delete line(s). Quickly rearrange lines by deleting them, moving to the new location, and pasting with “p”.

ct cf ci ca

dt df di da

Correct/delete up to or including specific characters. Since there are many variations, I break it down in the section below about correcting text.

s

Delete character(s) at the cursor and then enter insert mode. cw is usually faster if you want to correct an entire word, but this is useful for correcting a fixed number of characters (e.g. “5s” will correct the next five characters).

yy

Copy line(s). The “y” is for “yank.”

yw yW

Copy token(s)/word(s).

Best Vim Cheat Sheets

p P

Paste the last thing that was deleted or copied before/after cursor (for more advanced usage, you can precede it with a register specification, but that’s a topic for another day).

u ctrl+r

Undo and redo.

.

(That’s a period). Repeat the previous edit command. I use this all the time. Did you just add a line (e.g. using “o” or “O”) that you need to duplicate five more times with only slight modifications? Hit “5.” to repeat that operation, then make your modifications; no copy/paste needed.

Correcting Text

In a boring text editor, you are limited to very basic operations: highlight some text, delete it, type more text. Vim has the ability to highlight (it’s called “visual” mode), but I rarely use it. It is often much faster to achieve the same thing using a few editing commands.

I frequently need to correct some text that doesn’t fall neatly onto a token or word boundary. Fortunately, operations like “c” (correct) and “d” (delete) have a number of operators that may be applied to them:

  • t<char> – exclusive match: continue up to (but not including) the next <char> on this line
  • f<char> – inclusive match: continue up to (and including) the next <char> on this line
  • i<char> – exclusive inner match: apply to text bounded by <char>, where <char> is from a limited set of characters that come in pairs, like quotes, parentheses, brackets, etc.
  • a<char> – inclusive inner match: same as above, except it includes <char> on both ends

Say that I have the code below, and I want to completely replace the code inside the map() with something else:

signal.map(count -> String.format(“%d cookies, ah ah ah”, count));

The first thing I need to do is get my cursor anywhere inside the parentheses belonging to map(). The exact command I use depends on where I end up:

  • If the cursor is just inside the open paren for map(), I could use “cf)”. This corrects all text up to and including the next “)” on this line.
  • Say the cursor is on the word “format”. I would do “ci(”. Vim will search backward to find the first open paren, then search forward to find its match, and correct the text between (but not including) those characters.
  • Maybe my cursor was already closest to the word “cookies.” To break out of the inner parentheses, I would need to add a count and do “2ci(”. This is almost identical to the last example, except that the 2 is needed due to the nested parentheses.

I’m now in insert mode so I can carry on by entering the new text.

There’s More…

Vim may seem to have a steep learning curve, but by mastering a few commands you can quickly achieve greater productivity than you could with a regular text editor. What are some other Vim commands that you use every day?

If you’ve been following me for a while, you might know my editor of choice is VIM,it’s very clean. There’s nothing there to get in your way, except your own limitations, and those limitations can bedestroyed through practice. Haven’t tried vim yet? What are you waiting for?

Vim is a text editor written by Bram Moolenaar and first released publicly in 1991.It is commonly found on unix-based operating systems.VIM is based off an older text editor, vi, and it’s name is an acronym for Vi-Improved.With vim Your fingers never have to leave the keyboard to command great power. The learning curve is a little steep but you can very quickly pick up new skills as you need them. The basic premise is that there is an Input modeand a Command mode. By default you start in command mode, here you can move around the document, search, and do a fair bit of editing quickly. Insert mode is designed for adding (and removing) text, it’s just like a normal texteditor.

Quick Start/Cheat Sheet

Vim commands are more of a language than a list of commands you need to use.

From the Command Line

  • type “vim” into the command line to create a new untitled file
  • type “vim /path/to/file.name” to open an existing file. (if the file doesn’t exist, this creates it)
  • to open multiple files list them like vim file1.txt file2.sh they’re placed into buffers
    • you can switch to the next open file with the command :bn, or the previous one with :bp, to move to the next or previous buffer.
    • to open in a split window vim -o file.type file2.type file3.type (lower case “o” for horizontal, uppercase for vertical split)
  • open a file & jump to a particular line with vim +10 file.type for the 10th line (+ alone will jump to the end of the file)
  • You can run vim functions directly from the command line vim +FunctionName +qall (qall tries to quit all, but refers to the user to accept or reject changes made with a standard :w/q!)
  • open a file & jump to a particular word or phrase with vim -c '/searchstring' file.type (you can execute other commands with the -c flag too)
  • find the differences between two files with vim -d file.v1 file.v2 (this works like vimdiff)

Working with VIM modes

  • hit “i” to switch from command mode to input mode
  • hit “v” to switch from command mode to visual mode
  • hit “esc” to switch back to command mode

note: ‘i’ doesn’t mean “enter insert mode” so much as it is a command to “insert the following text until you hit ESC”Also, “command mode” is often referred to as “normal mode,” because for a lot of tasks, you will probably want to use a bunch of commands, instead of writing a bunch of stuff in input mode.

VIM Command/Normal-mode

  • type “:wq” or “ZZ” to save and quit
  • type “:q!” to quit without saving
  • moving the cursor (basic movements)
    • j move down one line
    • k move up one line
    • h move left one character
    • l move right one character
  • to move to line 88 hit 88G or 88gg
  • move to the begining of a file hit gg
  • move to the end of the file hit G
  • move one word forward with w
  • move one word backward with b
  • move to the end of the line with $
  • move to the begining of the line with 0
  • move to the first character of the line with ^
  • hitting % while the cursor is on a bracket like [({})] will find the matching bracket
  • to delete a character hit x
  • to cut a line hit dd
  • to copy a line hit yy
  • to cut or copy multiple lines put a number before the command like 5dd
    • you can put a number before most commands to repeat them X many times.
  • press p to paste after the current line
  • press P to pase before the current line
  • to delete from the cursor to the end of the line hit d$, for example, or any other movement key (wbhjkl…)
  • in command mode to search for apple type /apple and hit enter
    • to look for the next occurance hit n
  • in command mode to find and replace all occurances in a line type :s/original/replacement/g
    • when searching you can use regular expressions
  • in command mode to find and replace all occurances in a file type :%s/original/replacement/g
  • for an interactive history of commands use q:
  • for an interactive history of searches use q/ or q?)
  • need more info? try :help there’s a wealth of information there
    • you can get more details about the help command with :help help
    • you can find an index of commands with :help index

VIM Input-mode

I’m not sure how useful these are in gvim, but these should work if you’re running in a terminal.

  • alt/meta+normal command usually works
    • alt+hjkl offers the standard movements
    • alt+o opens a new line below the current one
    • alt+A appends to the end of the current line
    • alt+p to paste
    • alt+R' to paste from register ', for example, or use and other register.

VIM tips

Vim Shortcuts Cheat Sheet Pdf

  • If the file is owned by root and you opened it as another user, you can escalate privileges and save with :w !sudo tee %
  • You can insert a file below the cursor with :r /path/to/file.txt or if you don’t supply a file it will insert the current file below the cursor.
  • the delimiter when using :s doesn’t have to be / you can try % or _ if you want to avoid fences like in :s//usr/local/bin//common/bin/ you can use :s#/user/local/bin#/common/bin#
  • unless you set a equalprg in your vimrc, you can auto-indent with =
    • to autoindent an entire file use gg=G (could have “unexpected” results)
    • to autoindent the current line
    • to autoindent this line and the one after it is =j where j is a movement key
    • if you select a section with visual mode you can indent just that selection with =
  • You can store a cursor location in a mark, you can set a mark with command m followed by a letter like ma, it accepts [A-Za-z] so you get 52 different marks.
    • you can move to a line containing a mark using the ' (single quote) command 'a moves to the line containing the mark labeled a
    • you can move to the exact location of the mark using the ` (backquote) command `a moves to the mark labeled a
    • these are “movements” that can be combined with other statements like d`a to cut text from the cursor’s location to the mark labeled a
  • You can make macros with the q command,
    • hit qa to create a macro named a (should show a record indicator) enter a series of commands and hit q again to stop recording.
    • hit @a to execute the macro named a, you can execute the command multiple times in the standard way 23@a will repeat it 23 times.
    • You can execute a register as a macro with @A for register A, for example, or use any other register.
  • You can execute a register as an ex command with :@A for register A, for example, or use any other register.

Going Further

Best vim cheat sheet 2019

Vim is highly customizable, you can set shortcuts and preferences in the .vimrc file, usually located in your home directory.There are a ton of plugins (aka scripts) available too. They’re easy to manage with other scriptslike Pathogen, Vundle, or vim-plug. I just switch from vundle to vim-plug because it makes it easier to configure your plugins and does it a lot faster.

If you want to get a headstart, my dotfiles are available on github, but there are a lot of peopledoing that lately, so look around. Also there’s a few very nice VIM Distributions like Janus, SPF13-vim, and dotvim that have a lot of plugins and a nice vimrc right out of the box, definitely worth a look.

Links

  • Vim Interactive Tutorial (try it now!)
  • Vim Galore (“Everything you need to know about vim”)
  • Vimcasts (video tutorials)
  • Learning Vi & Vim editors (O’Reilly) (prefer books?)
  • VIM Adventures (Learn VIM playing an RPG)
  • vimgolf (find the shortest way to complete the challenges)
  • shortcutFoo (Drills to learn your tools better)
  • amix’s .vimrc (a huge default vimrc file with lots of goodies)
  • vimrc generator (makes a simple/minimal vimrc with a nice GUI)