commit 1eaf5265b5957b871b1c89d828278ada6afa0972 Author: Marco D'Agostini Date: Wed Nov 6 15:06:16 2019 +0000 diff --git a/TerminalShorcuts.md b/TerminalShorcuts.md new file mode 100644 index 0000000..e9d9b5a --- /dev/null +++ b/TerminalShorcuts.md @@ -0,0 +1,57 @@ +#TL;DR +Alt+0+.: inserts last command without the arguments + +--- + +Tested on Ubuntu 18.04 with the default binding settings *(i.e Emacs key bindings)* + +--- + +# You can combine keyboard shortcuts + +Let's consider the last command to be: + + mv foo bar + +up , Ctrl+w: last command without the last word = `mv foo` + +Alt+0+.: first argument of last command = `mv` + +## Some useful shortcuts: + + - Alt+.: insert last argument from last command *(repeat to go back in history)* + - Alt+number+.: insert #nth last argument from last command *(repeat to go back in history)* + - Alt+- , number , Alt+., **zsh:** Alt+-+#+.: insert #nth first argument from last command *(repeat to go back in history)* + + + - **Cut commands** (relative to cursor's position) + - Ctrl+w: cuts last word + - Alt+d: cuts next word + - Ctrl+k: cuts everything after + - Ctrl+u, **zsh:** Alt+w: cuts everything before + - **zsh:** Ctrl+u: cuts the entire command *(In bash you can combine Ctrl+u , Ctrl+k)* + - Ctrl+y: paste characters previously cut with any **Cut command**. *In bash You can chain **cut commands**, and Ctrl+y will paste them all.* + - Ctrl+_: undo last edit *(very useful when exceeding Ctrl+w)* + - Ctrl+left: move to last word + - Ctrl+right: move to next word + - home or Ctrl+a: move to start of command + - end or Ctrl+e: move to end of command + +### To see all shortcuts available +- **bash:** `bind -lp` +- **zsh:** `bindkey -L` + +## Unfortunately there are some limitations + "words" only includes `a-zA-Z` characters, so any symbol character will stop word-shortcuts. + +So if last argument was a url and you want to erase it with Ctrl+w it will be a pain. + +E.g: `curl -I --header "Connection: Keep-Alive" https://stackoverflow.com/questions/38176514/re-run-previous-command-with-different-arguments` + +To erase that **url** using Ctrl+w, you'd have to repeat it 12 times. + + +--- + + +It would be great to have similar shortcuts that only stops at the **space character** \ No newline at end of file