All Articles

Vim Commands

vimvim

Table of Contents

Click to follow link

VIM Commands

I’m currently using

  • VIM Editor for Python (iTerm)
  • IdeaVim for Golang (IntellJ)
  • VSCodeVim for JavaScript (VS Code)

Vim has 3 modes.

  1. Insert Mode
    Write text
  2. Normal Mode (Visual Mode)
    Navigate and manipulate text
  3. Command Mode
    Can input a wide variety of commands.

Change Modes

  • Normal Mode → Insert mode
    i : insert
    Enter insert mode

    • Insert at the beginning of the line
      I
    • Insert end of the line
      A
    • Insert at the nend of the word
      ea
  • Insert mode → Normal Mode
    v : Visual
    Enter visual mode
    V
    Enter linewise visual mode
  • Command mode
    esc
    Enter Command mode

↑ return to TOC

Left, Down, Up, Right

  • Move Left
    h
  • Move Down
    j
  • Move Up
    k
  • Move Right
    l

↑ return to TOC

Undo, Redo

  • Undo
    u
  • Redo
    ctr + r

↑ return to TOC

Delete

  • Delete a character
    x : Delete character after the cursor.
    X : Delete character before the cursor.
  • Delete a word
    dw
  • Delete the line
    d + d : Delete current line.
  • Delete to end of line.
    D
  • Delete number of lines.
    <#>d
    d<#>j : delete # of lines down(j)

    • e.g.
      3d : Delete 3 lines. 100d : Delete 100 lines.

↑ return to TOC

Move cursor

  • Beginning of the file.
    gg
    [[ Move to beginning of the file.
  • End of the file.
    G
    ]]
    Move to end of the file.
  • Move to the top of the screen.
    H : High
  • Move to the middle of the screen.
    M : Middle
  • Move to the bottom of the screen.
    L : Low

↑ return to TOC

Jumping around

  • Jump to specific line.
    :<line#>

    • e.g.
      :14 : Will Jump to line 14.
      :55 : Will Jump to line 55.
  • Jump to end of a word.
    e
  • Jump to end of a word (before whitespace)
    E
  • Jump to beginning of next word.
    w
  • Jump to beginning of next word (before whitespace)
    W
  • Jump to previous beginning of word.
    b
  • Jump to previous beinning of word (before whitespace)
    B
  • Jump to beginning of the line.
    0
  • Jump to end of the line.
    $
  • Jump to next paragraph
    }
  • Jump to previous paragraph
    {

↑ return to TOC

Scrolling screen

  • Move to current cursor position.
    z
  • Move forward a full screen.
    ctr + f
    f : forward
  • Move backward a full screen.
    ctr + b
    b : backward
  • Move forward half a screen.
    ctr + d
    d : down
  • Move backward half a screen.
    ctr + u
    u : up

↑ return to TOC

  • Find a word under cursor.
    *
  • Find a character after cursor in the line
    f
  • Serach string.
    /<string>

    • e.g
      /baby : baby will be searched
      /tiger : tiger will be searched

↑ return to TOC

Copy, Paste

  • Copy.
    y
    y : yank
  • Copy the line.
    yy
  • Copy the current word.
    yiw
  • Copy to the end of the line.
    y$ : Copy from current cursor to the end of the line.
  • Paste copied.
    p : Paste after the cursor.
    P : Paste before the cursor.

↑ return to TOC

Add new lines.

  • Add new line before cursor.
    o
  • Add new line after cursor. O

↑ return to TOC

Indentation

  • Auto indentatation.
    ==
  • Indent.
    >
  • Outdent.
    <

↑ return to TOC

Save, quite File

Save and quite in command mode.

  • Save it
    :w : write
  • Quit
    :q : quite
  • Force Quit
    :q!
    Quit w/o saving changes.
  • Save and Quite
    :wq
    Save and quite file.

↑ return to TOC