Questions tagged [variables]

For questions about vimscript variables, their scopes, and usages.

Brief intro

Vimscript has variables (:h variables) and scopes (:h internal-variables) for use when programming vim. Most of their usage is via statements like let or execute.

See :help eval for more information.

Use this tag if...

  • you have questions about using variables
  • you have questions about scope rules

Do not use this tag if...

  • you have questions about programming languages other than vimscript (if you have questions about using a programming interface, like python, use e.g. )
  • you have questions about other definitions of the world variable (such as susceptible to variation)
115 questions
13
votes
1 answer

Talking to vim from outside

Can I change a variable in an instance of vim from another shell (without sending keys through tmux)? I ask because I would like to use latexmk's compiling_cmd, success_cmd, and failure_cmd options to show compilation status on the…
Toothrot
  • 3,129
  • 13
  • 27
6
votes
1 answer

Are the internal g:, b:, w:, etc dictionaries documented?

I knew you could scope a variable by prefixing it with g: b:, etc. but I only just discoverred that the prefix itself references a dictionary containing all the scoped variables. For example, :echo b:c_minlines 50 and :echo b: {'c_minlines': 50,…
ivan
  • 1,450
  • 1
  • 11
  • 16
4
votes
1 answer

How to open a file with variable in the path?

gf runs fine with absolute or relative path. Is it possible to open a file with variable in the path? For example, in a tcl file: ... set FILE_ROOT /user/abc ... read_file ${FILE_ROOT}/some/path/abc.txt How to open ${FILE_ROOT}/some/path/abc.txt…
Fisher
  • 1,086
  • 2
  • 13
  • 28
3
votes
2 answers

Listing global variable

Is there any way to list all global variable? I'm guessing i could maintain a list where multiple value represent a global variable but that feel a bit weird. is there an official way to do that? (looked into the docs but didn't find anything) I'm…
Nordine Lotfi
  • 683
  • 4
  • 16
3
votes
2 answers

How can I get the list of variables I defined?

For convenience, I'd like to define some variables. But I worry that I may forget their names. How can I get a list of them?
Tokubara
  • 167
  • 6
3
votes
2 answers

How to dynamically define variables?

Want to read variable definitions from a tcl file, then dynamically define vim global variables. set PATH_A /full/path/a set PATH_B /full/path/b other_tcl_commands Read one line, split by space and save to list. Use list[1] as variable name and…
Fisher
  • 1,086
  • 2
  • 13
  • 28
2
votes
1 answer

Strange behaviour when using variables

When I try to use a file name in a variable for the cs add command, I cannot understand what happens. I'm using a bash script myscript.sh which returns the path name of cscope database (/mydir/cscope.out) based on the current file name…
Al Berger
  • 393
  • 1
  • 11
1
vote
1 answer

Sharing variables between different files in a plugin

Supposing I have two scripts that share variables. What is the preferred way to do this, supposing I wanted to keep the variables only in one place? Is there a way to keep them script-local and not global? Context: I'm writing two syntastic syntax…
user2598
1
vote
2 answers

How to get dynamic hex format variable width with leading zeros?

strlen(var) can return length without leading zeros. How to include leading zeros? Example let var=0x00001234, width shall be 8 instead of 4.
Fisher
  • 1,086
  • 2
  • 13
  • 28
1
vote
1 answer

Is there a way to get a tab-local variable for a tabpage that is not currently activated

I want to retrieve a t:varible for a different tabpage that is not the current tabpage. How can I do it without switching to that tabpage? I know its tabpagenr. How about window local variables w: and buffer local ones b:?
doraemon
  • 1,667
  • 11
  • 27
1
vote
2 answers

How to edit variable's content?

For example, I've used redir command to redirect command output to register a. Register a contains several lines of text. How to remove a line from register a or substitute a string from it?
Fisher
  • 1,086
  • 2
  • 13
  • 28
1
vote
2 answers

How to quickly edit vim variable content?

In vim I sometimes want to quickly change the content of a variable using its current content as template using vim editing capabilities. For example I want to append the word "bar" to the existing variable myvar. let myvar="foo" A possible…
1
vote
0 answers

why is b:changedtick never zero?

As the Title states b:changedtick is never zero. No plugin or special setting seems to be involved. Even : vim -u NONE -U NONE :echo b:changedtick returns a value != 0 The same happens if I start vim with a filename (no matter if the file exists)
Naumann
  • 2,759
  • 1
  • 11
  • 16
1
vote
1 answer

variable names prefixed with &

It seems that & followed by an option name is an variable containing the option value, such as &diff. What is &l:diff. I assume it is the local value for diff option, but I cannot find the doc that mentioned this. (I found the example in…
doraemon
  • 1,667
  • 11
  • 27
1
vote
2 answers

Find value of variable when it is not set (timeoutlen)

How can I find out the default value of a variable if it is not set? For example, the default timeout for the leader key is controlled by the timeoutlen variable, but if I do: :echo timeoutlen I get an "undefined variable" error. Is there any…
Tyler Durden
  • 2,091
  • 2
  • 23
  • 42
1
2