This page looks best with JavaScript enabled

Language of VIM/NEOVIM

 ·  ☕ 3 min read  ·  ✍️ Syed Dawood

The first thing that may come to your mind when I say language of vim is Vim Script.No that's not what I am talking about.I am talking about the patterns of keystrokes that recur over and over through your use of vim.

Construct A, Single alphabets

These are most common and most basic of all constructs ,It serves as main building block in vocabulary of language you are about to learn.It includes all the commands that are used in normal ,command mode and visual mode.

Constructaction
y/Y/yy/Yank
p/PPaste
x/X/ddCut or Delete
i/I, a/A , o/OInsert
v/Vvisual
:command mode
@cmacro
hjkl,f/F, e/E , w/W,b/B and many moremotion
  yy
  p
  dd
  v
  A
  B
  k
  c
  @b

Construct B: [count][Contruct A]

Construct B comes into picture when you want an action to be repeated several times. Count or range is usually a positive integer. Almost every vim command supports repetition using count. However there are some that behave differently from others, like appending a count to v or V will be multiplied n times the count or even entire file is selected if the file type is markdown ..Works fine with text and php,python files.

  3yy
  29dd
  6A
  9i
  32v
  5p
  17@y
  7W
  12: "and soo no

Construct C: [motion] or [i|a][motion]

In order fully understand the working of this construct, you must be familiar with types of motion that vim offers.I won't be going over them.It is also important to remember that this construct will not work with all commands you can experiment this construct on different commands.This construct does not work with Macros and for some constructs motion is insignificant.

  cw
  yW 
  c$ 
  dB
  yiw
  vap
  di} " or di{
  ci] " or ci[
  ya)

Construct D, [count][Construct C]

The fourth construct is extension of 3rd one,sometimes I wonder how a simple text-editor written in a period of early days of computation is capable of such complex operations and can compete with just any other editor or IDE. Okay , back to the topic.

  5yw
  20dw
  2viw
  23vi

Construct E, [count]"[char] in normal or ctrl-r in Insert/command mode

The odd one out, This construct is different from previous ones.It is allowed for only yank and paste operations.There is a catch , range only works in normal mode.primary use of this construct is to edit or delete content of a register, well why you might want to do that ? because Macros execute the content of registers.By the way if you want to know more about registers , Please check this post.There may be cases when you recorded a register which is just right but not completely what you want it to be and you dont want to re-record macro.You can paste the contents of register make the changes and yank it back to same register.

  "Insert or Command mode
  <c-r>ap
  <c-r>ayy
  "Normal mode
  "ap
  "ayy

Conclusion :

Your brain loves patterns and things that can be easily related to what you already know. Vim is complex , you need years of practice to master it and even after all those years you find something that you didn't know was possible or existed in vim.

Share on

ALLSYED
WRITTEN BY
Syed Dawood
< frontend | backend | fullstack > Developer