Skip to main content

Posts

Showing posts from 2018

Moving to Medium

It's been a long time since I want to give medium a try, and finally, I made some time to do it.
To get started on the new platform, I'll be doing series on "Getting programming concepts, languages and tools". If it sounds interesting to you, please take a look at the first post Getting AWK and spread the word if you like it.

I'm not going to migrate old entries to the new web site. They will remain here safe and sound!

As usual, thanks for reading!

Vim - Replace word under cursor

The way you edit text in vim is pretty much by running commands, you have a few shortcuts here and there, but most of the time is just running commands.

While I really like this approach, I do miss a replace word under cursor shortcut. To do that in "plain" vim, you have to type:

:%s/<C-r><C-w>/type_new_word_here/gc

(Where <C-r> stands for Ctrl+R, and <C-w> for Ctrl+W. That's a bit of a stretch on the mac where you only have a Left Ctrl key).

What the previous command does is to look for the word under cursor in the current file and ask you if you want to replace it with the word you have entered in the second part of the command. The flag gc tells vim that the action is global and that it must to ask you for confirmation before replacing matches.

There is not a whole lotta of typing but we can do better.

The good news is that with a bit of vimscript, you can avoid acrobatic motions and start replacing words with a copule of keystrokes.

This is the…