Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there a way speed up Linux CLI navigation when I must enter long commands? I simply use arrows right now, and - if I have a long command it takes some time to get from start of the command to the middle of it.

Is there a way to for example jump to the middle of the command without using arrows?

share|improve this question
add comment

4 Answers

up vote 19 down vote accepted

Some useful line editing key bindings provided by the Readline library:

  • Ctrl-A: go to the beginning of line,
  • Ctrl-E: go to the end of line,
  • Alt-B: skip one work backward,
  • Alt-F: skip one word forward,
  • Ctrl-U: delete to the beginning of line,
  • Ctrl-K: delete to the end of line,
  • Alt-D: delete to the end of word.
share|improve this answer
1  
+1 because this works even when, for some reasons, ctrl-arrows do not work. Worth to note, for screen users, Ctrl-A becomes Ctrl-A A. –  enzotib May 27 '11 at 18:54
    
To undo a deletion (or move text by deleting it), use Ctrl + Y. –  Lekensteyn Jun 8 '11 at 22:48
1  
Ctrl+Right arrow, Ctrl+Left arrow worth mentioning. –  mac Jan 16 at 15:04
add comment

I do not know of a way to specifically jump to the middle without using the cursor keys. However, I can recommend using CTRL + cursor key to move from blank to blank (i.e., jump from one word to another).

share|improve this answer
    
big PLUS. this actually makes it significantly faster already! Also - I can't believe I didn't know that. –  Stann May 27 '11 at 15:27
    
In my mind that information is a holdover from extensive use of VI in years gone by. I'm glad it helped. –  Kory Wnuk May 27 '11 at 15:30
add comment

Some more shortcuts from here

Ctrl + a – go to the start of the command line
Ctrl + e – go to the end of the command line
Ctrl + k – delete from cursor to the end of the command line
Ctrl + u – delete from cursor to the start of the command line
Ctrl + w – delete from cursor to start of word (i.e. delete backwards one word)
Ctrl + y – paste word or text that was cut using one of the deletion shortcuts (such as the one above) after the cursor
Ctrl + xx – move between start of command line and current cursor position (and back again)
Alt + b – move backward one word (or go to start of word the cursor is currently on)
Alt + f – move forward one word (or go to end of word the cursor is currently on)
Alt + d – delete to end of word starting at cursor (whole word if cursor is at the beginning of word)
Alt + c – capitalize to end of word starting at cursor (whole word if cursor is at the beginning of word)
Alt + u – make uppercase from cursor to end of word
Alt + l – make lowercase from cursor to end of word
Alt + t – swap current word with previous
Ctrl + f – move forward one character
Ctrl + b – move backward one character
Ctrl + d – delete character under the cursor
Ctrl + h – delete character before the cursor
Ctrl + t – swap character under cursor with the previous one
share|improve this answer
add comment

If you're a vi[m] and bash user, you may find it useful to make readline (used by bash) use vi-style editing by adding set editing-mode vi to your ~/.inputrc or /etc/inputrc files. Or, you could just make bash use vi-style editing by running the bash command set -o vi. Add the command to your ~/.bashrc file to make the behavior persistent.

If you're a zsh user, add bindkey -v to your .zshrc file for vi-style editting.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.