Technology and Art


Get new posts via email



Code

RedDragonForge
RedDragon
Cobol REKT
Mojo LSP
Plenoxels
IRIS

Contact

Github
Twitter
LinkedIn

Site Feed

Vim and TMux Commands Galore

Avishek Sen Gupta on 5 January 2023

I’ve also added TMux shortcuts because I’m learning to use that too.

Vim commands

  • u/<C-r>: Undo/Redo
  • .: Repeat last command
  • w/b: Move forward/backward by a word
  • e: Move to end of word (last character)
  • s refers to a sentence. Thus dis and das deletes a sentence from anywhere inside it, and everything around the sentence, respectively.
  • (/): Jump to previous/next sentence
  • i/a/I/A: Start editing before/after cursor, before start/after end of line
    • i: Considers whitespace as words too, so i2w selects a word and any whitespace after it.
    • a: Considers word + whitespace as a text object, so a2w selects "text1 text2 ".
  • 0/^/$: Go to starting character / starting non-whitespace character / end of line
    • +/-: Jump to starting non-whitespace character of next/previous line
  • d: Delete (suffix with counter and text object, like d2w, dd)
  • c: Change (suffix with counter and text object, like c2w, cc)
  • r: Replace the single character under cursor
    • R keeps you in replace mode
  • y: Yank (suffix with counter and text object, like y2w, yy)
    • Interesting Use Case: ny$ yanks from cursor to end of line n times, so n lines, starting from the current cursor position.
  • f-x/F-x: Find character x forward / backward from cursor
  • t-x/T-x: Find “just before” character x forward / backward from cursor
  • *: Search forward word under cursor
  • / and ?: Find string forward/backward
    • NOTE: You can chain this with other normal mode commands, e.g.: d/lol deletes all the way upto, but excluding, lol.
  • P/p: Paste before/after cursor
  • x: Delete character under cursor
  • nG/ngg: Go to line number n
  • G: Go to end of file
  • i: “Everything inside” qualifier used in conjunction with other verbs, like diw, ci"
  • a: “Everything around” qualifier used in conjunction with other verbs, like daw, ca"
  • <C-v>: Visual Block Mode, use I to insert en-masse
  • <C-o>/<C-i>: Go to old/new positions
  • <C-u>/<C-d>: Move up/down half a page
  • {/}: Jump forward/back across a contiguous block of text

Ex commands

  • x,y<Command>z: Defines an inclusive range of lines from x to y and performs <Command> with optional argument z.
    • m/t: Move/Copy range of lines to after z. Example: 10,20m30. Single line variants like10m30 also work.
  • x;+/-n: Defines range of +/-n starting from line x
  • ., .+/-n: Refers to the current line / Refers to n lines after/before current line.
  • $, $+/-n: Refers to the last line of the document (Compare to going to last character in line in Vim’s Normal mode). +/-n navigates n lines after/before last line.
  • %: Refers to all lines (same as 1,$)
  • <scope>s/<pattern>/<replacement> does search and replace, but only for the first occurrence of pattern on a given line. No specified scope limits it to the current line. Add /g at the end for it to process every occurrence of pattern on a given line.
  • Commands can be d, y, c, etc. Append /e to include the pattern.
  • Use :<scope>g/<pattern>/<Command> to match every line in scope which matches pattern, and then runs the Command on that line.

TMux commands

  • <C-b>?: View all keybindings
  • <C-b>%: Horizontal split
  • <C-b>": Vertical split
  • <C-b><Arrow Keys>: Moves across TMux panes
  • <C-b>d: Detaches from current TMux session
  • <C-b>[: Enables scroll mode
  • <C-b><Space>: Enables highlight mode after entering scroll mode. Press <C-b> to yank highlighted text.
  • <C-b>]: Pastes copied content to another TMux terminal
  • tmux ls: Lists running TMux sessions
  • tmux attach -t <SessionID>: Attaches to specified TMux session
  • tmux rename-session -t <OldSessionID> <NewSessionID>: Renames a TMux session
  • <C-b>,: Renames current window
  • tmux new -s <SessionID>: Creates a new TMux session with given SessionID

tags: Vim - Text Editing