Monday, May 6, 2024
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 1630  / 1 Year ago, thu, may 4, 2023, 11:00:45

In the terminal, one can use the tab key to help auto-complete typing out a directory or file name. However, if I make a mistake and mistype the beginning of the directory and "tab it out", I end up having to use backspace and re-type it in. Is there a shortcut key to undo the auto-completion in the terminal?


EDIT FOR CLARIFICATION


To expand on what I've said in a comment, I was wondering if there was a shortcut to undo to the last directory. So, currently ctrl+shift+- seems to work well except it un-does individual letters.


For example, if I have the following directory setup:


Documents

--> d1something

--> d2something

And I want to go to "d2something" but accidentally type "cd d1", it will autofill to:


cd Documents/d1something/

Then, by using ctrl+shift+- it will then be:


cd Documents/d1something

Again:


cd Documents/d1

Again:


cd Documents

What I was wondering if there's a shortcut to get from cd Documents/d1something/ back to cd Documents (first and last step). If not, the ctrl+shift+- will work fine.


More From » command-line

 Answers
1

According to the bash man page, the default shortcut for the undo function is either Ctrl+_ (note that this is Ctrl+Shift+- on most keyboards) or Ctrl+x followed by Ctrl+u. If your tab completion added a trailing slash to the directory name, you may have to undo twice, once to remove the slash and once more to remove the text that the completion added.



If instead what you want is to remove the last complete directory component from a path you are entering in bash, the closest way to achieve this is with the backward-kill-word function. By default this is bound to the Alt+Backspace key combination. This will erase the last "word" from your command line, where a word consists entirely of alphanumeric characters.



This seems to work with your given example directory names. Note that if the last directory name contains spaces or punctuation characters like - or _, these are treated as word delimiters, so you may have to repeat this key combination more than once to erase back to the last / character.


[#25249] Saturday, May 6, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
calronze

Total Points: 0
Total Questions: 110
Total Answers: 112

Location: Belarus
Member since Thu, Aug 11, 2022
2 Years ago
;