On 09/14/11 08:45, Russell Bateman wrote:
   Once I've typed in a command to search and replace for something, for
example:

      %s/search/replace/g

how can I re-execute that command without retyping it? (I have a string
of source files between which I'm moving via :n each time and I don't
want to have to retype the command; dot won't work obviously.)

While you can use @: as others have suggested, that merely repeats the most recent ex command, so if you've issued other ex commands since the :s then you may want to use

  g&

(or if you didn't use the 'g' flag, just use "&")

  :help g&
  :h &

The tricky part comes if you've done a search since the most recent one, as the "g&" will use the search-register rather than the actual search-re from the most recent :s command. I'm not sure whether that's a bug, since it seems to not repeat the last :s command as documented. E.g:

  vim
  5ix<esc>
  Y5p
  5ry
  gg
  :s/x/z/g<cr>
  /y<cr>
  g&

The "g&" effectively does a ":s/y/z/g" instead of the original ":s/x/z/g".

Granted, I almost never use "&" or "g&" as the "@:" usually does the job for me (and if not, I can use ^P or <up> to scroll through the command-line history to execute it once and then use "@:" after that), but it's nice to have in the repertoire.

-tim



--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to