Questions tagged [variables]

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

Filter by
Sorted by
Tagged with
1
vote
2answers
789 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
98 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
371 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
333 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
311 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
623 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
355 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
814 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
217 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
729 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 ...
8
votes
2answers
3k 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
764 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
273 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
44 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
257 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 ...
2
votes
2answers
3k 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
1k 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
909 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
770 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
173 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
952 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
969 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
2k 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
162 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
719 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
134 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
195 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
123 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 ...
5
votes
1answer
466 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