Good VIM Scripting Guide?

I used VIM for another 10 years, but I never wrote VIM scripts (I always subjectively believed that this was one of the areas where VIM is weaker than Emacs).

Recently, the implementation of โ€œin a VIM script, I can execute normal mode commandsโ€ made my mind go โ€œah haโ€ and suddenly began to realize why the parts of the VIM script are how it is done.

normal ma10jd'a20kp 

much wider than

 Marker m = currentLocation(); advanceLines(10); Buffer b = delete(currentLocation(), m); advanceLines(-20); insertBuffer(b); 

Now the question is - what is a good resource for learning vim scripts?

Thank!

+54
scripting vim
Jan 28 '10 at
source share
4 answers

The best advice I can give is what you read:

 :help usr_41.txt 

which will give you a good overview of the basics. Then find some things you want to do and create functions for them. While you are doing this, use intensively:

 :help function-list 

to understand what all the built-in functions are. Most of them are quite similar to other scripting languages โ€‹โ€‹(albeit with a more rigid syntax), so any experience with text in Python or something else will be useful.

Also, check out the vim and Google scripting page for examples of existing scripts that can help expand your knowledge.

Lastly (and probably most importantly), donโ€™t be afraid to ask about https://stackoverflow.com/a/2128/ or the Vim mailing list , and you will have a lot of support for any problems you may have.

+57
Jan 28 '10 at 12:12
source share

Learn Vimscript Hard Way is also worth checking out.

http://learnvimscriptthehardway.stevelosh.com/

+35
Apr 14 2018-12-12T00:
source share

Al gave you a good answer . I would also add vim.wikia , which has some tips related to your question.

On a note.

I would not say that ma10jd'a20kp more elegant. I see the following problems:

  • it's pretty hard to maintain (what if the number of rows becomes a parameter?),
  • people like to redefine keys they never learned (this can be fixed with a hit :normal! ),
  • some normal mode commands have strange behavior in the side register (for example, <esc> when the cursor is on the first column),
  • it spoils the label a and the unnamed case are other scripts, or even the user can expect that their values โ€‹โ€‹will not be changed by your script.
+15
Jan 28 '10 at 12:57 on
source share

I am in a similar situation. It is still on my read list, but I just found the Scripting Vim editor . The articles from IBM DeveloperWorks are usually very good, so itโ€™s probably worth checking out.

+14
Jan 28 '10 at 11:48 on
source share



All Articles