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
7
votes
1answer
337 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 ...
2
votes
1answer
50 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
28 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
32 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
61 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
18 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
31 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
29 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
42 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
541 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
21 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
2answers
34 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
31 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: ...
3
votes
1answer
47 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
29 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
1answer
26 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
22 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
53 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
124 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
82 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 <...
0
votes
0answers
31 views

“Invalid expression” setting 'foldtext', what is wrong?

I am trying to set 'foldtext', but it seems I misunderstand expressions, types, etc. of Vim fundamentally. Why does the following refuse to work? set foldtext=v:folddashes."TEST" Whereas this works?...
1
vote
1answer
38 views

Error detected while processing grammarous.vim: E117: Unknown function

I am trying to install the vim-grammarous plugin for Vim 8.0.1453. I have cloned the repo into my .vim/plugin directory. Now every time I open Vim I get an error message which also occurs when I try ...
1
vote
1answer
39 views

switch current directory between a base directory and current file directory

Goal: To achieve filename/path completion relative to current file directory using omni completion CTRL-X CTRL-F. I open all my files contained in a base directory such that :pwd in some_file outputs ...
0
votes
1answer
47 views

How do I deal with shell text which has underlines, bold, etc

Currently I am outputting AWS help to vim, and then searching through it, but to my horror, I am realising displays underlines, for example, NAME will be displayed as: N^HNA^HAM^HME^HE Where ^H is ...
0
votes
1answer
35 views

Capturing key stroke

I would like to write a script, maybe even using Python, that captures a key stroke in a Vim window. Let's say I am in insert mode and I type the letter g. I would like this key stroke to trigger some ...
0
votes
1answer
35 views

Deleting comments from the beginning of selected lines

I have written a vimscript function to toggle comments on/off on lines selected in visual mode. The function successfully adds comments but freezes when I try to uncomment selected lines. The ...
0
votes
1answer
64 views

How to check if the character under the cursor is a tab?

I am using the code getline(".")[col(".")-1] to get the character under the cursor. How can I check if the character under the cursor is a tab ?
1
vote
1answer
64 views

Which event is triggered by deleting a character with the x key?

I have written a vimscript function. I want to use autocmd to call this function when a character is deleted with the x key. But autocmd requires an event name. Which event is triggered when a ...
1
vote
0answers
66 views

get current vim mode inside vimscript code

I would like to be able to get the current usual mode of vim inside a vim script (and not only inside the statusline). I need this functionality to build a vim script linked with ruby script to be ...
0
votes
1answer
54 views

Is there a nice way to programmatically call the file auto-detection algorithm?

I was writing a simple Vim plug-in for a generic code generator called Templaty. The generator can theoretically work with any programming language, and I'd like Vim to automatically apply the correct ...
2
votes
1answer
68 views

Why does a custom 'contained' highlight match interfere with the C syntax highlighting?

I am having an issue, which I was able to reduce to the following sequence of commands: setf c syntax region templatyExpression matchgroup=Special start='{{' end='}}' syntax region templatyStatement ...
3
votes
1answer
45 views

Syntax highlight rule for a block comment using indentation

I have the following code and I want to define a syntax highlight rule that will show all lines as commented out starting at the line with ## till the indentation ends just before the last print line. ...
2
votes
2answers
204 views

Is there a way to yank directly to a vimscript variable?

I have some boilerplate code in one of my vimscript functions: " Save register 'a' so we don't clobber it let savereg = @a " Yank the current WORD into register 'a' and save it to 'input' normal "...
1
vote
1answer
43 views

How to replace all buffer content by some string?

For example, if I run some external program (formatter) from vim and write result of it to some variable: let result=system("some_program", getline(1, "$")) " do something with result How I can ...
1
vote
1answer
54 views

Split window size change event

Couldn't find anything in autocommand-events, but is there may be a way to be notified if window split size was changed (with mouse or with C-w +)? What I try to achieve is to be able to auto-save ...
1
vote
2answers
38 views

