Ivan Vecerina wrote:
[...]
While editing a file, I decide to rename "someIdentifier" to
"someIdentifier_" - I will need to append the underscore to
several (but usually not all) instances of the word.
[...]

Here's how I would do that:

Let's assume your current directory (as shown by ":pwd") is the top directory of the project in question, and that you want to check all *.pro, *.cpp, *.c and *.h files in that directory and below.

        :args ./**/*.pro ./**/*.cpp ./**/*.[ch]
        :argdo 1,$s/\<someIdentifier\>/\0_/gc | update

The first line sets the argument list to the project files.

The second line runs a common set of commands on all the files in the argument list, as follows:

        1,$       from first to last line of the file
        s/        substitute what?
        \<        begin-of-word (zero-length)
        someIdentifier
        \>        end-of-word (zero-length)
        /         replace by what?
        \0        the whole matched string
        _         plus an underscore
        /         start of replace flags
        g         everywhere (not only first time) in the line
        c         with "confirmation" prompt
        | update  then write the file if modified

The confirmation prompt takes care of your "...(but usually not all)..." restriction by showing you each possible replace in turn, asking for a yes/no decision. The ":update" command saves each file (if modified) before examining the next, and is not needed if at least one of 'autowrite' and 'autowriteall' is on (which is not the default).


Best regards,
Tony.
--
Sex is one of the nine reasons for reincarnation ... the other eight
are unimportant.
                -- Henry Miller

Reply via email to