Renaming variables in vim
Published on 22 Apr 2020
If I have a method definition like this:
def foo_bar(string)
puts old_variable_name
end
foo_bar('hello')
foo_bar('goodbye')
foo_bar('au revoir)
foo_bar('auf Wiedersehen')
foo_bar('ciao')
To change all instances of foo_bar
:
- Put my cursor over the first instance
gd
(orgD
for global replacement)c
(change)gn
(new name)ESC
key.
to repeat the changes one by one.
Alternatively:
- Put my cursor over the first instance
gd
(orgD
for global replacement)c
(change)gn
(new name)ESC
key:%norm.
to rename all occurences in the buffer.
Thus…
def bar_foo(string)
puts old_variable_name
end
bar_foo('hello')
bar_foo('goodbye')
bar_foo('au revoir)
bar_foo('auf Wiedersehen')
bar_foo('ciao')