Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Bash in vi mode with set -o vi.

Often I re-run a command but need to change the name of a file in the same directory.


mv /tmp/myfileA.txt /home/daniel/myfileA.txt

Then, I decide to also move another file:

mv /tmp/w00t.txt /home/daniel/w00t.txt

Typically I press the up-arrow key to get the last command, and press b until I get to the last slash character, and then insert the new file name. Since I do this very often, I'm wondering if there is an easy way to get the cursor just right after or on the last slash character.

Please note the above is only an example; I know I could do something like mv /tmp/{myfileA,w00t}.txt ... but often I simply type faster than I think :-)

share|improve this question

T/ puts the cursor after the last / character, so:

Up Esc c Shift+T / w00t.txt Enter

or, to replace the just first word in the file name:

Up Esc Shift+T / c w w00t Enter

or, if there are multiple words before the extension and you want to keep the extension:

Up Esc Shift+T / c t . w00t Enter

Alternatively, with history expansion:

share|improve this answer
lC is a nice touch. – jasonwryan Nov 25 '12 at 21:46
@jasonwryan actually T would have been better. – Gilles Nov 25 '12 at 21:59
Indeed: that will come in very handy. Thanks. – jasonwryan Nov 25 '12 at 22:23




  • Escape puts you in edit mode

  • Shiftf Searches backwards for the pattern:

  • /

You can then execute a number of different options:

  • Controlk: deletes to the end of the line

  • df/: the same

i Puts you back in insert mode...

share|improve this answer

Your Answer


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.