Questions tagged [variables]

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

Filter by
Sorted by
Tagged with
0
votes
2answers
498 views

How to correctly use a local script variable

Suppose I have the following code: let s:user_config=fnamemodify('user.vim', ':p') echom 'file found: ' . s:user_config if filereadable(s:user_config) source s:user_config else echom s:...
0
votes
1answer
77 views

passing local script variables to viml functions

If I run this code: let s:user_config=fnamemodify('user.vim', ':p') echom s:user_config if filereadable("s:user_config") echom 'this is true' else echom 'this is false' endif the result will be: ...
-2
votes
1answer
39 views

How do I find out the value of an option? [duplicate]

How do I find out the value of an option? I tried: :echo ignorecase :echo g:ignorecase :echo v:ignorecase None of these work.
1
vote
1answer
435 views

How do you use variables in a search?

I'd like to pull out a variable something like this to save repeating the same thing let s:twoLinesStartingWithWords = '^\w\+.*\n\w\+.*' "next/previous definition nnoremap <Leader>n /\=s:...
1
vote
0answers
84 views

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 ...
1
vote
0answers
701 views

Invoking a command with a defined variable results in "undefined variable"

I'm trying to integrate opam-user-setup's output with vim-plug. I've produced the following: let s:opam_share_dir = system("opam config var share") let s:opam_share_dir = substitute(s:opam_share_dir, ...
2
votes
1answer
548 views

What is the difference between let mapleader =”,”, and let g:mapleader=”,”

In one of the most popular vimrc’s available (Aimx’s vimrc), there is a line which maps both leader and g:leader to “,”. https://github.com/amix/vimrc/blob/master/vimrcs/basic.vim#L58 What is the ...
1
vote
1answer
46 views

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 ...
1
vote
1answer
735 views

the scope of variable in vim

I believe the following script in vimrc, which try to set spellfile, has something to do with the scope of vim variable. Especially the difference of $var and g:var: I can't figure out what's wrong ...
1
vote
2answers
1k views

shortcut of the current directory path when vsplit/split

I very often need to open files through vsplit/split. Very often I want to open files in the same directory. Still, I must pass their paths to vsplit/split. :vsplit @/siblingfile.txt @ is an alias ...
0
votes
2answers
121 views

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 ...
0
votes
4answers
507 views

redirect exmode command to variable

This is perhaps a beginner question, but I'm unable to (intuitively) figure out how to redirect the output of an ex command to a variable for further processing. Some background: I'm trying to create ...
6
votes
1answer
382 views

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:...
-1
votes
2answers
368 views

Can't reassign local variable value from register?

Given the following block of text: title,tags Run-ons - Comma Splices - Fused Sentences Rule 1 - Run-ons - Comma Splices - Fused Sentences Rule 2 - Run-ons - Comma Splices - Fused Sentences Example ...
2
votes
1answer
777 views

vim cannot access variable in autocmd

I am trying to configure prettier-eslint and prettier-standard as the js formatter with neoformat: " neoformat should try formatprg where available let g:neoformat_try_formatprg = 1 augroup vimrc " ...
6
votes
2answers
436 views

iskeyword for latex

Context Currently, when I set ft=tex, my set isk? reads iskeyword=@,48-57,_,192-255 that is, the default for vim. My "issue" Currently, in a LaTeX string such as $\abcde_\fgh$ the w jump would ...
1
vote
2answers
1k views

Copy the values from a variable?

I set a variable b:aaa which has the value that I can see via echo b:aaa, how can I copy that to text? I know I can do it by set @a = b:aaa "ap to get it. But can I copy it to the an open file ...
1
vote
1answer
281 views

How to open a GPG encrypted file without having to choose the GPG recipient with the gnupg plugin?

I want to edit a GPG encrypted file file.asc without having to split the window to enter the recipient. The recipient can be set in the vimrc. :let g:GPGDefaultRecipients='<key ID>' How would ...
1
vote
2answers
840 views

Tell Vim's put to print a string at a position given by the value of a variable

