vim

normal mode

  • [count]operation[count]{motion}
  • :q! = quit without saving
  • :x = :wq == write and quit
  • dd or D = delete line
  • d7d = delete the next 7 lines
  • . = repeat the last command
  • CTRL + o = back to last cursor position
  • p = insert (from register) / paste in line below cursor
  • P = paste obove cursor- :reg = list registers
  • "1p = paste from register 1
  • "+y = copy into system clipboard
  • "+p = pate from system clipboard
  • u = undo
  • CTRL + R = redo
  • i = enter insert mode
  • v = enter visual mode
  • y = yank / copy what was selected
  • yy = yank / copy line
  • 4yy = yank 4 lines
  • >> = indent- << = unindent
  • :E = open file explorer (works only with set nocompatible)
  • :bd = buffer delete / close buffer
  • :bn = goto next buffer
  • :bp = previous buffer
  • :ls = list of buffers
  • * = Find word unter cursor- :%s/search/replace/g g for global
  • :%!column -t spaces to columns
  • $ = goto the end of the line
  • x = delete charater under cursor
  • w = goto next word
  • dw = delete next word
  • 0 = goto start of line
  • z ENTER move view to line
  • :terminal Open Terminal in split view
  • :set rightleft right to left (exit with :set rightleft&)
  • :edit! reload file without saving or :e!
  • :set nowrap
  • :set wrap
  • :set nu Show line numbers. Reverse with nonu
    :setlocal cm=blowfish2
  • :X
  • h j k l = move cursor ( h: ← j: ↓ k: ↑ l: →
  • :sp = split screen (same file)
  • :sp filename = open other file
  • :vsp = vertical split
  • CTRL + w CTRL + w = switch between splits
  • :hide = close current window
  • :only = keep only this window
  • :help holy-grail = advanced help
  • :set rightleft = some fun

Search/Replace

  • R = enter replace mode- /pattern – search for pattern
  • ?pattern – search backward for pattern
  • n – repeat search in same direction
  • N – repeat search in opposite direction
  • :%s/old/new/g – replace all old with new throughout file
  • :%s/old/new/gc – replace all old with new throughout file with confirmations

insert mode

  • CTRL + n CTRL + p = Complete word
  • CTRL + x CTRL + l = Complete line
  • CTRL + r = insert register
  • 80i * ESC = insert 80 *
  • 5o # ESC = insert 5 rows starting with #
change EOL / line ending
  • :set ff=unix= set to unix line endings
  • How to jump back to NERDTree from file in tab
    ctrl-ww

INSERT
you can insert text from your host’s clipboard by pressing the right mouse button (default setting) or by pressing Shift + Ins. Note that this has the same effect as entering every character manually. So if you are using auto indentation in vim, this will very likely screw up your code.
To fix that, you can do the following:
Before pasting into vim, enable paste mode by entering :set paste.Press I to enter insert mode. The status bar should say -- INSERT (paste) -- now.Press Shift + Insert (The auto indentation of vim should not happen.)Press Esc to leave insert mode, and disable paste mode using :set nopaste again.

How to delete all lines of file in Vim
Type gg to move the cursor to the first line of the file, if it is not already there.Type dG to delete all the lines.

Leave a Reply

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