Shortcuts
Sungwa Yu

Note: ‘*‘ means the setup is conflict with another key

Mac

Mission Control

*Move left a space (desktop): Ctrl+2

*Move right a space (desktop): Ctrl+3

iTerm2

split horizontally: cmd+shift+D

split vertically: cmd+D

select pane: cmd+opt+arrow

type command to multiple terminals at the same time: cmd+shift+i

same for cancel

Capslox

Global

*Switch input source: Caps+space

Movement

Move up: Caps+e

Move down: Caps+d

Move backward: Caps+s

Move forward: Caps+f

*Move backward one word: Caps+w

*Move forward one word: Caps+r

Move to the beginning of the line: Caps+p

Move to the end of the line: Caps+;

Selection

Select current word (select backward): Caps+c select and copy Caps+c then Cmd+c

Deletion

*Delete one word (backward): Caps+'

*Delete to the beginning of the line: Caps+[

*Delete to the end of the line: Caps+']

System: delete line: Cmd+Del; new line: Cmd+Enter

Vim

References: https://vim.rtorr.com/

Commonly Used

  • Delete one word
    • Capslox: Caps+w/r to choose word, then Caps+' to delete the word on the left of the cursor
    • Vim: w and r to choose word, then daw
  • Delete to the beginning/end
    • Capslox: Caps+[/Caps+]
    • Vim: [/] (mapped to d0/D)
  • Copy a word
    • Capslox: Caps+w/r to choose word, then Caps+c to select the word on the left of the cursor, then Cmd+c to copy
    • Vim: w and r to choose word, then yaw

Global

  • :sav[eas] file - save file as
  • :ter[minal] - open a terminal window
    • Exit: Ctrl+w then :q!
  • :set spell spelllang=en_us - turn on English spell

Cursor Movement

  • h - move cursor left 4h: move cursor 4 character left
  • j - move cursor down. 4j: move cursor 4 lines down
  • k - move cursor up
  • l - move cursor right
  • ge - jump backwards to the end of a word. Map w
  • e - jump forwards to the end of a word. *Map to r
  • 0 - jump to the start of the line. Use I instead
  • $ - jump to the end of the line. Use A instead
  • gg - go to the first line of the document
  • G - go to the last line of the document
  • Ctrl + d - move forward 1/2 a screen. *Map to h
  • Ctrl + u - move back 1/2 a screen. *Map to l
  • f: find, fr find next r
  • fx - jump to next occurrence of character x (same line) eg. yfr; dfr
  • Fx - jump to previous occurrence of character x (same line)
  • ; - repeat previous f, t, F or T movement
  • , - repeat previous f, t, F or T movement, backwards

Insert Mode

  • i - insert before the cursor
  • I - insert at the beginning of the line
  • a - insert (append) after the cursor
  • A - insert (append) at the end of the line
  • o - append (open) a new line below the current line
  • O - append (open) a new line above the current line

Editing

  • cc - change (replace) entire line eg. caw: delete the word and enter insert mode; c4j
  • ciw - change (replace) entire word
  • u - undo
  • U - restore (undo) last changed line
  • Ctrl + r - redo
  • . - repeat last command

Marking Text (Visual Mode)

  • v - start visual mode, mark lines, then do a command (like y-yank)
  • o - move to other end of marked area
  • aw - mark a word eg. yaw: copy a word; caw
  • ab - a block with ()
  • aB - a block with {}

Visual commands

  • y - yank (copy) marked text
  • d - delete marked text

Cut and paste

  • yy - yank (copy) a line eg. yaw: copy a word; y4k; yfr
  • 2yy - yank (copy) 2 lines
  • yiw - yank (copy) word under the cursor
  • yaw - yank (copy) word under the cursor and the space after or before it
  • y$ - yank (copy) to end of line
  • p - put (paste) the clipboard after cursor*
  • P - put (paste) before cursor*
  • dd - delete (cut) a line eg. d8j, dfr
  • 2dd - delete (cut) 2 lines
  • diw - delete (cut) word under the cursor
  • D - delete (cut) to the end of the line
  • x - delete (cut) character

Exiting

  • :w - write (save) the file, but don’t exit
  • :w !sudo tee % - write out the current file using sudo
  • :wq - write (save) and quit
  • :q - quit (fails if there are unsaved changes)
  • :q! - quit and throw away unsaved changes
  • :wqa - write (save) and quit on all tabs

Search and replace

  • /pattern - search for pattern
  • ?pattern - search backward for pattern
  • n - repeat search in same direction
  • N - repeat search in opposite direction
  • :noh[lsearch] - remove highlighting of search matches
  • :%s/old/new/g - replace all old with new throughout file
  • :%s/old/new/gc - replace all old with new throughout file with confirmations

Tabs

  • :tabnew or :tabnew {page.words.file} - open a file in a new tab
  • gt or :tabn[ext] - move to the next tab
  • gT or :tabp[revious] - move to the previous tab
  • #gt - move to tab number #
  • :tabm[ove] # - move current tab to the #th position (indexed from 0)
  • :tabc[lose] - close the current tab and all its windows
  • :tabo[nly] - close all tabs except for the current one

Working With Multiple Files

  • :e[dit] file - edit a file in a new buffer (full screen, the previous file working on still exists under it)
  • :bn[ext] - go to the next buffer
  • :bp[revious] - go to the previous buffer
  • :bd[elete] - delete a buffer (close a file)
  • :b[uffer]# - go to a buffer by index #
  • :b[uffer] file - go to a buffer by file
  • :ls or :buffers - list all open buffers
  • :sp[lit] file - open a file in a new buffer and split window
  • :vs[plit] file - open a file in a new buffer and vertically split window
  • :vert[ical] ba[ll] - edit all buffers as vertical windows
  • :tab ba[ll] - edit all buffers as tabs
  • Ctrl + ws - split window
  • Ctrl + wv - split window vertically
  • Ctrl + ww - switch windows
  • Ctrl + wq - quit a window
  • Ctrl + wx - exchange current window with next one
  • Ctrl + w= - make all windows equal height & width
  • Ctrl + wh - move cursor to the left window (vertical split). *Map to H
  • Ctrl + wl - move cursor to the right window (vertical split). *Map to L
  • Ctrl + wj - move cursor to the window below (horizontal split). *Map to J
  • Ctrl + wk - move cursor to the window above (horizontal split). *Map to K
  • Ctrl + wH - make current window full height at far left (leftmost vertical window)
  • Ctrl + wL - make current window full height at far right (rightmost vertical window)
  • Ctrl + wJ - make current window full width at the very bottom (bottommost horizontal window)
  • Ctrl + wK - make current window full width at the very top (topmost horizontal window)

NERDTree

References: https://cheatography.com/stepk/cheat-sheets/vim-nerdtree/

Files

  • o: open in prev window (cursor goes in)
  • go: preview (cursor not goes in)
  • t: open in new tab
  • T: open in new tab silently
  • i: open split
  • gi: preview split
  • s: open vsplit
  • gs: preview vsplit

Directories

  • o: open & close
  • O: recursively open
  • x: close parent
  • X: close all children recursively