I am searching for an easy way to do search and replace things in vim as a "workaround" for refactoring.
On some other stackoverflow-question I found this snippet of code:
nnoremap gR gD:%s/<C-R>///gc<left><left><left>
I thought gD selects the current word under the cursor in the whole document and %s then search and replaces the matches after I typed the replace pattern. gc stands for globally with confirmation?!
However: This does not work as expected. For example in some python class of mine I can easy rename occurencies of self in the whole file but it does not work on method identifieres or field identifieres with a length of one.
def __init__(self):
self.test = []
self.A = []
...
So self could be changed using this snippet, but doing gR on the field A simply does not work.
How can I get this work to do an easy search and replace on one file?
Any tips on intelligent refactoring would be also appreciated. After hours of searching I just found plugins and workarounds which work mostly with C files, but I would also need at least Java, Python and PHP compatibility.
Thanks for every answer :)
UPDATE: I recently found out it just works if the initial selected pattern is on the beginning of the line. If the pattern is somewhere in the middle of the line it does not work...any ideas?