On 09/08/11 16:39, dmbfm wrote:
Hey guys. I'm running vim 7.3.35 on Ubuntun 11.04. And when I
type
:%s/this/that/
n
or
:%s/this/that/g
I get the same result, i.e., it always replaces every 'this'
in the file for 'that'. Shouldn't the fist command replace
only the first occurance of 'that'?
The /g flag impacts multiple matches on the *same line* rather
than all the matches in the file...just to be sure, if your text is
a little of this and some of this
and some of this and more of this
issuing your first command should change it to
a little of that and some of this
and some of that and more of this
whereas your 2nd command should change it to
a little of that and some of that
and some of that and more of that
The /g flag means that it it replaces all the matches on the same
line. If you only want to do the first match in the file you can use
:0/this/s//that
If you want just the next one after the cursor (including the
current line) you can use
:-/this/s//that
and if you want to start looking after the current line, just
remove the "-" from that.
While I didn't see anything of the like in your vimrc, there are
a couple options that trigger non-default behaviors with those
flags, so you might also check the output of
:set gdefault? edcompatible?
Both are generally discouraged for the havoc they cause in all
sorts of places.
-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