user9221677
user9221677

Reputation:

VIM language syntax

I am interested in understanding this from the point of view of the VIM grammar:

The general syntax for the operations is (as per vimtutor):

operator [number] motion

However, for some operators like f, the syntax is:

[number] f motion

I find this confusing and mess it up almost every time. Could someone please point out the logic (from the VIM Language perspective)?

Thanks.

Upvotes: 1

Views: 138

Answers (2)

Sparkofska
Sparkofska

Reputation: 1320

In my eyes f is not an operator but a motion: fx moves the cursor to the next appearance of x.

See this example for clarification:

  • dfx "delete find x" deletes everything up to (including) the next x
  • d5fx deletes to 5th x (including)

Both examples follow the grammar operator [number] motion:

  • d operator
  • 5 number
  • fx motion

Looking at the f-command this way may clear up your confusion.

Motions are generally used to move the cursor around. They can be prepended by an operator (another example: j moves to line below, dj applies delete-operator to line below, 5dj does it 5 times).

Upvotes: 3

romainl
romainl

Reputation: 196886

f is not an operator so there's no reason to assume it should work like an operator.

f is a motion… and it pretty much works like a motion, as expected.

See :help operator for the complete list of available operators and take a look at the section to which :help f belongs.

Upvotes: 2

Related Questions