Questions tagged [vimscript]

A scripting language embedded into Vim. It can be used to customize Vim to suit your needs and to create plugins. Also called VimL.

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

Use "normal" in function

I'm writing a function to automate some task. I did this: function InitTTbuffer() " Split file and find the first imap :exe "normal \<C-w>\<C-s>/imap\<CR>" ...
Antonio's user avatar
  • 277
0 votes
4 answers
123 views

Check if a script is sourced

I use quite a number of plugins now and the init.vim script for nvim has become quite unwieldy. So I started separating out the individual configuration files for each individual plugin. And now I ...
FalcoGer's user avatar
  • 149
0 votes
3 answers
151 views

What exactly does Vim need from you to make a separate folder for your scripts?

Every coding configuration need I have for Vim works just fine if I put it all in the .vimrc file, but I'm curious: let's just say that I wanted to make my own scripts or plugins, and my .vimrc file ...
user avatar
2 votes
0 answers
33 views

How do search's b and z flags interact?

I'm using searchpos instead of search is I can echo the column where the match happens, which, with example file below coincides with the matched character. 123456789 ^ | +-- cursor is ...
Enlico's user avatar
  • 2,184
3 votes
3 answers
108 views

Auto-fix missing Python f-string prefix in insert mode

I am constantly forgetting to add the f prefix in Python when I'm within a string and start inserting a variable ("foo bar {var}"). I then do: <ESC>F"if<ESC>f{a and finish ...
Ryan's user avatar
  • 151
1 vote
1 answer
206 views

What is `normal! zvzz` in vimscript?

I found here the following command normal! zvzz But I don't know what it does.
linrongbin's user avatar
0 votes
0 answers
43 views

How can I get the number of matches of pattern without altering the search buffer nor moving the cursor?

My end goal is to be able to highlight all the matches of the word being typed and echo their number, but this question is about one specific aspect of this, which I've been having trouble with, ...
Enlico's user avatar
  • 2,184
1 vote
1 answer
60 views

How to evaluate vim script in the substitution field and put text with it?

