On bash command-line, how to delete all letters before cursor? I know Ctrl-k deletes all afterward the cursor.
3 Answers
Ctrl-u
- Cut everything before the cursor
Other Bash shortcuts,
- Ctrl-a
Move cursor to beginning of line
- Ctrl-e
Move cursor to end of line
- Ctrl-b
Move cursor back one word
- Ctrl-f
Move cursor forward one word
- Ctrl-w
Cut the last word
- Ctrl-k
Cut everything after the cursor
- Ctrl-y
Paste the last thing to be cut
- Ctrl-_
Undo
And discover more via man page for bash shell: man bash
Additional bash command-line shortcut cheat sheet: http://www.bigsmoke.us/readline/shortcuts
See the documentation here: http://www.gnu.org/software/bash/manual/bashref.html#Commands-For-Killing
Obligatory: Learn more about Bash, Linux, and Tech through Julia's comics: https://twitter.com/b0rk/media
-
7
-
1Where is the "official" documentation about these? Why you only show fish without showing how to fishing?– qazwsxSep 8, 2012 at 21:35
-
4
-
2
-
2@qazwsx For at least some of this, GNU readline is the relevant software, maintained by the GNU bash maintainer, and in step with it. See tiswww.case.edu/php/chet/readline/rluserman.html . Also
man 3 readline
is full of exotica. Apr 14, 2022 at 9:50
In zsh, Alt+w clears all characters before the cursor.
In contrast to bash this does NOT cut them; it just deletes them.
This applies to zsh's Emacs mode (which is the default), NOT to Vi mode.
-
Actually, I did recently learn that bash does 'cut' when readline (not bash, actually) deletes. On my Linux machine now, in bash, I can cut back a word with control+W and "yank" it back with control-Y. Many vexing and obscure key combos are there, but learning the big hitters is already useful when working in a shell. (If you dare to use vim mode for readline, you can have yank with a different meaning.) My head hurts, but cursor keys are less worn. See tiswww.case.edu/php/chet/readline/rluserman.html Apr 14, 2022 at 9:55
man 3 readline
. These apply to very many ineractive command-line tools, not just bash.