Skip to content

Instantly share code, notes, and snippets.

@edwelker
Last active August 29, 2015 13:58
Show Gist options
  • Save edwelker/10001002 to your computer and use it in GitHub Desktop.
Save edwelker/10001002 to your computer and use it in GitHub Desktop.
Bash history
History event commands
! - history substitution
!! - last command
!n - nth command
!-n - nth previous command
!string - command that starts with string
!?string[?] - command that contains string
^old^new^ - quick substitution of command
History word commands
:0 - name of command
:n - nth arg
^ - first arg
$ - last
% - argument matched by ?string?
:n-m range
-m (same as :0-m) - 0 through m
:n- - n through next to last
:n* - n through last
* - all args
History Modifiers
:p - just print the command
:s/old/new - first instance
:gs/old/new - change all instances
:Gs/old/new - substitute on all words in command
:& - repeat previous substitution, first instance
:g& - repeat previous substitution, all instances
:q - quote a word list
:x - quote separate words
Truncation modifiers
:r - first available root
:e - first available extension
:h - first available head
:t - first available tail
vi mode:
esc, /string<enter> - will search for the most recent string
ctrl-r: will reverse search history, repeated ctrl-r's will cycle back through matches
$<tab> - will autocomplete all env variables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment