Perform Vim Normal Mode moves using the Command Line

Felippe Nardi
1 min readFeb 7, 2015

--

Lets combine two powerful Vim modes: normal mode and command line mode. Chaining both allows you to repeat the same normal mode action across several lines at once. Suppose you want to remove the last character on each line of a selection, you can simply run this:

:norm $x
Gif exemplifying “removing last character” and “wrapping lines in HTML tags”

This will repeat the normal mode action “$x” — which means: go to last character of the line ($) and then crop it (x)— on each line of the selection.

You can also combine it with Macros. It will allow you simplify repetitive and — otherwise complex — editing tasks. For example, here is how to wrap all selected lines in a HTML tag:

  1. In normal mode: Create a macro that wraps a single line into a tag
  2. In command line mode: Apply the macro in each line of the selection

Let’s say you recorded the macro on the a key, you would only have to select the lines and run:

:norm @a

This will wrap all the selected lines into HTML tags.

Hope you enjoyed and will use that soon ☺

Subscribe to A Tiny Piece of Vim for more tips like this

Unlisted

--

--

Felippe Nardi

I help you create super interactive and unique live experiences for online audiences that you can run entirely by yourself 🚀 http://instagram.com/felippenardi