People who code: we want your input. Take the Survey

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

How do I put the List returned from a 'heredoc' (:h Let-HereDocs) into a Dictionary in Vim? How do I also make this work in Neovim?

In :help let-heredoc it explains that one can set a variable to a 'heredoc' where each line of the heredoc becomes an entry in a list as follows: let text =<< trim END if ok echo 'done' ...
1
vote
2answers
78 views

Why would you use `nnoremap gf gf` as SpaceVim does?

While writing this answer about vim-rails on SpaceVim, I found out these mappings set by SpaceVim, such as this one: nnoremap gf gf SpaceVim also creates similar mappings for all of the other gX ...
1
vote
1answer
53 views

How to place cursor after lines appended in function

I have, for many years, used Vim. Until today, I've not found the need for writing my own functions. I found myself faced with adding some features to existing code, and in so doing needed to ...
0
votes
1answer
180 views

How to check if variable is of list type? of dictionary type?

In a plugin, I'm using json_decode() to obtain information from somewhere. I've no control over the json structure, but expect a list of numbers under a key foo: { "foo": [10, 20, 30] } How to ...
1
vote
1answer
91 views

How do I substitute inside the visual selection in a vimscript function

I have a function that looks like this: function Foo() normal! vi) '<,'>s/abc/def/g endfunction However, when I try to call it, I get "Mark not set" error. What is wrong? Shouldn't the ...
3
votes
1answer
189 views

How to exclude filetype with autocmd to load language specific skeleton

I have the following in order to use a different template per language. But I want English to be the default, if I don't specify .en.adoc in the filename. But the *.adoc,*.en.adoc also picks up *.fr....
1
vote
2answers
523 views

Parsing output of json file with jq

I have the following windows.json file [{ "id":5178, "pid":40345, "app":"Alacritty", "title":"Alacritty", "frame":{ "w":880.0000, "h":531.0000 } },{ "id":...
1
vote
4answers
196 views

line-continuation in an an if-statement

For better readability I'd like to split if-statements with multiple expression into multiple lines. But when executing such a statement via a register vim always complains about it. This: if 1==1 &...
1
vote
1answer
83 views

using \r in {sub} of substitute() function call

I want to write a zsh vi-mode helper to wrangle complex commands but ran into a snag using \r in a substitute() function invocation. It results in \r replaced with control characters ^M in output. ...
1
vote
2answers
74 views

Command-P 'paste script/shortcut'

I am using a mac, and I usually paste things in by doing the following: :set paste! cmdp :set paste! This is really the only way I've been able to paste things into vim reliably (with the help of ...
2
votes
1answer
73 views

Vim executing UltiSnips snippet every time I scroll the page

I inserted the 'datetime' snippet from vim-snippets/all.snippet right at the beginning of my document. The problem is that the time keeps on updating whenever I scroll, as if vim is redrawing the ...
1
vote
2answers
51 views

Embed <Return> within register

I want to have predefined register that will jump to the location matched by regular expression, i.e. in vimrc I add: let @a="/=\"" That will be useful for me when I want to navigate to the next ...
1
vote
1answer
300 views

How to use TexMathZones in Markdown Syntax, for Snippets?

I am a recent and very happy Vim User. I write Mathematics and Computer Science Lecture Notes in Markdown Files, organized in a Vimwiki. I use the UltiSnips Snippet Plugin. This plugin provides me ...
2
votes
1answer
123 views

Concatenate vim command after :terminal

Is there any way I can concatenate a command after :terminal? For example :terminal | <some_other_vim_command> will pass | <some_other_vim_command> to the terminal that just opened, but ...
1
vote
1answer
97 views

How to check whether a command is run with range or not?

For example, I have the following code command! -range Test call TestFunc() function! TestFunc() abort " if run with range " get selected content " else " get current word under the ...
3
votes
2answers
206 views

Execute with system function results in error of `undefined variable`

execute "normal! :echo ". system('echo hello') The above results in: E121: Undefined variable: hello Why? I'm expecting it to evaluate as: execute "normal! :echo hello"
0
votes
1answer
528 views

How to read a file into a variable vimscript?

I'd like to read the contents of a file, and put this into a variable - so I can later use it in a command. How can I achieve this?
2
votes
6answers
696 views

How to delete a pair of parenthesis with backspace

I'm using vim to code C++ and I want to handle the parenthesis more easily. I knew that there was a plugin named Surround, which can help us but it is not what I expected. I set some shortcuts as ...
1
vote
1answer
84 views

Highlight multiple words from modeline-like tag?

I am using a function in my vimrc to detect contents similar to those of a modeline and use that to highlight specific words in the file contents. The function I'm using is from the answer to my ...
5
votes
2answers
571 views

How can I run a function / action every period of time (once an hour)?

I want to run https://stackoverflow.com/questions/7588531/vim-set-color-theme-based-off-time-of-day So something like: if strftime("%H") < 12 set background=light else set background=dark ...
1
vote
3answers
180 views

Is it possible to create map to call Funcref (including lambda)?

Is it possible to do this: function Foo(func_ref) abort nnoremap <buffer> <cr> :find_a_way_to_call_func_ref endfunction function s:callback() abort echo "123" endfunction command ...
2
votes
1answer
118 views

How to add modifier to user defined command?

I'd like to write commands that work with :tab and :vert. Say I have a command that opens a new split window as shown below function! FooSplit() let l:message="hello world" new put! =l:...
0
votes
1answer
164 views

Open a file from a new blank tab in vim

If I've already opened a tab with: :tabe Is it possible to load the file in that tab? For example, to do something like: :o ~/.vimrc In other words, instead of doing :tabe ~/.vimrc, can I do that ...
1
vote
1answer
18 views

Problem when inserting text from a function in a for loop

I have a function that animates the insertion of the contents of the last modified register at the cursor's location as if someone was typing it: function! AnimateInsertion() abort " split ...
1
vote
2answers
172 views

How can I format all Markdown # headings using a bash command?

I would like to format Markdown headings to titlecase, and I have a bash command that works to format input: echo "convert to title" | awk 'BEGIN{split("a the to at in on with and but or",w); for(i ...
2
votes
1answer
296 views

List of Vimscript comment keyword highlights

While editing my vimrc I noticed that some keywords get highlighted at the beginning of lines, like Note: and Reminder:. I tried to find this syntax group in the vim.vim syntax file, but to no avail. ...
1
vote
1answer
14 views

How can I replicate behaviour of go-to command? (42gg, 42G)

I've been searching far and wide around tutorials, :help command, source code, Stacks but maybe I just can't form my query correctly in the vimscript lingo. My goal is to have a short command for ...
1
vote
1answer
93 views

Function to toggle terminal creates extra empty buffer

I have modified a function from CKolkey's dotfiles - ToggleTerminalDrawer (line 230) so that it works for Vim8.2 (instead of neovim). Here is my modified function now in my vimrc: nnoremap <silent&...
0
votes
1answer
81 views

Is it possible to pass local variables to functions inside statusline=%{}?

I have a function that builds my status line by appending values with statusline+= depending on the context. Everything works, except that if I try to call a function in the following form: setlocal ...
0
votes
0answers
11 views

Trouble creating a remap that compiles the current open latex file along with one other latex file in the current directory

I am working with latex files. I want to have a normal mode remapping which compiles my current file and a latex file named main.tex (both in my current working directory). The command to compile is:...
31
votes
1answer
6k views

What are the new “popup windows” in Vim 8.2?

The latest version of Vim, 8.2, has a new feature called "popups" or "popup windows". They sound interesting but I'm not quite sure what they're good for. Can you enlighten me...preferably with some ...
3
votes
1answer
164 views

Building a Vim Plugin for Autocompletion

I've been a vim fan for almost 5 years right now and never moved to any other editor. Since my background in deep learning and NLP, I realized that there a lot of new development in source code ...
0
votes
1answer
66 views

What does [ .. ] mean in a function signature?

For example this function signature has several braces [ and ]: matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]]) What it means? Unnecessary argument?
1
vote
2answers
93 views

How to get the number of the output of `vimgrep`

I wrote a vim-script function, which allows me to grep a keyword in my project. function! CustomGrep(...) if a:0 == 0 silent vimgrep <cword> **/*.h **/*.hpp **/*.c **/*.cpp else ...
1
vote
2answers
160 views

vimscript: No match error

I'm trying to write a vim-script function, which allows me to grep the word under cursor easily in my project. function! CustomGrep() vimgrep expand("<cword>") **/*.h **/*.hpp **/*.c **/*....
2
votes
0answers
68 views

Resource for highlight syntax debugging

I’ve been developing a Vim syntax file for ISC Bind 9.15+ The stock named.vim that came with Vim is quite outdated (V9.4) About 89 syntaxes out of 498 have been completed so far to catch up. But ...
1
vote
0answers
46 views

How can I send a visual selection to another file, at a line with a certain pattern?

I'd like to be able to yank a visual selection and then append it to another file at a certain line (according to a pattern). In particular (as shown in the attached screenshot), as an example i'd ...
1
vote
1answer
369 views

Commands to write text to a buffer

I'm writing a plugin that often needs to write text to specific buffers. My current solution is to make the script execute normal commands that open a split with the buffer, write the text and then ...
3
votes
1answer
123 views

Why does vimscript use `set cpo&vim`?

Please explain following two lines found in synload.vim file: let s:cpo_save = &cpo set cpo&vim What is vim in the last expression? What is result of such an expression, and what does it ...
4
votes
3answers
572 views

How can I calculate the duration of a function call?

I have this function which insert 2 dates in a file: function MaFunction() put =strftime(\"%c\") exe 'w' exe 'call Function1()' put = strftime(\"%c\") endfunction Example: 24/03/...
1
vote
1answer
68 views

Set option on window without going to the window and come back

I want to set some options on a particular window number. What I've been doing is go to the window by {winnr} wincmd w, set some options and do some work then come back. But this creates a UI flash (...
0
votes
1answer
803 views

I can't get solarized plugin to work in vim (I am using vim-plug)

I just started using vim. As I understand it, using a plugin manager is the easiest way of installing plugins for vim. So I thought I would try vim-plug which I installed using curl as explained here....
0
votes
1answer
53 views

VimScript - Save specific positions consistently even after buffer changes

I want to save multiple positions in vimscript, and make sure that they stay at the right place, even after the buffer changes Here are the solutions I found so far, and why I want something else: ...
5
votes
1answer
456 views

Can I set breakpoint in a vim plugin script written in python?

When a vim plugin is developed in a mixed script of vim script and python, can we set breakpoints and debug the python script. I tried to use PDB module, but vim is dead when it go to the pdb....
1
vote
0answers
167 views

Provide arbitrary arguments to a snippet in UltiSnips

There are numerous occasions where you might want to have another optional argument in your snippet. Lets say I want to have a numbered list for example. Preferably I'd call something like enum3 which ...
1
vote
2answers
198 views

Vim8/NeoVim Invalid Expression remapping <C-x><C-o> to <Tab> for OmniShap-vim

I was reading a blog post for Settings up a C# Development Environment with Vim on Debian and I got most of this going except I have an issue with the <C-x><C-o> inoremap'ing. I am running ...
1
vote
1answer
124 views

vimscript : How do I apply a function on the current buffer?

I have written a function which capitalises the first letter of each word like this: function! CamelCase() range let old = getline(a:firstline, a:lastline) for line in old let x = ...
1
vote
2answers
128 views

Trouble Splitting a YAML-Like List

I'm working on a plugin that needs to parse a YAML-like list and I can't quite nail the pattern needed to split the string. The pattern needs to match a comma delimited list that can have both singly ...
4
votes
1answer
318 views

How to iterate over pattern matches?

I've got a file, containing some output log. It consists of several blocks of information, that start and end with some fixed patterns. I need to put a summary for each block in the beginning of the ...
0
votes
1answer
113 views

search a pattern preceding cursor position, modify it and insert the modified string

I am writing a mapping to autocomplete tags Pattern: <.*?>, matches complete HTML tags only. The goal is to lookbehind and see if there exists a text like <html>. Mapping: inoremap <...

1
4 5
6
7 8
24