VIM: parameters, variables and conversion between two

I am confused about this in VIM. Some things need to be installed, while others need to be allowed. And how can I check a specific option. I know this is an option because I use set to change it.

For example, how to check if the current parameter is filetype java?

+4
source share
3 answers

: set is used to display parameter values, explicitly indicating option values ​​and switching them, and: let it be used to set parameter values ​​as a result of some previous expression (when you determine the parameter value by a variable). Naturally, in vim scripts you will use: albeit more.

For instance:
you usually set the file type with

:set ft=batch 

but you can also

 :let varijabla='batch' :let &filetype=varijabla 
+6
source

Options

All of these options will change Vim's behavior anyway. Many of them should be used to customize your Vim: you can set the method for processing backup files, how to manage text, display menus and toolbars, as well as many other things. Several parameters are local to the buffer or window; they indicate, for example, that syntax highlighting and padding should be used in the buffer. The :set command can be used to set and print a parameter value, see :help :set . You get a list of all parameters with a one-line description if you type :h option-list . You will get a list of all the options with their long description if you type :h option-summary .

Internal variables

Internal variables are two different things: they are like variables in a program. You can create or destroy a variable at any time. They will not affect Vim behavior on their own, only through Vim scripts (for example, Vim plugins and your .vimrc file) that can read (and change) their value and do different things based on this. There are several types of internal variables: global variables, local variables, and some others. They are described in :h internal-variables . They are evaluated in expressions ( :h expression ) and can be installed and removed using let ( :h :let ) and unlet ( :h :unlet ).

Variables in an expanded sense

There are other objects that behave like variables, but are not internal variables. They are also evaluated in expressions, and their value can be set using the let command; but they cannot be deleted. There are three types of variables, besides the internal ones: environment variables ( :h :let-environment ), register variables ( :h let-register ) and optional variables ( :h let-option ). They all have a prefix so that they can be distinguished from internal variables and from each other. Environment variables are prefixed with $ , register variables with @ and optional variables with & . These variables point somewhere (to the real environment variable, register or option), and when their value is read or set in the script or by the user, the value of the "real thing" is actually read or set.

+11
source

I just got it by exploring a few more: To get the parameter value, the & option prefix.

therefore, the above can be done as

 if &filetype == 'java' 
+9
source

Source: https://habr.com/ru/post/1285660/


All Articles