Linked Questions

0 votes
2 answers
204 views

How do you use a variable as argument to another vim command? [duplicate]

I have the following function: fu! EditFileInBrowser() let l:url = @+ let l:url = substitute(l:url, 'http:\/\/127\.0\.0\.1:4000\/', '', '') let l:url = substitute(l:url, '/$', '', 'g') let l:...
StevieD's user avatar
  • 1,472
1 vote
1 answer
113 views

Use variable in vim mapping async task [duplicate]

I am trying to use a variable in this mapping: let board_ip = "192.168.100.18" │ nnoremap <F6> :AsyncRun echo . ...
Chris's user avatar
  • 141
0 votes
0 answers
24 views

how to reference variables in config [duplicate]

Let's take undodir as an example; we might have something like this in our vimrc: set undodir=$HOME/.config/nvim/undo/ In order to make config platform-agnostic one might want to use variables ...
laur's user avatar
  • 159
1 vote
0 answers
19 views

Return value to custom function [duplicate]

I'm writting a function to integrates NERDTree with Ack. The goal is to create a "Find in Directory". I create this: function! Fif_NERDTreeGetPath() let nodePath = g:NERDTreeFileNode.GetSelected()....
Diego Somar's user avatar
0 votes
0 answers
13 views

autocommand variable is not substituded [duplicate]

let Dropbox = "/usr/Dropbox" ... autocmd BufNewFile *.php 0r Dropbox/vim/templates/php_start.txt The variable 'Dropbox' is not substituded by its value
lima2018's user avatar
24 votes
3 answers
15k views

How to use a variable in the expression of a 'normal' command?

How can one use a variable when executing something via normal! in vimscript? Example: function! MyFunction(someArg) normal! (a:someArg)l endfunction This should move the cursor someArg steps ...
user avatar
0 votes
1 answer
3k views

how to use variables in vimscript shell commands

I have this code intended to: read current line extract variable from end of line, looking for text like #ad04e482 search for filename that begins with the string ad04e482 open that file to edit in ...
alec's user avatar
  • 785
2 votes
2 answers
768 views

Insert output of function with variable into buffer

I'm trying to make a vim function that takes a variable and uses that as part of a shell command and buts it into the current buffer. I tried using read but that just interprets the var as a string. ...
hemlock's user avatar
  • 23
2 votes
2 answers
656 views

How to `source` a path stored in a variable in Vimscript

tldr: The title pretty much summarizes the entirety of the question I am trying to make my configuration more adaptable to different machines so that I can use git to keep them in sync between my ...
Riley Hughes's user avatar
0 votes
2 answers
991 views

Can I use a variable in autocmd pat?

I have 3 languages and any can be a source or target so I need some flexibility. I am successfully loading a language translation specific setup with this: let g:tr_source = 'dyu' let g:tr_target =...
Boyd's user avatar
  • 209
0 votes
1 answer
297 views

Use normal command output as variable

I want to be able to use some normal commands I tend to use in the day to day as an input for another function, for example 4X, I would like 4X to be expanded to XXXX and then use it in a function as :...
Hassek's user avatar
  • 103
1 vote
3 answers
263 views

How can I set path of vim from the shell command result

