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
26 views

How can I display text differently from how it is actually stored?

I am making a custom syntax partially based on Markdown. I want to display links differently from how they are stored in the file. For example, [About me](about.md) in the file should be displayed as ...
1
vote
0answers
12 views

Get comments LINED UP in 65c816 asm syntax [duplicate]

I've been writing some 65c816 assembly lately. They have some interesting commenting conventions that I was hoping VIM could help me with. LDA $E7 ; You see, they BEQ IfZero ...
1
vote
1answer
231 views

How to populate the preview window?

I need to show a 'prompt' in the preview window when the user makes a selection of an item in a popup window, which is similar to the way the tern-for-vim completion plugin does in Javascript files, ...
0
votes
1answer
65 views

How can I have lnext/lprev fallback to cnext/cprev when appropriate?

It is often the case that I am in projects with varying filetypes. Sometimes I'm compiling using :make<CR> and sometimes I'm using plugins like ALE. At any given time, I probably only have one ...
1
vote
1answer
31 views

Ways to improve a function

Perhaps this is more of a 'code-review' question, but I think this is perhaps the best (or only) place to post this question. I've been working over the past few days to understand how vim functions ...
0
votes
0answers
15 views

hlexists() for hilight group name or syntax groupname, or both?

My understanding of how hlexists() work is that it checks for groupname. I am assuming that there are two kinds of groupnames: highlight syntax Does it work not only on groupname provided by the hi ...
1
vote
1answer
14 views

Vimrc syntax move up and down a certain line continously

So I am new to Vim and I am trying to understand the language of vimrc. I have this in my vimrc: map <F8> <C-E>: sleep 100m<CR>j<F8> This would automatically move the cursor ...
1
vote
2answers
148 views

using input() for custom command

I'm using vim to edit my latex files and I'm trying to automate some aspects of it. I want a command that inserts the following: \begin{env} \end{env} Where env is an user input. So I came up whit ...
0
votes
2answers
36 views

How to store state (e.g. variables) between user actions?

