Questions tagged [variables]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1
vote
2answers
23 views

Gvim - Change window position horizontally

I want to create a command that will place my gvim window to a different "x" location on my screen while maintaining the "y" position. I do this in my _gvimrc by calling winpos 319 16 I want to ...
0
votes
1answer
18 views

How to use variables in a user defined command? [duplicate]

I have this user defined command: command! PS silent! w | PlugSnapshot! ~/.vim/plugins/plugins.lock How could I change it to take the filepath from a variable, something like this: let ...
0
votes
1answer
35 views

Ex command to put value of variable into terminal emulator?

Using a terminal emulator (with :term), I would like to insert the value of a variable at the terminal cursor. In a normal text buffer, I could use put =g:my_variable or exec ("normal! i" . g:...
2
votes
1answer
51 views

How to get the current mode in vim?

I'm writting scripts for vim, and I want to let the script do different things in different mode. I know that the statusline will show the current mode, but I don't know how to get the exact current ...
0
votes
1answer
30 views

How to generate a string by concatenating another string with an environment variable

I need to create a variable with a fool folder direct which need to concatenate from a environment variable and the end notes function! MyFoo(arg) let repo=$Project + "/cfora" #Q1 ...
0
votes
2answers
80 views

How to use variables? [duplicate]

I'm trying to use indent size as variable, but it doesn't work. let indent=4 set tabstop=&indent set softtabstop=&indent set shiftwidth=&indent set expandtab I tried both &indent and ...
1
vote
1answer
57 views

How to define a varialbe and refer to it later

I need to define variables who can hold number or strings. Those variables would be used later in the key mapping for example let bookMark=Lib7 //:echo boomMark do give out Lib7 nmap gb :<c-u>...
2
votes
1answer
278 views

How can I use the return value of a function in a :set command?

I want to set an option to a string containing full path of current working directory. For example set tags=getcwd()."\tags" " retrieve the full path of the tags file in current workding directory ...
1
vote
1answer
111 views

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: ...
1
vote
2answers
25 views

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?
1
vote
1answer
104 views

Give variable to makeprg

I'm trying to put the output of a command into a QuickFix list when a particular key is pressed. That command takes as its argument the word under the cursor, so my function looks basically like this (...
2
votes
2answers
124 views

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 ...
2
votes
0answers
137 views

Why gf is not working with variable?

If there is no variable in path, gf can open the file. Added sfname+={,} to .vimrc to support ${VARIABLE}. :!echo ${VAR}/test/file can correctly print full path with ${VAR} expanded. But if run 'gf' ...
0
votes
2answers
99 views

How to analyse file and get variable definition?

For example, a tcl file, how to analyse the file and get each variable's value? It can be done by reading each line, check if there is "set XXX ...", then get variable name and its value. After ...
0
votes
1answer
88 views

Statusline – update variables on file change

I'm currently learning Vimscript, but I'm stuck at a particular problem. I'm creating a statusline which shows the full path (~) of the file currently displayed in the buffer. Instead of just using %...
1
vote
2answers
233 views

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 ...
2
votes
1answer
802 views

How can I use a string variables for filepath in vimscript map command?

I have multiple lines like the once below in .vimrc file. nnoremap \html :-1read $HOME/.vim/snippets/html_basic.snippet<CR> nnoremap \bs :-1read $HOME/.vim/snippets/bootstrap.snippet<CR>...
2
votes
1answer
81 views

How to match pattern with buffer-scoped variable

Goal: write code to do block commenting/uncommenting while keeping the current indentation level. This has been solved, see here for my code Current problem: use s/// to match a line that begins with ...
0
votes
1answer
192 views

How does Vim sets 'shell'?

I have an issue with Vim in NixOS. The problem is that Vim sets to shell the path to not desired bash (non-interactive bash). So I want to know how Vim finds a shell and sets its path to shell to ...
0
votes
1answer
38 views

Vim not using variable value when changing a setting

I have the following vimscript: let g:base_path="~/.config/nvim/" let g:plugins_path=base_path."plugins/" let g:repos_path=plugins_path."repos/github.com/" set runtimepath+=g:repos_path."Shougo/dein....
1
vote
0answers
87 views

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/...
0
votes
2answers
34 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
55 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
34 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
202 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
56 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
276 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, ...
1
vote
1answer
249 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
32 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
349 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
431 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
63 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
216 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
255 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
192 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 ...
1
vote
1answer
365 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 " ...
4
votes
2answers
262 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
395 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
180 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
508 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 ...
7
votes
2answers
2k 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
473 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
205 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
38 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
192 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 ...
1
vote
2answers
1k 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
482 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
660 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
483 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....
0
votes
1answer
67 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 ...