I have to replace a lot of variables s1.size() with wa, and replace s2.size() with wb accordingly. I have made next substitution request: :'<,'>s/\vs([1|2])\.size\(\)/w\={"1":"a&...
Vladyslav Rehan's user avatar
0 votes
1 answer
24 views

How can I add more to this command?

I have been trying to make this command into a function which gets called by command, but I am not having much luck with it. " Clear registers command! WipeReg for i in range(34,122) | silent! ...
paradroid's user avatar
  • 367
0 votes
2 answers
128 views

Cannot get block-wise visual selections in vimscript?

I am searching for how to get visual selection in vimscript. And I found this: https://stackoverflow.com/a/61486601/4438921, it is great, but the only issue is that, in block-wise visual mode, I ...
linrongbin's user avatar
1 vote
1 answer
277 views

How to pass an argument for glob in fzf.vim Rg to support searching in specific files?

I am using fzf.vim plugin with ripgrep. Fzf comes with the command :RG and :Rgright out of the box that lets me to search for keywords in files. However, often I need to search for keywords in ...
Iggy's user avatar
  • 175
0 votes
1 answer
73 views

Using variable to find & replace while incrementing number with regex

Given the following text: 0 : Container( alignment: Alignment.center, padding: const EdgeInsets.all(24.0), child: RichText( text: TextSpan( ...
AdjunctProfessorFalcon's user avatar
0 votes
1 answer
42 views

My plugin got sourced first before init.lua

I make a colorscheme plugin with vimscript (the code sucks, as I've never write a plugin before), there it checks if a global var exist or not. " nvim-colors/colors/kalm.vim ... if !exists('g:...
manungsa's user avatar
0 votes
2 answers
119 views

How to format curl result into jq then redirect to Vim?

I am trying to pipe curl result to jq then to Vim, but nothing happens. If I follow the below method I get the desired result: curl --location --request GET "$url/myproj/v1alpha1/consumption"...
Samselvaprabu's user avatar
0 votes
0 answers
59 views

Is there a way to access the text currently being typed in insert mode?

From :help registers I know that the . register contains the last inserted text. However, thanks to the following autocmd, I have verified that it's content is actually updated after exiting insert ...
Enlico's user avatar
  • 2,184
0 votes
2 answers
38 views

How to combine identical ftplugin files?

I am trying to write a plugin and I observed that I have identical ftplugin files. e.g. ftplugin/python.vim and ftplugin/julia.vim have exactly the same content and it looks like the following: ...
Barzi2001's user avatar
  • 516
0 votes
2 answers
156 views

How to automatically close all the terminal buffers when closing vim with :qa?

I am wondering if there is a way to automatically force-wipe all the running terminals when quitting Vim with :qa. My attempt (that does not work): vim9script def WipeoutTerminals() for buf_nr in ...
Barzi2001's user avatar
  • 516
0 votes
2 answers
85 views

Capturing a group in a pattern used in a Vim autocmd

I need Vim to ignore the .tmpl file extension to enable syntax highlighting. How can I rewrite this: autocmd BufNewFile,BufRead *.lua.tmpl set filetype=lua to be more general? I want to match the lua ...
Nikita M. Grimm's user avatar
0 votes
2 answers
93 views

Set command-line local variable

How can I set a variable that only the current command line sees? So that :let s:one = 1 | echo s:one prints 1 but running two commands :let s:one = 1 :echo s:one errors E121: Undefined variable: s:...
minseong's user avatar
  • 2,291
0 votes
1 answer
46 views

Get index of search in substitute expression multiple times in Vim

Sorry. Although this is one duplicate question of this, but I don't have reputations now, so I can't comment on the above original question. As one workaround, I posted a new question and this is my ...
zg c's user avatar
  • 3
0 votes
2 answers
241 views

How can I write a custom formatexpr to specify the point at which 'gq' wraps?

I don't want VIM to automatically wrap text, so setting textwidth is not a solution to this problem. This comment gives a useful outline, but I'm not really sure how to go about doing this. My first ...
AmagicalFishy's user avatar
0 votes
2 answers
81 views

How to re-open the same window with the same buffer therein?

Consider the following snippet: vim9script # Set stuff in the newly created window var my_win_nr = winnr('$') var my_win_id = win_getid(my_win_nr) win_execute(my_win_id, 'wincmd L') win_execute(...
Barzi2001's user avatar
  • 516
0 votes
0 answers
93 views

How to find all the lines that match a literal string?

How to find all the lines that match exactly a given string, literally? For literally, I mean that if the string has special characters used in regex, like *, ?, etc., then they shall be consider as-...
Barzi2001's user avatar
  • 516
0 votes
1 answer
67 views

Passing arguments to function in remapping

I have the following solution in my .vimrc that allows me to wrap text with certain delimiters that works function! Wrap(action, delim) let l:delims = {'(': ')', '[': ']', '{': '}', '"': '&...
hilbor's user avatar
  • 15
0 votes
3 answers
62 views

Is it possible to chain an arbitrary number of v[global]?

I am trying to execute the following: exe 'v/' .. g:pattern1 .. '/ | v/' .. g:pattern2 .. '//' where g:pattern1 and g:pattern2 are regular expressions, but what happen is that in the returned text ...
Barzi2001's user avatar
  • 516
0 votes
1 answer
112 views

How to use BufDelete and BufWipeout when the deleted/wipeout buffer differs from %?

Consider the following script: vim9script var buffer_info = getbufinfo() g:buflist = [] for dd in getbufinfo() add(g:buflist, dd['bufnr']) endfor def g:BufListRemove() # If the buffer is in ...
Barzi2001's user avatar
  • 516
0 votes
1 answer
58 views

Default value for non existing keys in dictionaries

Is there a way to return a default value if a key is not present in a dictionary? For example, say that I have mydict = {'foo':1, 'bar': 2}. I want that if I call e.g. :echo mydict['apple'] I get a ...
Barzi2001's user avatar
  • 516
1 vote
1 answer
78 views

Map to for loop

How can I make a mapping that includes a for-loop? xnoremap <leader>y :for i in [1, 2, 3, 4] | echo i | endfor errors E121: Undefined variable: i and xnoremap <leader>y :for line in ...
minseong's user avatar
  • 2,291
3 votes
1 answer
452 views

How to yank without a buffer?

Does any kind of :call yank(register_name, "string") API exist in vim? Or at least :yank register_name "strings" - I can't find any way to yank in vimscript without modifying a VIM ...
minseong's user avatar
  • 2,291
0 votes
0 answers
79 views

How to set timeoutlen for a specific key?

My config inoremap jk <Esc> I want to use set timeoutlen=350 for this specific keymap and no other. How can I do that?
Mega Bang's user avatar
  • 199
0 votes
0 answers
44 views

How to highlight all the columns of a window?

Consider the following snippet: vim9script var winid = win_getid() var winwidth = winwidth(winid) var range = [] for lnum in range(10, 20) add(range, [lnum, 0, winwidth(winid)]) endfor var m = ...
Barzi2001's user avatar
  • 516
0 votes
2 answers
82 views

Help in defining a custom command when -nargs=? : how to determine if the arg is passed or not in the repl part?

I am struggling with this line (Vim9script): command! -nargs=? MyCommand :call <sid>MyFunc(???) What I would like to do is to replace the ??? in the MyFunc call in the above example so that I ...
Barzi2001's user avatar
  • 516
1 vote
1 answer
87 views

A problem with special character in Vim script

I'm trying to build a diacritic plugin which It's just a list of commands like ia <leader>'e é " this one is source just fine ia <leader>ae æ " This one causes error But I'm ...
ekiim's user avatar
  • 133
0 votes
1 answer
44 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
  • 516
0 votes
0 answers
41 views

in vim-script is it possible to open command-line window, like by "q:"

I would like in a vim-script to write commands that do following: Suspend the running vim-script. Open a command-line window, put the cursor into it, as normal mode "q:" does. Do ...
Anton Wessel's user avatar
0 votes
1 answer
139 views

How to set the mode from a vimscript?

If I save the result of :call mode() in a variable, how can I restore that mode later?
minseong's user avatar
  • 2,291
0 votes
1 answer
39 views

Vim custom command to execute 'c""<Esc>P'

I am trying to write a custom command that executes the following: 'c""<Esc>P', namely cut visually selected text, insert ""and paste the cut text into the quotes. I have ...
hilbor's user avatar
  • 15
-1 votes
2 answers
55 views

What's the difference between `:e foo.ext` and `:n foo.ext`

As title. Sorry for being possibly a very simple question but could anyone rephrase the answer so it can be easily understood by a beginner?
NeoZoom.lua's user avatar
  • 1,392
1 vote
2 answers
85 views

`Cmd+V`/`Ctrl+V` pasting has an extra new line

In init.vim I have the following setting to ensure the text is yanked to the system clipboard: set clipboard^=unnamed,unnamedplus In Neovim, I select the lines with visual line mode (V) and copy them ...
Wenfang Du's user avatar
0 votes
1 answer
116 views

How to make the 81st column stand out in Lua?

Like this for Vim, I'm trying to convert (with no success): matchadd('ColorColumn', '\%81v\s*\zs\S', 100) from vimscript to a Lua autocmd: autocmd({'BufRead'}, { pattern = "*", ...
Joannes's user avatar
  • 237
0 votes
1 answer
17 views

User-defined commands that call the same functions but with different arguments

I am trying to create a command that calls the same function but with different arguments, like the following: def g:MyFunction(a: string, b: bool) if b echo "foo" else ...
Barzi2001's user avatar
  • 516
0 votes
0 answers
596 views

nvim-treesitter not working; throws error E5113

I just installed nvim-treesitter and it throws me this error message when starting nvim: Error detected while processing /home/MYUSERNAME/.local/share/nvim/plugged/nvim-treesitter/plugin/nvim-...
user avatar
0 votes
2 answers
133 views

How to search within a vimscript function

I'm trying to write a vimscript function that will search for a ruby class definition. My function correctly goes to the top of the file to start the search, but then doesn't move to the given class ...
Leonard's user avatar
  • 99
1 vote
2 answers
183 views

Call original gf after remapping gf to custom function

gf doesn't work for absolute links used in Azure DevOps yaml files, p.e. - template: /devops/template/my-template.yml (It only works without the leading slash.) This is why I have created my custom ...
MaxGyver's user avatar
  • 229
0 votes
1 answer
66 views

How to use `syn` in regex match?

I'm trying to follow a link using <CR> in a markdown file. I was giving a look into the native markdown syntax file vim ships with and found a few that use the syn command syntax syn region ...
PedroSantana's user avatar
0 votes
0 answers
17 views

How can I replicate a block of text with a pattern replaced?

I have a bunch of blocks of text across multiple files that reference a common symbol (a number). I need to create several copies of this with the symbol replaced with different values of the number. ...
Curtis's user avatar
  • 101
0 votes
0 answers
42 views

Check if cursor is inside a pair of quotes

What I'm looking for is basically a programmatic version of vi", va', etc. Say my cursor is at |: function_call(arg, "stri|") I want to be able to find the location/range of the quote ...
Kyle Richards's user avatar
1 vote
1 answer
66 views

term_start won't open terminal in the desired position

If I run term_start('zsh', {'term_name': 'MYTER','vertical': v:true}) I get the expected behavior, but if I run term_start('zsh', {'term_name': 'MYTER','belowright': v:true}) will produce E475: ...
Barzi2001's user avatar
  • 516
0 votes
2 answers
82 views

Vim9script commands from command line result in E1124. Is it normal?

If I run e.g. :var a = 1 from the command line I end up in E1124: "var" cannot be used in legacy vimscript. Running on MacVim 9.0.1276. Is it normal behavior?
Barzi2001's user avatar
  • 516
0 votes
1 answer
39 views

How to predefine functions in syntax file?

I have a syntax file for CSV files. To be able setting the separator, there is a function ChangeChar() and the syn match ... terms are variable. To initialize it ; is used. But to call the SetMatches()...
Andy A.'s user avatar
  • 233

1
2
3 4 5
32