简体   繁体   中英

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.

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM