Skip to content

Moving efficiently

Moving efficiently on the command line

class=noborder

This chart shows where different vi movement and editing keystrokes will take you on the command line, inspired by ClĂ©ment Chastagnol's "Moving efficiently on the command line", which showed the same thing for emacs key bindings. If you want to experiment with it in bash, type set -o vi to enable vi key bindings. To enable them in your shell and other readline tools:

echo 'set editing-mode vi' > ~/.inputrc
echo 'bind -v' > ~/.editrc
echo 'export EDITOR="vim"' >> ~/.bashrc

Movement

  • 0 Goes to the start of the line
  • ge End of the previous word
  • b Start of the current word
  • h Previous letter
  • l Next letter
  • e End of current word (which does not include punctuation)
  • w Start of next word
  • E End of current Word (which includes punctuation)
  • W Start of next Word
  • t/ The character before the next / (or any other key)
  • f/ The next / (or any other key)
  • $ End of the line

Editing

 $ <span style="background:#F0D0D0">cp monfi<span style="color:blue">c</span>hier.txt dir/a</span>    S         <i>Replace the entire line</i>
 $ <span style="background:#F0D0D0">cp monfi<span style="color:blue">c</span></span>hier.txt dir/a    c0  d0    <i>Replace or delete to start of line</i>
 $ cp <span style="background:#F0D0D0">monfi<span style="color:blue">c</span></span>hier.txt dir/a    cb  db    <i>Replace or delete to the start of the word</i>
 $ cp monfi<span style="background:#F0D0D0"><span style="color:blue">c</span></span>hier.txt dir/a    s r x     <i>Replace or delete the current char</i>
 $ cp monfi<span style="background:#F0D0D0"><span style="color:blue">c</span>hier</span>.txt dir/a    cw  dw    <i>Replace or delete to the end of the current word</i>
 $ cp monfi<span style="background:#F0D0D0"><span style="color:blue">c</span>hier.txt</span> dir/a    cW  dW    <i>Replace or delete to the end of the current Word</i>
 $ cp monfi<span style="background:#F0D0D0"><span style="color:blue">c</span>hier.txt dir</span>/a    ct/ dt/   <i>Replace or delete to the next `/` (exclusive)</i>
 $ cp monfi<span style="background:#F0D0D0"><span style="color:blue">c</span>hier.txt dir/</span>a    cf/ df/   <i>Replace or delete to the next `/` (inclusive)</i>
 $ cp monfi<span style="background:#F0D0D0"><span style="color:blue">c</span>hier.txt dir/a</span>    C   D     <i>Replace or delete to the end of the line</i>
 $ cp <span style="background:#F0D0D0">monfi<span style="color:blue">c</span>hier</span>.txt dir/a    ciw diw   <i>Replace or delete the current word</i>
 $ cp <span style="background:#F0D0D0">monfi<span style="color:blue">c</span>hier.txt</span> dir/a    ciW diW   <i>Replace or delete the current Word</i>
  • I Insert at the start of the line

  • i Insert at the current position

  • xp Swap the current and next character
  • a Append after the current position (the next character)
  • A append to the current line

2018 Hacks


Last update: November 8, 2020