Question

I noticed some syntaxes when i use vim

for example

[<motion>]<operator><motion>

e.g.

<gg><d><G> // delete from the top of file to the bottom of file
    <d><G> // delete from the current line to the bottom of file

and for

<operator><operator>

e.g.

<y><y> // inline copy
<d><d> // inline delete
<>><>> // inline right-indent

OK, something like these.

For the syntax or the way to combine the command i know just a few patterns.

And for me i think there are so many ways to combine commands on vim it looks too messy for me

I think Vim should have a basis of command.

I would like to know that

Does vim have a certain syntax to combine the commands?

Can you give me a further information about this?

Was it helpful?

Solution

Think of actions as sentences and commands as words in that sentence: verbs, objects, prepositional phrases, modifiers grouped in that sentence according to a grammar that (like most grammars) has its corner cases but makes a lot of sense overall. Hell, Vim even has transitive and intransitive verbs!

The basic rules are really quite simple:

{count}operator{motion}
{count}operator{text-object}

If you have a clear idea of the action you want to perform, using Vim's language is almost friction-less.

"Cut this block of lines and paste it below the function signature." could become:

dip                           " cut this paragraph
?func<CR>                     " move the cursor to the first func above
p                             " paste

instead of the incredibly convoluted:

<Home>                        " move the cursor to the start of the line
<Shift><Down><Down><Down>     " select the block I want to move
<C-x>                         " to cut the selection
<Up><Up><Up><Up><Up><Up><Up>  " move up to the target
<End>                         " move the cursor at the end of the line
<CR>                          " open a new line 
<C-v>                         " (finally) paste those lines

(edit)

The example above stands as a good illustration of the beauty of Vim's editing model: there's very little to none "delta" between what you think and what you actually do. In more traditional editors, that "delta" can be huge because of all the completely unrelated steps necessary to perform a given task. Because using Vim is like speaking a language with your fingers, you only have to think in that language to be efficient. What you gain from that is more than speed.

(endedit)

"Paste 6 times." becomes the awesome:

6p                            " paste 6 times

instead of:

<C-v><C-v><C-v><C-v><C-v><C-v>

Other interesting rules:

  • lowercase motions (bwe) work on keyword characters-delimited words,
  • uppercase motions (BWE) work on whitespace-delimited WORDS,
  • some uppercase operators (FTP) work just like their lowercase counterparts but in the opposite direction,
  • some uppercase operators (IA) work like their lowercase counterparts but on the extremities of the line,
  • some other uppercase operators (YCDVS), like doubled lowercase operators (yyddcc) are shortcuts for very common operator{motion} sentences…

Glts has written an awesome article on the subject.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top