Text objects and related plug-ins in Vim

Source: Internet
Author: User

Recently on personal blog http://foocoder.com will introduce a vim plug-in every day, think of the garden has not been updated for a long time, but also to update an article.

Today, according to the request of the reader, introduce the next text object. It also introduces some of the text-related plug-ins I'm using.

The so-called text object, simply refers to a certain standard separator to identify a piece of text, such as a word, a word, a passage.

After you use a text object you will find that your move and speed in Vim has increased not 1:30.

The structure for editing commands in Vim is as follows:

 <number><command><text object or Motion>

You can see that the text object and the motion operation are exactly the same, the first is the number, such as 3w, moving forward three words.

Text objects have roughly the following:

W s P ' "" <> [] () {} <tag>

where w means that word,s represents the sentence, p represents the paragraph, and the other is the enclosing symbol introduced yesterday, and the label is represented by T.

There are two kinds of operation range of text object, one is expressed by I, it is inner meaning, that is, not including the spaces on the edge of the word, or the < enclosing symbol itself. An expression of a, which is the meaning of arround, in contrast to I, uses a to include the spaces or the enclosing symbol itself.

The edit command for a text object is a few common editing commands in Vim, respectively

' Y: Copy ', ' d: Delete ', ' C: replace ', ' V: Checked '

Say a little bit more, a few examples believe everyone immediately understand. (In the case of * are the cursor position)

Like what:

<*h2>sample title

Press CIT and the text becomes:

 

Another example:

Console.log ("Stay hungry," + "Stay *foolish")

Press Da "and the text changes to:

Console.log ("Stay Hungry," +*)

Press di again), and the text changes to:

Console.log ()

Like what

Hello worl*d

Press DIW and the text changes to:

Hello

It's easy to understand, isn't it? Did you find out why the text object would be very convenient? You can manipulate the entire text directly regardless of where the cursor is in the text. Experience the feeling of literally put flying.

Vim also allows scripting to be used to customize text objects, which is what we're going to introduce today, and these plug-ins customize some text objects.

1.CamelCaseMotion

The plug-in is to separate each word of the hump word, for example:

Get*elementsbyclassname

When Di,w is pressed, the text changes to:

Getbyclassname

Very convenient.

2.argtextobj

The plug-in defines a parameter text object within a function. Like what:

Foo (text, ti*mes, option) {}

When DAA is pressed, the text changes to:

Foo (text, option) {}

We are here for the moment today. It's almost 0 o'clock, so hurry up and send it out. Any questions can be answered to me.

Back to the column page: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.