I have a line like:
contact.psu_code = row[:psu_code] unless row[:psu_code].blank?
and I want to substitute psu_code with, say contact_disposition, like:
contact.contact_dispositon = row[:contact_disposition] unless row[:contact_disposition].blank?
where it substitutes only in the single line I’m on, with no confirmation. I know of %s/orig/sub but it’s cumbersome.
What do you mean, it’s cumbersome? If you want to do a search-and-replace on a single line, you don’t need to use
%.Without
g, Vim would stop after replacing a single occurrence. By specifyingg, the replacement is done on the entire line.If you want confirmation, add
cto the options afterg.Here’s a convenience function for it:
I mapped it to
<leader>r, but you can easily change that to whatever keymapping you’d like.