I would like to add a new line in a certain line in a buffer. So far my starting position is as follows: let newl = "\n" " set cursor to beginning of buffer call cursor(1,1) " search up to 10 lines ...
10
votes
2answers
4k views

`set` option with variables

I am trying to rewrite adding a string to option with variable. The original string is set rtp+=~/.vim/bundle/Vundle.vim The following is the working let way: let MYVIMDIR='/home/loom/foo' let &...
1
vote
1answer
888 views

how can i assign the content of a function variable to an option?

this is what i wanted to do: function! Spell(lang) if a:lang == "off" set nospell else set spell set spelllang=a:lang endif endfunction unfortunately this does not work ;( this ...
0
votes
1answer
322 views

Substitute variable into match

This highlights the parts of the lines that are over 80 columns long: augroup over_length autocmd! autocmd BufEnter * highlight OverLength ctermbg=darkgrey autocmd BufEnter * match ...
1
vote
1answer
47 views

How can I use a register with :find?

I'm trying to improve my vim-abilities. I'm writing a command and a function to find the current Word under the cursor. What I want to be able to do is type :FindFile and have the word under the ...
0
votes
1answer
301 views

Ask a list of all percent-prefixed variables

In reading other's .vimrc, I find many percent signs. For instance in the portion concerning the status line, I know %F%m%r%h must stands for something like the current filename being edited. But ...
4
votes
2answers
4k views

Use variable for mapping inside vimrc

I'm testing NeoVim and would like to put in my vimrc universal mapping for either vim and nvim. I've sketch sth like below so far, but it doesn't work and it's very rough. function! Meta(key) " ...
1
vote
1answer
2k views

How to use a variable value in a colorscheme

I'm trying to make a colorscheme configurable where I define the style in a variable defined in my .vimrc. let g:plugin_style='<vim-highlighting-style>' Then in the colorscheme I'm doing: ...
0
votes
1answer
997 views

Use variables in colorscheme [duplicate]

I had to notice that this doesn't work: let test=128 highlight Normal ctermbg=test Is it possible to use variables in colorschemes?
0
votes
1answer
958 views

Execute curl command with variable interpolation

I'm trying to adapt this known-working snippet for installing vim-plug: if empty(glob('~/.vim/autoload/plug.vim')) silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw....
1
vote
1answer
236 views

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 ...
12
votes
1answer
975 views

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 ...
3
votes
2answers
1k views

How to handle a nested dictionary with mixed key/values?

I would like to create a dictionary variable for a vimL script. That dictionary will hold information related to a folder structure. However, I have a bit of hard time designing this variable and also ...
6
votes
2answers
3k views

Append to global variable and completion

I would like to create a global (configuration) variable that ideally would work as a comma separated list but that we could also append to it. The idea is to have the same behavior as when using += ...
3
votes
1answer
184 views

How to `unlet` a variable using from a `argdo` statement in VIM

I do have a bunch of XHTML files and I need to put an @id for all the p elements inside all those files. I have tried the following argdo approach in the following way: :cd d:\testfiles\ :args *....
2
votes
1answer
914 views

As an argument of a function, when does a variable name need to be quoted?

If I define the variable foo like this: :let foo = '~/Desktop' And I want to check the length of the string it contains, then I can type: :echo strlen(foo) The output is 9, which is right. If I ...
2
votes
1answer
165 views

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....
0
votes
1answer
204 views

Why I can't use a script variable as a function parameter in a mapping:

I have the following script variable and a mapping defined as follows: let s:tblgen_files = '-G \"\\.td$\"' nnoremap <leader>st :call <SID>PrjAck(expand('<cword>'), s:tblgen_files, "...
8
votes
1answer
142 views

How can I use consecutive numbers in an Ex-style substitute command?

For example, let's say I want to put a number before every line that starts with the word "Do". The command would look something like :%s/^(Do )/1. \1/, but what can I do so it will apply numbers ...
6
votes
1answer
609 views

Can I do array destructuring in VimL?

Can I do this in Vimscript? let [a, b] = s:MyFunc() function! s:MyFunc() return [1, 2] endfunction

1
2