I'd like to set c++ header file path automatically from .vimrc. So I tried to write .vimrc file as shown below: let g:gcpp_headers_path=system("g++ --version | grep g++ | awk '{print \"/usr/...
Jumogehn's user avatar
  • 165
1 vote
1 answer
532 views

Custom key binding for project-wide search and replace using FZF.vim Rg function?

I know that one can do a project-wide search and replace using the results of an Rg search in FZF.vim by doing the following: Run :Rg SEARCH_TERM Use Alt + a (or in my case, Esc + a, since I'm using ...
rplee's user avatar
  • 177
1 vote
2 answers
278 views

switch current directory between a base directory and current file directory

Goal: To achieve filename/path completion relative to current file directory using file name completion CTRL-X CTRL-F. I open all my files contained in a base directory such that :pwd in some_file ...
Haslo Vardos's user avatar
1 vote
1 answer
364 views

How can I use a variable line number with a command?

I want to move a line to another specified in a variable. So where I might do this to move the current line up seven lines: :m-7 I want to do it with a variable line destination. Something like this: ...
markling's user avatar
  • 349
0 votes
2 answers
198 views

VimScript: Substitute string variable content for string variable name

I would like to the present working directory (:pwd) be changed across all tabs and subwindows at the same time. I tried: let PreferredPWD=expand('%:p:h') " The desired working directory " ...
user2153235's user avatar
1 vote
1 answer
196 views

How to create key-mapping for vimgrep with dynamic values for {file} argument

Problem I am trying to create a more dynamic mapping for vimgrep. Many project directories I work in don't have consistent names for directories in which source/test code lives (ie. test vs. tst). I ...
clarkjoe's user avatar
0 votes
1 answer
172 views

vim mapping diffput / diffget to Ctrl+Left / Ctrl+Right with working buffer selection from count

Pretty new to mappings in Vim, In Diff Mode I've got C-Up and C-Down mapped to [c and ]c for diffjumping. I'm wanting to map C-Right and C-Left to :<C-U>diffput v:count<CR> and :<C-U>...
Jack T's user avatar
  • 1
1 vote
1 answer
96 views

vim expression unusual behavior

While playing with map() I get an error, which I cannot understand. In essense, pu=map(getcompletion('*','event'), '"h" . v:val') pu=map(getcompletion('*','event'), "'h' . v:val") pu=map(...
qeatzy's user avatar
  • 960
1 vote
1 answer
151 views

How to invoke Linux shell env variable into vimrc?

How to invoke Linux shell env variable into vimrc ? I split vimrc configurations into multiple files and included these files in vimrc via :runtime [file]. This works well. :runtime vimrc.d/vimrc....
Robert Hu's user avatar
0 votes
1 answer
124 views

How to use variable in syntax match

I have made (better said got) a syntax file for CSV files. This works fine so far. But there is the semicolon used as seperator. I want to be able to change the seperator e.g. by a function / mapping /...
Andy A.'s user avatar
  • 233
3 votes
1 answer
69 views

How can I rename the current buffer to the current time?

I have tried :file strftime("%H%M") But this sets it to literally "strftime("%H%M")". My motivation for this is that I have a mapping for :term cmake and I end up with a ...
KangarooChief's user avatar
0 votes
1 answer
62 views

How do I use variables with the delete command? (i.e., how to expand/reference variables for command arguments?)

I'm using variables for line numbers, and I want to delete a range of lines using these variables. How do I do that? let x = 5 let y = 20 " I want to delete the range of lines from x ...
Rob Bednark's user avatar
0 votes
1 answer
45 views

Add a string at the beginning of a line through builtin functions

I am practicing some vimscript and, although there are very good plugins out there, I am writing a function for commenting/uncommenting code for the matter of experimenting. So far, I wrote the ...
Barzi2001's user avatar
  • 536
0 votes
1 answer
43 views

add python option in vimrc

For my fortran ft I use au BufWritePre <buffer> :silent %!fprettify --silent in my ftplugin. The fprettify is a python script with many command line options, using argparse. Now, my question is,...
BaRud's user avatar
  • 481
0 votes
1 answer
50 views

Is it possible to call a shell command which includes default register contents inside a function?

I want to write a function which opens a vim plugin's Github page, eg calling the function while on this line: Plug 'tpope/vim-rhubarb' ... will do !open https://github.com/tpope/vim-rhubarb. Here's ...
Zubin's user avatar
  • 101
0 votes
1 answer
35 views

How to put sync region start=<this> into a variable?

I have the following code: com! -nargs=* ShFoldFunctions <args> fold ShFoldFunctions syn region shFunctionOne start="^\s*[A-Za-z_0-9:,][-a-zA-Z_0-9:]*\s*()\_s*{" end="}&...
KamilCuk's user avatar
  • 265