Renaming variables in vim
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')
Published on 22 Apr 2020
all tags
100daysofcode activerecord android annoyances api apt arch array artix atom az3w backend bash blog browser bug callback career ci-cd cli cloud code coding config configuration cp crud cryptography css csv database db design devops django docker email erp feelsgood filter fugitive gif gist git gnome gnome pomodoro grep hebrew http ide isbn-fetcher iso javascript job search js kanban kindle koans learning linkedin linux logger manjaro map markdown microservices mobi mtp neovim nodejs nvchad packages panda pastbin patch portfolio post postgres pytest python rails reduce refactoring reflections rest routes rspec ruby salesforce script scripting security sed shell sql string_replacement study tdd terminal testing tmux ttd version_control vim vim sort walkthrough webdev workflow zsh