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')
all tags
activerecord android annoyances api apt arch array artix atom az3w backend bash blog browser bug callback career cli cloud code coding config configuration cp crud css database db design devops django email erp filter fugitive gif gist git gnome grep hebrew http ide isbn-fetcher iso javascript job search js kanban kanban\ kindle koans linux logger manjaro map markdown microservices mobi mtp neovim nodejs packages pastbin patch post python rails reduce refactoring rest routes rspec ruby scripting security sed shell sql string_replacement study tdd terminal testing version_control vim walkthrough workflow