The main question is in the title, that is, I have a function, which is invoked by the user and it should 'remember' necessary stuff between invocations, so the next time the user calls it (like, ...
1
vote
1answer
192 views

How to open directory in toggled netrw window?

I've toggled netrw explorer window by adding the following commands found in an answer posted to this question to the vimrc file. let g:NetrwIsOpen=0 function! ToggleNetrw() if g:NetrwIsOpen ...
0
votes
1answer
78 views

How to bind these keys to prevent recursive binding in Vim?

I have been trying to do :noremap j k and :noremap k j which works but instead of going up it goes slanted up and down. I want j to move up and k to move down which is opposite in vim. I also tried :...
0
votes
1answer
19 views

Can the command :filter be used recursively?

I mean the :filter command, not the external one. I want to filter the filtered results again, if not clear. The trivial try didn't work - :filter /abc/ filter /cbd/ %list
0
votes
0answers
15 views

redirect doesnt save error

Errors, ie python errors, appear in :messages. And yet, they are not present in the file generate by redir >> fil. I wish they would be added too. Any chance? For example, these lines aren't ...
2
votes
1answer
434 views

Vimscript: How to check if a buffer is modified

Given a buffer number i, I want to check if the buffer has been modified after the last save. How do I do that in vimscript? I tried to use getbufvar() like the following: if getbufvar(i, "&...
3
votes
3answers
835 views

How to find plugin vimscript function definition?

Assume I am using some plugin function e.g. For vim-plug, I put this code in my .vimrc at the end call plug#end() How to find out where is this function plug#end() is located? from vimrc directly ...
0
votes
0answers
54 views

vimscript: Efficient way to extract portion from line of text

I have a plugin that does syntax highlighting and folding for a kind of data file. The syntax and folding are both dependent on textual values in specific places (columns) of current line of text. ...
1
vote
1answer
244 views

How to set cursor position in a popup buffer?

I'm tinkering with popups and trying to open one, select a line (namely set the cursor line by pressing mapped keys (Ctrln / Ctrlp)), then close it. The problem is that I cannot select a line, despite ...
1
vote
1answer
135 views

Usage of t. and | in vim command

I've assembled the following command to take a markdown file and add a ==== under each line that starts with a #: :g/^#/t. | s/./=/g How exactly does this work? As far as I understand: :g/ start a ...
1
vote
3answers
56 views

Customizing Tabbing and backspace properties in vim

There are two features related to indenting that I find very helpful in Textmate, and I'm looking to find the closest thing in vim. First, I can tab to the correct level of indentation, especially in ...
0
votes
1answer
52 views

How to send contents of visual selection to an external script

I would like to write a python script that parses some vim data and returns a result. For example, we'll turn numbers, separated by lines, into a sorted list of unique numbers. If we had this as the ...
1
vote
0answers
15 views

Design guideline for doing both autocompletion and highlighting?

For Vim, are there any design guidelines for simultaneously doing autocompletion and syntax highlighting? For the NFTABLES command line (and file) syntaxes, I see lots of recurring but partial syntax ...
2
votes
2answers
171 views

How to provide shared variables for plugins?

I've written some Vimscript code* in which it's convenient to have a set of shared color names. To use the names, so far I've had to rely on code like this: execute 'source ' . expand('<sfile>:...
1
vote
1answer
76 views

vim input function with default value

I'm working a function to rename the visual selected text function! Rename() name = getline("'<")[getpos("'<")[2]-1:getpos("'>")[2]-1] let newname = input('rename the selection with: ...
2
votes
1answer
1k views

Ultisnips py3 errors

I have these following errors whenever I try to get into insert mode (see images). I am confused about how to resolve them. I did try uninstalling and reinstalling SirVer/ultisnips, but didn't change ...
2
votes
2answers
80 views

Keep cursor from moving when using operators

I'm trying to implement a custom operator following :h :map-operator. The operator works just fine but has the side effect of moving the cursor position! For example the code defining the <F4> ...
0
votes
1answer
28 views

Toggle the mode in a vim function

I am trying to modify the following function: function! changeNumber() abort if &nu + &rnu == 0 set nopaste " how to set normal mode after the function exits? else ...
2
votes
1answer
287 views

How do I increment a variable?

My question might be silly since I'm a new vimscript user. I need to define a variable as follows: let foo = 1 "Implementing foo :echo foo Without success, I tried to increment my variable with the ...
2
votes
1answer
301 views

How to match this syntax group?

I'm trying to improve on the MySQL syntax highlighting, for my particular code base. I have a lot of this sort of thing FROM TBL_ENTITIES E JOIN TBL_RELATED_ENTITIES RE ON RE.entityFK = E....
2
votes
1answer
174 views

Remapping `v` in netrw/calling NetrwSplit(5) directly

So I've created some helper functions to help work around netrw. They are some keybind simplifications that help with things like window/cursor management when opening files, where to open them, ...
2
votes
1answer
177 views

How is the fn key in written in vimscript?

How do I map the fn key in combination with another key to a macro? I know that the ctrl key in key combinations is written as a C (e.g., <C-c> for ctrl+c) in vimscript. So how would I do ...
1
vote
1answer
87 views

How to add language highlighting tags to fenced code blocks in markdown

I'd like to create a vim function to automatically add the code highlight tags, e.g. ```python and ``` around fenced code blocks to have syntax highlighting in my markdown previewer (I'm using iamcco/...
2
votes
0answers
76 views

Check valid values of an option (e.g. check if completeopt+=popup is valid)

I want to know if I can use the popup option for my completeopt in the running version of vim/neovim. The example is just for clarity, I'm looking for a solution that is generic. I know I can check ...
2
votes
1answer
53 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
74 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
51 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
165 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
89 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
176 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
502 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
172 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
80 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
63 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
68 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
50 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
287 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
117 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
87 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
188 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
444 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
658 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
3 4
5
6 7
24