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.
vim Normal mode commands (Editing) Repeat the Last Change Your cursor will be at position 1 of line 1, and all you need to do to fix the next two lines is press j. twice - that is, j to move down a line and . to repeat the last change, which was the addition of the I .
Search for text using / or for a word using * . In normal mode, type cgn (change the next search hit) then immediately type the replacement. Press Esc to finish. From normal mode, search for the next occurrence that you want to replace ( n ) and press . to repeat the last change.
Press y to replace the match or l to replace the match and quit. Press n to skip the match and q or Esc to quit substitution. The a option substitutes the match and all remaining occurrences of the match. To scroll the screen down, use CTRL+Y , and to scroll up, use CTRL+E .
1 Answer. sed and vim are not related (well sort of, but it's far out). Their substitution commands are similar, but far from identical. Both of them use basic regular expressions, but vim has its extensions for it, and GNU sed has other extensions for it.
Specifically for subsitutions: use &
to repeat your last substitution on the current line from normal mode.
To repeat for all lines, type :%&
q:
to enter the command-line window (:help cmdwin
).
You can edit and reuse previously entered ex-style commands in this window.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With