Creating and destroying temporary files by vim

I integrated luacheck in vim with the following simple function: function! LuaCheck() let errors=system("luacheck " . expand("%")) cexpr errors cwindow 5 endfunction autocmd FileType lua ...
1
vote
1answer
32 views

Set CoC nodejs path dynamically

Currently for CoC I am setting the nodejs path like this: let g:coc_node_path = '/usr/local/.nvm/versions/node/v12.4.0/bin/node' But I want this variable to be set to the output of which node. How ...
0
votes
0answers
23 views

Lose hlsearch when using with vim-fuzzysearch

I'm using this plugin: vim-fuzzysearch. When I have long file (I need to press ctrl-f/ctrl-b to scroll) Steps to produces: 1. Turn on `hlsearch` + vim-fuzzysearch and search for a keyword 2. ...
1
vote
1answer
74 views

How can I decide whether a file can be opened in VIm or not?

I want to make a script with FZF (Fuzzy Finder) and I want to show only those file which can be opened with VIM. So, I don't want to list mp4, jpg, pdf etc files in FZF. So, is there any way to ...
2
votes
2answers
66 views

Do not delay mapped keys with common prefix

What I want to do is have two mappings. One mapped to <s-k>, and one mapped to <s-k><s-k>. What happens right now is that if I press <s-k> vim delays for timeoutlenms, and if ...
1
vote
1answer
40 views

How to turn on airline theme's background in vim?

I just started using vim and I installed tpope/vim-pathogen and then vim-airline/vim-airline-themes plugin to use these themes. Then I changed my .vimrc to set up the papercolor theme, powerline fonts ...
1
vote
1answer
41 views

Catch the “search hit BOTTOM, continuing at TOP” when cycle through the badly spelled words

Can anyone show me how to catch the last badly spelled word when vim says ...hit BOTTOM? I tried to do it like this: while 1 try " Jump to the next silent keepjumps normal! ]s ...
1
vote
2answers
95 views

Why does matchlist() return empty strings at the end of the result?

From the Vim's help: echo matchlist('acd', '\v(a)?(b)?(c)?(.*)') Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', ''] I understand why the 3rd element is an empty string: 'b' is not present in ...
3
votes
1answer
20 views

Use mapped shortcut without timeout

I have these in my .vimrc: set notimeout nnoremap <leader>n :set rnu!<CR> nnoremap <leader>h :<C-u>call Toggle_colorcolumn()<CR> <leader>n works instantly; <...
0
votes
2answers
204 views

get string from cursor to end of <CWORD>

In vimL, how to get a string from cursor to end of <cWORD>. I know expand('<cWORD>', but don't known how to keep only right part of cursor. Example given text pre abc-xyz.xxx:123 post, ...
2
votes
1answer
61 views

Is it possible to set a timer task in vim7

As we know, we can set a highlight color while searching a keyword. I'm wondering if I can set a timer task to clear the highlight color after a few seconds. For now, I have to type :noh<CR> ...
0
votes
1answer
67 views

How do I tell vim to detect when a new file was created and do some action? [closed]

What I want to achieve is simply set up some auto command that will detect anytime I create a new file and based on the name of the file I want to insert a couple of lines of text in that file. So if ...
4
votes
3answers
255 views

Is it possible to create a snippet to “expand” struct members to fill?

In the type of c programming that I do day to day, I often have to "fill" struct members in order to pass them to an API. For example: struct measurement { double start_time; double end_time; double ...
2
votes
1answer
57 views

Expand `pwd` inside a vim command

I have a variable that I would set to the current result I get from :pwd. I tried the following, which obviously doesn't work: :let b:projectroot = expand("pwd") But this is essentially what I want ...
3
votes
2answers
90 views

`system()` can't get output of shell command in vimrc

I want to enable some configurations only when the distribution is Fedora. Here is my code. let s:os = system("sed -n 's/^NAME=\(.*\)/\1/p' /etc/os-release") echo s:os if s:os == "Fedora" " ...

1
2 3 4 5
19