From 1eaf5265b5957b871b1c89d828278ada6afa0972 Mon Sep 17 00:00:00 2001 From: Marco D'Agostini Date: Wed, 6 Nov 2019 15:06:16 +0000 Subject: [PATCH 01/14] --- TerminalShorcuts.md | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 TerminalShorcuts.md 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 From 1a54c36b84ef2eb68a1c52f087a28c7d6a7fd70e Mon Sep 17 00:00:00 2001 From: Marco D'Agostini Date: Wed, 6 Nov 2019 15:06:32 +0000 Subject: [PATCH 02/14] --- TerminalShorcuts.md | 1 + 1 file changed, 1 insertion(+) diff --git a/TerminalShorcuts.md b/TerminalShorcuts.md index e9d9b5a..0abcc00 100644 --- a/TerminalShorcuts.md +++ b/TerminalShorcuts.md @@ -1,4 +1,5 @@ #TL;DR + Alt+0+.: inserts last command without the arguments --- From f354285d23543f6a55e6763d53985e0978b71c2c Mon Sep 17 00:00:00 2001 From: Marco D'Agostini Date: Wed, 6 Nov 2019 15:07:01 +0000 Subject: [PATCH 03/14] --- TerminalShorcuts.md | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/TerminalShorcuts.md b/TerminalShorcuts.md index 0abcc00..67248a1 100644 --- a/TerminalShorcuts.md +++ b/TerminalShorcuts.md @@ -1,15 +1,3 @@ -#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 From b235a4959d32703d3bb4c4b63c4ad6edd036b481 Mon Sep 17 00:00:00 2001 From: Marco D'Agostini Date: Wed, 6 Nov 2019 15:08:19 +0000 Subject: [PATCH 04/14] --- TerminalShorcuts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TerminalShorcuts.md b/TerminalShorcuts.md index 67248a1..34ccb99 100644 --- a/TerminalShorcuts.md +++ b/TerminalShorcuts.md @@ -14,7 +14,7 @@ Let's consider the last command to be: - **Cut commands** (relative to cursor's position) - - Ctrl+w: cuts last word + - Ctrl+w: cuts last word - Alt+d: cuts next word - Ctrl+k: cuts everything after - Ctrl+u, **zsh:** Alt+w: cuts everything before From 604ece742f0be0eef5bf0d209911ea4a12a93eba Mon Sep 17 00:00:00 2001 From: Marco D'Agostini Date: Wed, 6 Nov 2019 15:08:45 +0000 Subject: [PATCH 05/14] --- TerminalShorcuts.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/TerminalShorcuts.md b/TerminalShorcuts.md index 34ccb99..2a511a9 100644 --- a/TerminalShorcuts.md +++ b/TerminalShorcuts.md @@ -15,11 +15,11 @@ Let's consider the last command to be: - **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.* + - 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 From a4fd8b48f525e1dd9ddc5ae8abdb81d13df598bc Mon Sep 17 00:00:00 2001 From: Marco D'Agostini Date: Wed, 6 Nov 2019 15:09:56 +0000 Subject: [PATCH 06/14] --- TerminalShorcuts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TerminalShorcuts.md b/TerminalShorcuts.md index 2a511a9..c63c4c5 100644 --- a/TerminalShorcuts.md +++ b/TerminalShorcuts.md @@ -19,7 +19,7 @@ Let's consider the last command to be: - 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+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 From 491ab2bccfc93964c7f0adbb35958ef3eebc3a99 Mon Sep 17 00:00:00 2001 From: Marco D'Agostini Date: Wed, 6 Nov 2019 15:28:55 +0000 Subject: [PATCH 07/14] --- TerminalShorcuts.md => bash-zsh_TerminalShorcuts.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename TerminalShorcuts.md => bash-zsh_TerminalShorcuts.md (100%) diff --git a/TerminalShorcuts.md b/bash-zsh_TerminalShorcuts.md similarity index 100% rename from TerminalShorcuts.md rename to bash-zsh_TerminalShorcuts.md From d033536d202524126514729c4073030327cf59ee Mon Sep 17 00:00:00 2001 From: Marco D'Agostini Date: Fri, 3 Apr 2020 11:36:32 -0500 Subject: [PATCH 08/14] Moved *insert commands* to its own section, and specified repeat commands only works in Linux --- bash-zsh_TerminalShorcuts.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bash-zsh_TerminalShorcuts.md b/bash-zsh_TerminalShorcuts.md index c63c4c5..33d4fb5 100644 --- a/bash-zsh_TerminalShorcuts.md +++ b/bash-zsh_TerminalShorcuts.md @@ -8,9 +8,12 @@ Let's consider the last command to be: ## 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)* + - **Select previous arguments** + - Alt+.: insert last argument from last command. + - Alt+number+.: insert #nth last argument from last command. + - Alt+- , number , Alt+., **zsh:** Alt+-+#+.: insert #nth first argument from last command. + + *In Linux you can repeat commands to go back in history* - **Cut commands** (relative to cursor's position) From 2cbeb1a314ffa8bcc8c7b9c5812bbbb58196982d Mon Sep 17 00:00:00 2001 From: Marco D'Agostini Date: Fri, 3 Apr 2020 12:31:22 -0500 Subject: [PATCH 09/14] Organized for general use --- bash-zsh_TerminalShorcuts.md | 67 +++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/bash-zsh_TerminalShorcuts.md b/bash-zsh_TerminalShorcuts.md index 33d4fb5..4129b0b 100644 --- a/bash-zsh_TerminalShorcuts.md +++ b/bash-zsh_TerminalShorcuts.md @@ -1,3 +1,41 @@ +# Shortcuts + +*For Ubuntu's default keybinding settings (i.e Emacs keybindings)* + +## Insert previous arguments + - Alt+.: insert last argument from last command. + - Alt+number+.: insert #nth last argument from last command. + - Alt+- , number , Alt+., **zsh:** Alt+-+#+.: insert #nth first argument from last command. + +*In Linux you can repeat commands to go back in history* + +## Cut/Paste 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.* + + +## Move cursor + - 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 + + +## Other + - Ctrl+_: undo last edit *(very useful when exceeding Ctrl+w)* + +# To see all shortcuts available + - **bash:** `bind -lp` + - **zsh:** `bindkey -L` + +# Other examples + +## Common usecases Let's consider the last command to be: mv foo bar @@ -6,34 +44,7 @@ Let's consider the last command to be: Alt+0+.: first argument of last command = `mv` -## Some useful shortcuts: - - - **Select previous arguments** - - Alt+.: insert last argument from last command. - - Alt+number+.: insert #nth last argument from last command. - - Alt+- , number , Alt+., **zsh:** Alt+-+#+.: insert #nth first argument from last command. - - *In Linux you can repeat commands 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 +# 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. From a087e26fb3770cdcd3f08c41bef2a762a8a1cecd Mon Sep 17 00:00:00 2001 From: Marco D'Agostini Date: Fri, 3 Apr 2020 12:32:03 -0500 Subject: [PATCH 10/14] Example to section `Insert previous arguments` --- bash-zsh_TerminalShorcuts.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bash-zsh_TerminalShorcuts.md b/bash-zsh_TerminalShorcuts.md index 4129b0b..8b298d5 100644 --- a/bash-zsh_TerminalShorcuts.md +++ b/bash-zsh_TerminalShorcuts.md @@ -9,6 +9,17 @@ *In Linux you can repeat commands to go back in history* +### Example: + +Last command is: + + mv foo bar + + - Alt+0+.: insert first argument of last command = `mv` + - Alt+2+.: insert last 2nd argument of last command = `foo` + - up , Ctrl+w: last command without the last word = `mv foo` + + ## Cut/Paste commands *(relative to cursor's position)* - Ctrl+w: cuts last word From d79533b24653741c68442a70290d2024f63685a9 Mon Sep 17 00:00:00 2001 From: Marco D'Agostini Date: Fri, 3 Apr 2020 12:32:48 -0500 Subject: [PATCH 11/14] Added a custom shortcut for zsh, to iterate through the arguments in a previous command --- bash-zsh_TerminalShorcuts.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/bash-zsh_TerminalShorcuts.md b/bash-zsh_TerminalShorcuts.md index 8b298d5..a2176cd 100644 --- a/bash-zsh_TerminalShorcuts.md +++ b/bash-zsh_TerminalShorcuts.md @@ -44,6 +44,33 @@ Last command is: - **bash:** `bind -lp` - **zsh:** `bindkey -L` +# Custom shortcuts +## Iterate through the arguments in a previous command +*only works in zsh, and probably only Linux* + +run or add this to your `~/.zshrc` + + autoload -Uz copy-earlier-word + zle -N copy-earlier-word + bindkey "^[:" copy-earlier-word + +Now use Alt+. to go as back as you want, then use Alt+: to iterate through the arguments + +### Example: +Last command is + + echo 1 2 3 4 5 + +- Alt+.: `5` +- Alt+.+:: `4` +- Alt+.+:+:: `3` +- Alt+.+:+:+:: `2` +- Alt+.+:+:+:+:: `1` +- Alt+.+:+:+:+:+:: `echo` + +source: https://stackoverflow.com/a/34861762/3163120 + + # Other examples ## Common usecases From 30c7a5b09ef098b9895b2781e2e7e3151aede44c Mon Sep 17 00:00:00 2001 From: Marco D'Agostini Date: Fri, 3 Apr 2020 12:38:05 -0500 Subject: [PATCH 12/14] Fixed hierarchy --- bash-zsh_TerminalShorcuts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bash-zsh_TerminalShorcuts.md b/bash-zsh_TerminalShorcuts.md index a2176cd..ae803fa 100644 --- a/bash-zsh_TerminalShorcuts.md +++ b/bash-zsh_TerminalShorcuts.md @@ -40,7 +40,7 @@ Last command is: ## Other - Ctrl+_: undo last edit *(very useful when exceeding Ctrl+w)* -# To see all shortcuts available +## To see all shortcuts available - **bash:** `bind -lp` - **zsh:** `bindkey -L` From 3f86a5ed250c638c28dd33f2119d7321a7ad46f9 Mon Sep 17 00:00:00 2001 From: Marco D'Agostini Date: Fri, 3 Apr 2020 12:48:48 -0500 Subject: [PATCH 13/14] Improved description and instructions for custom shortcut `Iterate through arguments` --- bash-zsh_TerminalShorcuts.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bash-zsh_TerminalShorcuts.md b/bash-zsh_TerminalShorcuts.md index ae803fa..bebbd02 100644 --- a/bash-zsh_TerminalShorcuts.md +++ b/bash-zsh_TerminalShorcuts.md @@ -45,15 +45,21 @@ Last command is: - **zsh:** `bindkey -L` # Custom shortcuts -## Iterate through the arguments in a previous command +## Iterate through arguments *only works in zsh, and probably only Linux* -run or add this to your `~/.zshrc` +### Description +Insert any argument of a previous command by iterating one by one until selection + +### Setup Instructions +run this: autoload -Uz copy-earlier-word zle -N copy-earlier-word bindkey "^[:" copy-earlier-word +*(to make this permanent, add it to your `~/.zshrc` and restart shell)* + Now use Alt+. to go as back as you want, then use Alt+: to iterate through the arguments ### Example: From 2951ee6e407d373eb8f9d48079f7761676a3ef04 Mon Sep 17 00:00:00 2001 From: Marco D'Agostini Date: Fri, 3 Apr 2020 12:56:14 -0500 Subject: [PATCH 14/14] # -> number --- bash-zsh_TerminalShorcuts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bash-zsh_TerminalShorcuts.md b/bash-zsh_TerminalShorcuts.md index bebbd02..125aa3a 100644 --- a/bash-zsh_TerminalShorcuts.md +++ b/bash-zsh_TerminalShorcuts.md @@ -5,7 +5,7 @@ ## Insert previous arguments - Alt+.: insert last argument from last command. - Alt+number+.: insert #nth last argument from last command. - - Alt+- , number , Alt+., **zsh:** Alt+-+#+.: insert #nth first argument from last command. + - Alt+- , number , Alt+., **zsh:** Alt+-+number+.: insert #nth first argument from last command. *In Linux you can repeat commands to go back in history*