I need to replace a file which has thousand of lines code.
In the log, it has a specific word which I want to replace this work with some other words.
Say, how to replace all "AA" to "BB" in this file?
thanks
Since you don't know one of the most basic and frequent commands in vi / Vim, the :substitute command, and apparently also aren't aware of the great built-in help and many many tutorials on the web (most of which cover the :s command), maybe the best approach (if you're using GVIM) is
:promptrepl
Run Code Online (Sandbox Code Playgroud)
which will bring up a search-and-replace dialog that is very similar to that in other text editors. It's even accessible through the menu Edit > Find and Replace...
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.
You want to use
:%s/\<AA\>/BB/g
Run Code Online (Sandbox Code Playgroud)
% specifies that you want to replace on all lines.
s tells vim that you want to do a substitution
Between the first / and second / is what you want to replace (ie \<AA\>).
The \< and the \> are word boundaries, making sure that AA is matched but fAA or AAg is not.
Between the second / and third / is your replacement (ie BB)
The final g says that you want to replace all occurances on a line (not only the first).
| 归档时间: |
|
| 查看次数: |
108 次 |
| 最近记录: |