The vim wikia page provides the following description for search and replace:
:%s/foo/bar/g
Find each occurrence of 'foo' (in all lines), and replace it with 'bar'.
:s/foo/bar/g
Find each occurrence of 'foo' (in the current line only), and replace it with 'bar'.
...
I can see that the the %
character causes the whole buffer to be searched.
What is the meaning of the %
character in vim? Is it a variable that refers to the current buffer?
Learn how to look up commands and navigate the built-in :help
; it is comprehensive and offers many tips. You won't learn Vim as fast as other editors, but if you commit to continuous learning, it'll prove a very powerful and efficient editor.
Here's how you would have found the information:
Look up the command: :help :substitute
:[range]s[ubstitute]/{pattern}/{string}/[flags] [count]
Ah, the stuff in front is called range . Further down, there's a link to it:
Also see |cmdline-ranges|.
( :help [range]
would have also taken you to it.) And that explains the meaning of %
, as well as the help keyword for direct access.
% equal to 1,$ (the entire file) *:%*
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.