Tip to replace text easily in VIM equivalent to Ctrl + F (search and replace)
Like all text editors VIM can search and replace text with another text, but this function is not accessible by the traditional Ctrl + F keyboard shortcut. You must type a command line in VIM to be able to do:
:1,$s/text to be replaced/text to replace it with/g
It seems a little barbaric to read, but it's very simple. Let's detail this command line:
- ":" allows to invoke a function in VIM
- "1" represents the first line of the file and can therefore vary
- "$" represents the last line of the file and can therefore also vary
- "s" the invoked command
- "/" are text delimiters. If your text contains /, it will be necessary to escape them with a \
- "g" allows to do a global search and therefore to replace all occurrences. This is an option that can be omitted.
I hope this tip will be as useful to you as to me.
Add a comment