Skip to content

Instantly share code, notes, and snippets.

@zfwf
Last active March 10, 2020 03:34
Show Gist options
  • Save zfwf/9c56b32dfe6f6f739114e6f9dbf4a9ad to your computer and use it in GitHub Desktop.
Save zfwf/9c56b32dfe6f6f739114e6f9dbf4a9ad to your computer and use it in GitHub Desktop.
Terminal commands to learn

tmux

  • tmux new -s <name> create new session with
  • tmux attach -t <name> attach to session with
  • tmux kill-session -t <name> kill session with

In tmux hit prefix c-a or c-b then:

? to see a list of commands
Sessions
:new<CR>  new session
s  list sessions
$  name session
d  detach
Windows (tabs)
c  create window
w  list windows
n  next window (`c-l` for oh-my-tmux)
p  previous window (`c-h` for oh-my-tmux)
f  find window
,  name window
&  kill window
Panes (splits)
%  vertical split
"  horizontal split

o  swap panes
q  show pane numbers
x  kill pane (or c-d)
+  break pane into window (e.g. to select text by mouse to copy)
-  restore pane from window
⍽  space - toggle between layouts
m-<arrow key>  resize pane
<prefix> q (Show pane numbers, when the numbers show up type the key to goto that pane)
<prefix> { (Move the current pane left)
<prefix> } (Move the current pane right)
<prefix> z toggle pane zoom

neovim

  • explorer: http://vimcasts.org/episodes/the-file-explorer/

  • g actions: http://vimdoc.sourceforge.net/htmldoc/vimindex.html#g

  • insert mode:

    • <c-p>, <c-n> enable completion
    • <c-x> extended completion mode (shows other options)
      • + <c-l> complete a line (you have to start typing a bit of the line then vim completes for you)
      • + <c-n> | <c-p> context aware completion (use multiple <c-n> + <c-p> to complete sentence)
      • + <c-f> complete file name
  • normal mode:

    • wWeEbBfFtT%/?{} (easymotion)
    • *|# search forward|backward
    • =i{ indent block within {}, also >i{ / <i{ to increase / decrease indent within {}
    • mk, make marker k, `k, move to k. <cmd>`k applies <cmd> between marker and current location.
    • text object
      • iw inner word
      • it inner tag (content of html tag)
      • i" inside " quotes
      • ip inside paragraph
      • as a sentence
    • fold
      • za toggle code fold
      • zr fold reduce (foldlevel--), zR open all folds (set foldlevel to the highest level)
      • zm fold more (foldlevel++), zM close all folds
      • zc close fold under cursor, zC close fold under cursor recursively
      • zo close fold under cursor, zO open fold under cursor recursively
      • zv view cursor line, if jump to a line in a closed fold this opens just enough fold to see the line
      • zx update fold, re-apply foldlevel, undo manual folds
    • :b n|p move to next|prev buffer
    • splits
      • :[v]sp [vertical] split
      • <c-w> general split command
        • + q close split
        • + [j|k|h|l] move to [down|up|left|right] split
        • + <number>[+|-] [increase|decrease] split size by
    • tag/nav
      • <c-]>, <c-t> - jump to def, jump back. <c-i>, <c-o> move forward and backward through jump list (look in to locations, then back out)
      • g] to view a list of def for a tag
      • gd|gD local|global declaration.
      • g*|g# search for the word fwd|bwd under the cursor (like , but g on 'rain' will find words like 'rainbow').
      • <c-w>} preview tag in preview window, :pclose closes preview window
      • <c-w>f goto file under cursor in new window
  • Ex mode

    • :+ny yank n line after current line, :-ny same before current line
    • :.,+ny yank current and n line after current line, :-n,.y same in the other direction
  • quickfix

    • cop[en], :ccl[ose], open, close
    • :cn and :cp allows moving to next, prev item even when quickfix is closed

vimdiff

  • diff
    • ]c and [c next or prev change
  • merging
    • :diffg RE " get from REMOTE
    • :diffg BA " get from BASE
    • :diffg LO " get from LOCAL
    • ConflictMotions plugin can help navigate around conflict markers

vscode vim

gd - jump to definition. gq - on a visual selection reflow and wordwrap blocks of text, preserving commenting style. Great for formatting documentation comments. gb - adds another cursor on the next word it finds which is the same as the word under the cursor. af - visual mode command which selects increasingly large blocks of text. For example, if you had "blah (foo [bar 'ba|z'])" then it would select 'baz' first. If you pressed af again, it'd then select [bar 'baz'], and if you did it a third time it would select "(foo [bar 'baz'])". gh - equivalent to hovering your mouse over wherever the cursor is. Handy for seeing types and error messages without reaching for the mouse!

resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment