Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

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
0answers
36 views

Find out last used text object

I'm trying to figure out a way to make a repeatable operator insert. To do so I'm trying to make use of tpope/repeat. My idea is to set a repeatable call that repeats the last operation, repeating the ...
1
vote
0answers
54 views

What happens when error occurs during cdo?

:h :cdo says: When an error is detected execution stops. The last buffer (or where an error occurred) becomes the current buffer. Let's see what really happens: ...
0
votes
0answers
31 views

Is there a SafeState equivalent in neovim?

I have the following function that I'm porting to neovim: " --------------- " Auto record visual mode " --------------- " Allows executing operators with a different syntax. " First we go to visual ...
1
vote
1answer
29 views

Detect that user pressed ESC in getchar()

It looks like quite a simple question, but I cannot find an answer. Is there a way to detect that the user pressed ESC key while waiting for user input in vimscript? I would like an intuitive way to ...
0
votes
3answers
40 views

Redirect output of vim command to external program

I would like to filter the output of vim commands with fzf. The idea is for example, if I use vim unimpaired plugin and I don't exactly remember which map was to navigate to the next git conflict but ...
3
votes
2answers
258 views

What is the proper way to allow the user of a plugin to modify settings?

So I have a plugin that I am writing which should allow the user to set whether they want to enable a feature. I want the feature to be disabled by default, and allow the user to change it by adding ...
0
votes
2answers
41 views

Is it possible to reverse an existing highlighting group?

Is it possible to automatically create a highlight which is the reverse of an existing highlight? Example highlight Search guifg=Black guibg=Yellow, becomes highlight CustomHighlight guifg=Yellow ...
6
votes
1answer
889 views

Visual scrolling/visual <C-e> and <C-y> across wrapped lines?

This has been asked on stackoverflow before, but it seems it still has no solution. Perhaps that has changed with Vim 8.0. I'd like to be able to scroll (i.e. scroll-wheel, or <C-y>/<C-e> ...
0
votes
1answer
20 views

Why doesn't i<Ctrl-R>=expandcmd('se shm') work?

I'm trying to do i<Ctrl-R>=expandcmd('se shm') and more generally i<Ctrl-R>=expandcmd({expr}) but I'm just getting the literal {expr} inserted. When I type :se shm<CR> I get the ...
0
votes
1answer
60 views

Using %:p when path has space in it

I have this bit of vim script: nmap <F9> :w<cr> \:execute 'silent !tmux new -ds blah'<cr> \:execute "silent !tmux send-keys -t blah '%:p' Enter"<cr> \:execute 'silent !...
7
votes
2answers
392 views

How to source a part of a file

I can source a file, e.g. my vimrc with :so % or :so <filename>. But what do I do when I need to source only part of a file. I want some way to visually select a portion of the file with :h v ...
0
votes
0answers
21 views

Neovim highlight syntax region inside typescript tagged template literal

I am having trouble fixing a syntax plugin for Vim. I've found a bug in a plugin that has not been touched in a fair amount of time. I want to address it myself but I believe I am lacking in a lot of ...
0
votes
1answer
20 views

Calling a function when timeoutlen expires and retrieving the input command

This might be quite challenging, but I would like to achieve the following behavior. Imagine that I have two mappings that overlap: dcb := delete comment block := delete comment block (all adjacent ...
1
vote
2answers
53 views

Send keys to a terminal buffer

I want to map a keyboard shortcut to execute the last command in a terminal buffer that I have open. I've made some progress: I am storing the buffer's channel id correctly but when I try to send ...
0
votes
0answers
15 views

Spell check operator

Is there a way to run the spell checking for a single text object instead of the entire file? I would like to do something like: gsip (go spell in paragraph) I've found a gammar check operator: ...
0
votes
1answer
13 views

How to fix incorrect highlighting from 'matchpairs' caused by setline()

when using setline() to insert brackets, matchpairs does not do its job correctly. Using these commands fu Test() cal setline(".", "()") endf au TextChangedI * cal Test() set up the text ( ) ...
0
votes
1answer
72 views

How to automatically execute a command every time visual mode is entered and every time normal mode is entered

I would like to execute a command every single time I enter visual mode and another command every time I leave visual mode. Is there a way to achieve this? My objective is to automatically record ...
4
votes
2answers
132 views

Diffing two time stamps under selection

Is there a way to make a function in vim that takes the difference between two time stamps under highlight? For example: 1 20:37:00 2 20:42:30 Supposing you highlight lines 1 and 2 and run the ...
1
vote
1answer
25 views

Calling g@ from a a vimscript function

I want to call g@ from a function. Given an operation: " Taken from :help g@ function! CountSpaces(type, ...) let sel_save = &selection let &selection = "inclusive" let reg_save = @@ ...
1
vote
1answer
21 views

Error With Simple Function Using setline()

I'm trying to start writing some Vim Script, and I've come across this issue. fu Test() call setline(1, getline(".")) endf autocmd InsertCharPre * call Test() This is in my .vimrc. When I type ...
13
votes
1answer
7k 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 ...
1
vote
0answers
33 views

How to use actual window size to control vim settings?

Background: neovim with tagbar plugin installed Goal: when starting nvim, if current window size is larger than 100, open tagbar and set auto-open for new buffers. Currently I use the settings below ...
0
votes
0answers
33 views

Is it possible to replace tildes representing empty lines with another character?

I'm writing a plugin which needs to replace the empty line tildes with with a '.' character in a single window split. Is this possible to do with Vimscript?
1
vote
1answer
76 views

How to change string at specific byte index nicely?

I want to change 3rd byte of a string to x, i'm currently using this code: let s = s[:1] . 'x' . s[3:] It's a bit awkward, i wish i can do let s[2] = 'x', but that's not allowed. Are there any ...
21
votes
2answers
6k views

Extract the result of a shell command to a variable in a .vimrc file?

In my .vimrc file, I would like to store in a variable the result of an external command, in my case : $ echo $LANG So that my vimrc file would have : let language = output(!echo $LANG) if language ...
2
votes
2answers
37 views

Two consecutive identical calls to echo have different output

Question reposted on StackOverflow, where it's receiving more attention. Given the following function in the .vimrc file, fu! MyFun(count) echo a:count echo a:count if a:count > 0 ...
3
votes
1answer
22 views

Record all line-number fold-levels and restore fold-states (despite fold-level change)

I have found myself so extraordinarily frustrated with Vim's foldmethod=syntax behavior that I've contemplated dropping the editor entirely, despite being mostly happy with it for a few years now. ...
0
votes
1answer
494 views

Integrating autocomplete and snippets

I'm trying to set up an autocompletion/snippet workflow that's a bit complicated. This is stemming from needing a better workflow for latex. Right now I'm using coc.nvim and UltiSnippets but I am ...
1
vote
1answer
32 views

vim8 - why does my 0read not read? [closed]

I have the following function in an autoload file: function! closet#FindSkeletonForFile() if exists('b:closet_skeleton') return 0 endif let b:closet_skeleton = s:closet....
10
votes
2answers
2k views

What does `idem` mean in the VIM docs?

One example would be in the List docs: :unlet list[3] "idem
1
vote
1answer
18 views

How to get a function to print something to colon command and let user edit it?

I need to write a function that when executed it opens colon command and paste some stuff on to it and let user edit it before executing the command. for example function! EditRelativePath() :e ...
1
vote
2answers
114 views

Review: git branch in statusline

I am learning vimscript, and below the part of my .vimrc used to display the current git branch in the statusline. I am aware that there are ready-made options out there, but this is more of an ...
2
votes
1answer
33 views

Standard way to implement a :tselect-like menu?

In the context of developing a plug-in, what is the most portable (various versions of vim, nvim, ...) and readable way to implement a "menu" similar to what :tselect gives i.e. that appears in the ...
1
vote
2answers
53 views

Toggle between two most recent syntax highlighting settings

I often nest one programming language within another (e.g. HTML inside python). This can be done per-language, and written items in ~/.vim/after/syntax/ for that purpose, but I don't have the patience ...
1
vote
1answer
66 views

How do I make this vimscript function (taken from another question here) 'forget' about a previous search term?

Based on the accepted answer to this previous question, I put the code below in my .vimrc, which changes the color of my statusline depending on whether my search (started with / or ?) yields results ...
0
votes
2answers
90 views

How to match autocmd pattern for unique file

I'm trying to make autocommands that will run only when the buffer is a man page (:Man) but I can't get the right pattern as i'm not too familiar with regexp and globs. here's what i've tried so far: ...
10
votes
3answers
2k views

How do I reverse a string with Vim script

I am trying to reverse a string, so that 'abc defg hij' becomes 'jih gfed cba'. The solution I came up with is join(reverse(split(l:text, '.\zs')), '') Is there a more elegant solution or should I ...
2
votes
1answer
70 views

How do I pass a full filepath to a function in a Vim plug-in?

I have an exe program that checks for certain errors in a text file. I want to create a shortcut (like \+M) to run that exe file against the text file. My exe file's path is C:\Users\xyz\Documents\...
3
votes
2answers
376 views

Vimscript - Surround word under cursor with quotes

I'm writing a Vim plugin which will need to surround the word directly under your cursor with a quotes. I have tried using simple solutions which use commands like "b" and "e" executed in normal mode, ...
1
vote
0answers
34 views

How to set the language for the user interface using vimscript?

I know I can change the language of the Vim user interface using :language en_US.UTF-8, but how can I do that using vimscript? set language=en_US.UTF-8 is invalid, and the Vim documentation says that ...
18
votes
2answers
926 views

The simplest way to start Vim in private mode

I want to be able to easily start Vim in a private mode. Let's define a private mode as one that utilizes this set of commands: set history=0 set nobackup set nomodeline set noshelltemp set ...
1
vote
1answer
40 views

Get the length/number of colums in the current line/row

How can I get the length of the current row in vim script?
9
votes
1answer
1k views

How to check whether Vim is built as a 32-bit or 64-bit application?

How do I check if Vim is compiled as 64-bit or 32-bit from within vimscript? Specifically on Windows.
1
vote
1answer
57 views

Command Ordering

I made a user command called Type and would like it to appear first in the list of available commands when I type :t and then hit tab. Currently, the first command is TOhtml, which I've never used. ...
0
votes
1answer
49 views

[no]foldenable / foldmethod for each buffer but keep those settings persist for each buffer

I have two opening buffers and one has foldenable and foldmethod=indent, other has nofoldenable and foldmethod=syntax. I need that when I move between buffers, each buffer has it own fold settings ...
1
vote
1answer
139 views

How to visually select a pattern only on current line using vimscript?

I'm trying to write a vimscript function that will allow me to map a key to select a regex match on the line my cursor is on. This will help with selecting strings for use with ctags. For example, I ...
1
vote
1answer
27 views

Find the location of a directory at runtime to provide a default directory

I want to move some scripts that I have made to some sort of standalone plugin. The content would look like myplug/ plugin/ mydefaultdir/ For the scripts, I require a set of files which could ...
1
vote
2answers
68 views

Insert text in the middle of a string vimscript

I'm trying to make a function in vimscript that converts markdown to html files using pandoc and putting that converted file in a specified directory. Currently i am putting the file in a directory ...
9
votes
1answer
1k views

How can I merge two dictionaries in Vim?

I have two dicts: :let defaults = {'hello': 'world', 'bye': 'jupiter'} :let override = {'hello': 'mars'} How can I merge the keys from override so that I end up with a new dict like so: {'hello': '...
3
votes
0answers
86 views

Why does vim CursorMoved event triggered in this script?

I'm writing a vim script. When fun() is called, I want a new window of 3 lines height is opened, with the content of register h displayed. And then, when the user moved the cursor, like hjkl, the ...