> i try to remove 4 spaces in my file
> so i type
> :%s/\ \{4}//g
Just as an aside, you don't need to escape the space, so you can
just use
:%s/ \{4}//g
> now i want to replace the tab with 4 spaces
> :%s/ ^I / \ \{4} /g
>
> but it cannot work
>
> i just wonder why {n} work differently in both cases
You have one or two issues here:
1) you're searching for "space tab space" (assuming that's a
literal tab, not "carat eye") instead of just a tab. For clarity
and simplicity, I'd use "\t" instead of "^I".
2) the \{n} notation is only available in *searching* regexp
patterns, not in replacements. You can hack it by using "\=" to
do something like
:%s/\t/\=repeat(' ', 4)/g
if you need to keep the count separate from the replacement.
However, given the character count, I'd just use
:%s/\t/ /g
Lastly, if you're jiggering spaces/tab back and forth, you may
want to read up on the ":retab" command which does this all for
you based on your 'tabstop' and 'expandtab' settings.
For more info:
:help :retab
:help repeat()
:help sub-replace-special
-tim
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---