I’ve to replace all occurrences of a specific macro inside some(only some amongst dozens) C functions. Since the file is thousands of lines long, with several instances of the macro in all the functions, I’d like to replace all occurrences within the particular function the cursor is currently placed.
I know VIM provides navigation commands (like [[ to go to the beginning of the current function, and then % to find its matching closing brace) , but I can’t figure out how to use them to come up with the required search-replace command.
Can anyone help ?
I’ve to replace all occurrences of a specific macro inside some(only some amongst dozens)
Share
Place your cursor on the first opening brace. Then type
v%and you will see the function body get highlighted. Then type the replacement command:s/find/replace/gand hit enter. This will replace within the selected function.Note: You will see you command prompt change to:
:'<,'>:s/find/replace/g.