How can I operate on a search match?

The ‘gn’ command makes it easy to operate on regions of text that match the current search pattern. By default, it will search forward for the last used search pattern and visually select the match. If the cursor is already on the match, it will be visually selected. If you used the ‘gn’ command after an operator (e.g. ‘c’ to change text), it will be applied on the match. If Visual mode is active before using gn, the visual selection will be extended until the end of the next match. The ‘gN’ commands works similar but searches backwards. This allows to repeat simple operations on each match. For example, you might want to change each occurence of apples by peaches. So you search using ‘/apple’ then you can use ‘cgnpeach<esc>’ to replace the current match by peach. Now you can use the dot ‘.’ command to redo the replacement for the rest of the buffer.

Read free Software Algorithms and Computer Science Books by CodeAhoy Learn.

Introduction to Recursion and Backtracking

Sorting Algorithms

Introduction to C Programming Language

And More...

Speak Your Mind