Monday, 23 March 2015

Tips: Shortcuts on the current line

Try these useful bash shell shortcuts:


  • Ctrl+A: move to the start of the current line
  • Ctrl+E: move to the end of the line
  • Alt+F: move to the end of the next word
  • Alt+B: move to the start of the current or previous word
  • Ctrl+T: swap the two last characters, e.g.: 
    sl<C-t>
     → 
    ls
  • Alt+T: swap the last two words, e.g.: 
    foo bar<M-t>
     → 
    bar foo
  • Ctrl+U: cut the text of the current command before the cursor.
  • Ctrl+W: cut only the word before the cursor.
  • Ctrl+K: cut the text of the current command after the cursor.
  • Ctrl+Y: paste the previously cut text after the cursor. This is useful when you have typed a long command and realize that you forget to do something before, e.g.:
    1
    2
    3
    
    % ./my_long_command -v -u foobar -t -x<C-U>
    % ./do_something_before
    % <C-Y><enter> # paste and execute ./my_long_command…
  • Alt+U: uppercase the next word, e.g.: 
    ls<C-a><M-u>
     → 
    LS
  • Alt+L: lowercase the next word, e.g.: 
    LS<C-a><M-l>
     → 
    ls
  • Alt+C: capitalize the next word, e.g.: 
    foo<C-a><M-c>
     → 
    Foo
  • Ctrl+L: clear the screen, leaving the current line at the top.
  • Ctrl+_: undo (incremental).

No comments:

Post a Comment