简体   繁体   English

vim中%字符的含义是什么?

[英]What is the meaning of the % character in vim?

The vim wikia page provides the following description for search and replace: vim wikia页面提供以下搜索和替换说明:

 :%s/foo/bar/g 

Find each occurrence of 'foo' (in all lines), and replace it with 'bar'. 查找每个'foo'(在所有行中),并将其替换为'bar'。

 :s/foo/bar/g 

Find each occurrence of 'foo' (in the current line only), and replace it with 'bar'. 找到'foo'的每个匹配项(仅在当前行中),并将其替换为'bar'。

... ...

I can see that the the % character causes the whole buffer to be searched. 我可以看到%字符导致整个缓冲区被搜索。

What is the meaning of the % character in vim? vim中%字符的含义是什么? Is it a variable that refers to the current buffer? 它是一个引用当前缓冲区的变量吗?

Learn how to look up commands and navigate the built-in :help ; 了解如何查找命令并导航内置: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. 你不会像其他编辑那样快速学习Vim,但如果你致力于不断学习,它将成为一个非常强大和高效的编辑器。

Here's how you would have found the information: 以下是您将如何找到这些信息:

Look up the command: :help :substitute 查找命令: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. :help [range]也会把你带到它。)这解释了%的含义,以及直接访问的help关键字。

%       equal to 1,$ (the entire file)        *:%*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM