Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How plug-ins are configured in Vimscript's old society


May 24, 2021 Vim


Table of contents


The first thing we need to talk about is how to configure our plug-ins. In the past, this would have been a messy toss, but now we have a tool that makes it very easy to install the Vim plug-in.

We need to go through the basic configuration first, and then we'll talk about how to save trouble.

The basic configuration

Vim supports splitting plug-ins into multiple files. You can ~/.vim under ./.vim to place different content.

We'll now cover some of the most important folders, but we won't spend much time on them. When we create Potion plug-ins, we get to know them one by one.

Before we move on, we need to identify some word specifications.

I'll use "plug-ins" to represent a whole bunch of Vimscript code that does a series of related things. In Vim, "plugin" has a more professional definition, which means "a file under ~/.vim/plugins/

Most of the time, I'll use the first definition. If it refers to the second definition, I will specify it specifically.

~/.vim/colors/

Vim will look ~/.vim/colors/mycolors.vim execute it. This file should include all the Vimscript commands you need to generate your color scheme.

In this book, we won't talk about color schemes. I f you want to create your own color scheme, you should adapt it from an existing color scheme. Remember, :help be with you all the time.

~/.vim/plugin/

~/.vim/plugin/ be executed at the _Vim of each startup. The files here include the code that you want to load whenever you start Vim.

~/.vim/ftdetect/

~/.vim/ftdetect/ is also executed every time you start Vim.

ftdetect an abbreviation for "filetype detection". T he file here is only responsible for initiating automatic commands of the filetype set the file of the file. This means that they generally do not exceed one or two lines.

~/.vim/ftplugin/

~/.vim/ftplugin/ different.

It all depends on its name! W hen Vim sets filetype of a buffer to a certain value, it looks for the corresponding file under . . . ~/.vim/ftplugin/ . F or example, if you set filetype=derp Vim will look for ~/.vim/ftplugin/derp.vim Once the file exists, Vim executes it.

Vim also supports ~/.vim/ftplugin/ T ake the example we just had: set filetype=derp will tell Vim to execute all the s.vim files under ./.vim/ftplugin/derp/. ~/.vim/ftplugin/derp/ *.vim This allows you to logically split ftplugin

Because these files are executed each time filetype executed in a buffer, they can only be set with the buffer-local option! If global options are set in them, all open buffer settings are overwritten!

~/.vim/indent/

~/.vim/indent/ similar to ftplugin The file with the name is also loaded only when it is loaded.

indent file should set indentations related to the corresponding file type, and these settings should be buffalo-local.

Yes, of course you can put these codes in ftplugin file, but it's best to separate them so that other Vim users understand your intentions. This is just a convention, but try to be considerate and follow it.

~/.vim/compiler/

~/.vim/compiler is very similar to indent file. They should set compiler-related options under the current buffer with the type name.

Don't worry about not knowing what compiler-related options are. We'll explain it later.

~/.vim/after/

~/.vim/after a bit magical. The files under this folder load every time Vim starts, but only after the files ~/.vim/plugin/

This allows you to override Vim's default settings. You'll rarely need to do this, so ignore it unless you have the idea of "Vim set x but I want different settings."

~/.vim/autoload/

~/.vim/autoload folder is even more magical. In fact, its role is not as complicated as it sounds.

To be concise: autoload way to delay plug-in code loading until it is needed. We'll go into more detail and show you how to use the plug-in when refactoring it.

~/.vim/doc/

Finally, ~/.vim/doc/ provides a place where you can place documents for your plug-in. Vim's requirements for documentation are much better (see all :help so it's important to write documents for your plug-in.

Practice

Reread this chapter. I 'm not kidding. Make sure you (by and large) understand every folder we've talked about.

As an extra bonus, look for some Vim plug-ins you're using to see how they organize code files.