"VIM001" writing the first vim script

Source: Internet
Author: User

Learn vim always see each road master in the implementation of their own plug-in, see my mouth water, also want to write the vim plug-in, so I also open dry. Start with the first script and start controlling your vim.

The first thing we want to ask is where to start learning, I search all kinds of information in the first step, but search to search, and ultimately to see the document. In the process of Google, I found the following help command, began my Learning path, so-called to take a mermaid than to take people fishing.

: Help Vim-script-intro:h Vim-script-intro

To the top of this help document, you will see this title: Write a Vim script, which is not what I'm looking for. Let's look at the first script provided by VIM and create a new script before writing the script.


~$ Vim First.vim

Description: Start is the command entered in Vim, to ~$ start is the Linux command, if you have not used Linux, that also to add Linux knowledge Oh, this article is based on Linux, oh, of course, using Linux under Windows, it is not professional, I'm joking.

Well, let's start with the script, the first example that VIM provides:

: Let i = 1:while i < 5:  Echo ' Count is ' I: let  i + = 1:endwhile

":" Can be omitted, only when you execute a command is necessary. The script is written, but how do you do it? Execute the following command in VIM

: Source ~/first.vim

~/is the directory of the current user only. The output is as follows:

Count is  1count was  2count is  3count is  4

I think it's a pity that the authors of the tutorial didn't use helloworld!

If the article ends here, I also feel that there is no need to write, directly read the tutorial vim, this is the first time I began to study vim, before all know how to use the good. I think there can be more in-depth study, keep this blog post will be summed up.

Let's start by explaining this piece of code. Let is assigning a value to a variable, and assigning a value of 1 to I, the general syntax is as follows:

: let {variable} = {expression}

We enter the following command to see a detailed description of let:

: H Let

Or to pursue a document-based purpose, if you have a problem or demand, Google has not found a half a day, you have to honestly go through the document, because the document is the best learning materials, more than any tutorial.

: let {var-name} = {EXPR1}

Assigns the value of an expression to an internal variable, the type of {Var-name} is determined by {EXPR1}, and if {var-name} does not exist, a new variable is created.

: let {var-name}[{idx}] = {EXPR1}

If {var-name} is a sequence, you can assign values to a variable in the sequence, and we create a new vim script: Let.vim

Let list = [0,1,2,3]  "Entire sequence assignment echo listlet list[0] = 1 + 2  " expression let list[1] = 2let list[2] = 3 * 4let list[3] = 5/2ec Ho list echo list[2]

Next we see how let's manipulate the two-dimensional sequence

: let {var-name}[{idx1}:{idx2}] = {EXPR1}

At this time {EXPR1} can be a sequence, we can give a sequence of the assignment of a sequence, or several sequences can be assigned simultaneously, you can assign a value.

Let List1 = [[0,1,2],[3,4,5],[6,7,8]]echo list1echo list1[0:1]echo list1[0]let list1[0] = [9,10,11]echo list1let list1[0] [0] = 0echo list1let list1[0] = [' ww ', ' Q ', ' E ']echo list1

For more let-related information, see the Help documentation for vim.

Code-managed: Https://github.com/solomon5926/vim-script

"VIM001" writing the first vim script

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.