views:

784

answers:

4

In Unix the ^ allows you to repeat a command with some text substituted for new text. For example:

csh% grep "stuff" file1 >> Results
grep "stuff" file1
csh% ^file1^file2^
grep "stuff" file2
csh%

Is there a Vim equivalent? There are a lot of times I find myself editing minor things on the command line over and over again.

+3  A: 

There are 2 ways.

  1. You simply hit the . (period) key to perform an exact replay of the very last command (other than movement). For example, I type cw then Hello to change a word to hello. Move my cursor to a different word and hit . to do it again.
  2. For more advanced commands like a replace, once that you do after hitting the : key, you simply hit the : key then the ^ arrow and it fills your command line with the same command.
palehorse
But I don't want to repeat the command, I want to repeat a command(from the command line) with slightly different text.
Whaledawg
Yes, you can the ^ arrow, then change anything on the line. I am sorry I did not mention that.
palehorse
+6  A: 

q: to enter the command-line window (:help cmdwin).

You can edit and reuse previously entered ex-style commands in this window.

rampion
Nice tip, did not know about that one.
palehorse
Not exactly what I was looking for, I wanted a quicker way. But this is really good info because now I could at least write a function to do what I'm looking for. Thanks.
Whaledawg
A: 

Take a look at this: http://vim.wikia.com/wiki/Using_command-line_history for explanation.

Zsolt Botykai
+1  A: 

Once you hit ":", you can type a couple characters and up-arrow, and it will character-match what you typed. e.g. type ":set" and it will climb back through your "sets". This also works for search - just type "/" and up-arrow. And "/abc" up-arrow will feed you matching search strings counterchronologically.

le dorfier