www-gem words

It's normal to use (neo)vim

Published on

vim If you’re a (meo)vim user, you’re extremely familiar with the normal mode of course but have you ever heard of command normal (shorter norm). If yes, then you just saved yourself 3 minutes of reading ^^ Otherwise, let me try to explain this wonderful command to you.

Basically, the normal command allows the user to repeat a command across multiple lines. Let’s use this simple text block example:

The ocean is like
a sky
where waves create
my dreams.

Let’s now imagine, you need to insert the word “blue” after the first word of each lime.
You could modify each line one by one, you could use a pretty complex search and replace command, or you could use… wait, I know it… wait a minute… yes, the normal command !

To do so, select the entire block by typing vip for example. Then type :norm 0wiblue and hit Enter. That’s it.
In case, you’re not yet familiar with all (neo)vim keybindings (don’t worry you’ll grab it quickly), here is an explanation of this norm command:
0: move the cursor at the start of the line
w: move after the first word
i: switch to insert mode
blue: type “blue”

As usual feel free to create a keybinding for the norm command so you can save even more time in your days.

╭── If normal sounds too normal for a command, let’s talk about the dot command

Note that (neo)vim offers another command with similarities to norm: . Yes, this is right, I’m talking about the . command, the dot command. Hitting . in normal mode will repeat the last vim command you’ve executed.

If we take the same example as above, you could achieve the same result by:

  1. manually add “blue” on line 1
  2. move to line 2 after the first word, hit .
  3. repeat step 2 for line 3 and 4

Thanks for your read. Hope it's been useful to you.


Interact with this post using Mastodon or

Comment on wwwgem's post

Copy and paste this URL into the search field of your favourite Fediverse app or the web interface of your Mastodon server.

✄ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈

More food for thoughts? Check other posts about: #(Neo)vim