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

Scrolling down in popup window not working as intended

I have the following code: let text = range(50)->map({_,i -> string(i)}) let winid = popup_create(text, { \ 'line': 1, \ 'col': 1, \ 'minwidth': 1, \ 'minheight': 1, \ '...
1
vote
2answers
61 views

Any ways to sync the movement of the number column and another window?

I want to be able to control/sync the movement (scrolling) of the number column (usable with :set number) with another different window (which doesn't have :set number set). Any ways to do this?
1
vote
1answer
107 views

Running function using <SID> on commandline not working

So i found the following vimscript code: let s:mappings = { \ 'k': {id -> s:scroll_line(id, -1)}, \ 'j': {id -> s:scroll_line(id, 1)}, \ 'd': {id -> s:scroll_page(id, ...
2
votes
1answer
299 views

What is {what} supposed to mean in the official documentation?

I keep seeing mention of {what} here and there, mainly in eval.txt, popup.txt, terminal.txt, syntax.txt, and channel.txt. From :h popup_create() popup_create({what}, {options}) Open a popup window ...
2
votes
1answer
52 views

Any way to execute vimscript beside yanking and doing @" on the commandline?

I'm used to just yanking and pasting the register @" into the commandline to execute vimscript, when I'm doing testing experimentation (since it's faster than pasting it into the .vimrc) Any ...
1
vote
1answer
35 views

“Could not pop the stack error” in vimwiki function

Got a vimwiki function: function! vimwiki#base#is_diary_file(filename, ...) abort echo a:filename let l:diary_file_paths = a:0 > 0 ? a:1 : vimwiki#diary#get_diary_files() let l:...
0
votes
4answers
81 views

“Hard-include” in vim script

I want to: let s:asciiart = ["", "", s:hardinclude(system("command params")), "", ""] where command returns one string with: "art-line-1", "art-line-2", "art-line-3" so I end up with: s:asciiart =...
2
votes
1answer
48 views

Finding where one word is close to another word: parametrized command in vimrc

I asked this question, about how to find where one word is close to another word, and Quasimodo gave the very fine answer: /\vaid(\W+\w+){,3}\W+country Now I want to parametrize this command into ...
1
vote
2answers
159 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 ...
1
vote
1answer
161 views

Any recommended ways to debug vimscript?

I'm interested in different ways to debug/trace or/and see the execution in real time (a la bash -x) vimscript.
1
vote
1answer
86 views

How to run a <SID>SomeString normal mapping?

After reading help I've started experimenting with a kind of a weird type of mappings — ones that are strings to be emitted and captured and not entered by user. So inside a script I've created: ...
0
votes
1answer
43 views

How to identify the script that's calling a user command?

I have a problem: I need to pass « any » caller-session trace into a user command… Was trying with: command WantToKnowWhosCalling call Impl("\<SID>", \ expand("<SID>&...
2
votes
2answers
88 views

Set line number on chunks of file

Following an example such as: ##1## many text and lines ##z## ##2## more text ##z## ...etc How could i make the line number display only on chunks of text, inside of the ##digit## and the ##z## ...
1
vote
2answers
390 views

Check if a specific window is open

I have a window in vim opened (current file) and another one in split called [Scratch]. I want to check if the [Scratch] is open or not. Any example is appreciated.
4
votes
2answers
114 views

How to open folds in a pedit-preview popup window?

I'm displaying a file contents by using :pedit …the-file-path…, to then call popup_setoptions(…the-ID…,#{firstline:anumber}) in order to scroll the popup and highlight/show the desired part of the ...
0
votes
1answer
30 views

How to put Shift+v in a function?

I'm trying to apply the Shift-v keymap in a vimscript, but not sure how. I tried using <s-v> and Shift-v without success.
1
vote
1answer
83 views

How to use read instead of execute in a function?

I'm trying to search for the selected line of a file using the following: function! GrepSelection() normal! gvy let result = escape(@", '\\/.*$^~[]#') let result = substitute(result, &...
3
votes
1answer
50 views

How can I make a new line in my _vimrc after using the normal i command?

I'm very new to Vim and I have some ASCII art in my _vimrc. I've inserted it there using normal i, but it doesn't display properly, because the normal i commands don't have a line break at the end. I'...
1
vote
1answer
59 views

Vim filter command not using line-wise selection

I may have seen this question before on Vi Exchange but I'm having trouble locating it while searching now. If it's already been answered, please let me know the duplicate and I can find that. I have ...
4
votes
3answers
937 views

create own snippets

I'm rather new to vim. And I don't like much to install many packages. I use html, javascript and react.js, and i would like to create some simple way to type and then have the correct snippet on the ...
1
vote
1answer
140 views

get vimrc or init.vim defined by -u switch in vim/neovim

According to :help starting, we can specify a specific vimrc file using the following command $ vim -u /path/to/vimrc How can I access the path of that vimrc/init.vim file in vim/neovim? I have ...
2
votes
2answers
102 views

How to return first match from search

Following my question about some search pattern in vim, I would like to get the the text corresponding to the first match (if any) of my search pattern wich includes cursor position and is multiline. ...
0
votes
1answer
151 views

how to use variables in vimscript shell commands

I have this code intended to: read current line extract variable from end of line, looking for text like #ad04e482 search for filename that begins with the string ad04e482 open that file to edit in ...
3
votes
3answers
1k views

How to execute a command in an inactive window

I was playing around with the MiniBufExplorer plugin, and I thought it would be nice if the MBE window could stick to the bottom of my ViM screen, even if I specifically open a new window with e.g. :...
4
votes
1answer
63 views

Set variable equal to search match subsection

Unnecessary Context: I want to write a function that closes open HTML tags, because closetag.vim seems complicated, and I like to understand all the stuff I run in Vim. My plan for this is to match ...
1
vote
2answers
357 views

Global options as function local variables

I'm asking about this code snippet: :function TextwidthIsTooWide() : if &l:textwidth ># 80 : return 1 : endif :endfunction This is what vim-help says on the l (local) prefix: Inside ...
7
votes
1answer
961 views

How does one include a trailing space in a mapping?

I'm currently trying to create the following mapping in my vimrc: nnoremap <Leader>s :split The :split is followed by a trailing space. This makes sense so I can enter the file name without ...
3
votes
2answers
166 views

Can't repeat negated pattern using \@!

I have this text: ```python x = 1 ``` Basically markdown python cells. I would like to extract the content of the cell surrounding the cursor, if any. As you may have guessed already, I am trying to ...
0
votes
2answers
110 views

How can I view a list of all of the features that can be checked for using `has()` in Vim?

How can I view a list of all of the features that can be checked for using has() in Vim? I recently came to know the has() function for testing the presence of "features" (see below). :h ...
1
vote
1answer
63 views

In VimScript what is the best technique for changeing the text when the cursor moves away?

I am new to vimscript. I am trying to figure out how plugins like vimwiki or vim-note reformat the visible text. I know how to use the syntax highlighter to highlight, bold, underline, strikethrough, ...
2
votes
1answer
110 views

Why does invoking “normal!” in insert mode cause error “Not allowed here”?

New to vimscript. I am trying to invoke a function in insert-mode. The function is a bit complicated, but I am stuck at running "normal!". Here is the mapping: inoremap <buffer> <...
1
vote
1answer
27 views

How can I alter the window to which ctrl+w, ctrl+p will jump to?

What I'm looking for is a programmatic way of changing which window Ctrl+w, Ctrl+p will jump to. The reason why I want to do this is that I have an autocmd like the following autocmd BufEnter ...
0
votes
2answers
142 views

How to iterate over a directory of files in vimscript?

I have a directory ~/.vim/rc.d/ that houses various configuration files. I like this pattern for configuring various things in my homedir because it modularizes configuration options. The problem is ...
32
votes
2answers
11k 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 ==...
1
vote
0answers
111 views

Can I use feedkeys() inside of a keyloop implemented by getchar()

I implemented a fuzzy filter, which accept a list argument, open a window with a scratch buffer whose content set to the list, then waiting for use input and do filtering. Here is why I ask this ...
2
votes
1answer
320 views

Vimscript: evaluating the contents of a variable

I know I can evaluate a (visually) selected piece of vimscript by yanking it into a register and then executing the register with :@registerName. Can this be done without clobbering a register e.g., ...
2
votes
0answers
28 views

Can you read the value of `showcmd` in a vimscript function?

I don't know how to make any vimscript I'm writing or running aware of what my pending command is! Specifically: When I hit ^W in preparation to change the window I'm selecting, I'd like to have my ...
1
vote
1answer
198 views

Improve copy to clipboard using xclip

I'm trying to improve the answer here for copying to clipboard in a vim without the +clipboard option. The problem with the above approach is that :w always writes the entire line, so it is not ...
0
votes
0answers
65 views

How to hide a buffer thru vimscript, with buffer number or buffer name

I'm trying to make a plugin that hide and show a terminal window on the bottom of the window, but i can't find a reliable way to hide a specific buffer, i tried using hide but you only can hide by ...
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
141 views

Change comment char based on filetype

I am playing around with asm, which uses ATT syntax. For the filetype asm, vim is using the comment char ;, though it should be #. How/where can I change the comment char per file type? Note that I am ...
0
votes
2answers
470 views

Statusline – update variables on file change

I'm currently learning Vimscript, but I'm stuck at a particular problem. I'm creating a statusline which shows the full path (~) of the file currently displayed in the buffer. Instead of just using %...
4
votes
1answer
101 views

Count lines matching a pattern

I'm trying to obtain the number of lines matching a pattern, from a function. I would like the cursor not to be moved at all during the process. In this case, non-empty and non-comment lines. Here's ...
1
vote
1answer
213 views

Syntax in autocmd command to compile and run cpp code

From this post here: https://stackoverflow.com/questions/540721/compile-directly-from-vim One of the answer is: autocmd filetype cpp nnoremap <F4> :!g++ % -ggdb -o %:r <CR> autocmd ...
1
vote
1answer
73 views

Text to vim-quickfix with navigation

LaTeX, being a markup language, is very hard to grammar-check. I found one program, that do this exactly Textidote. Problem is, this is a standalone program and, for example, this latex code: \...
1
vote
1answer
31 views

add second column next to line number column

I would like to create a second column next to the line number column. It shall behave identical to the line number column, i.e., move up and down when scrolling. Ideally its content should be ...
2
votes
0answers
35 views

How to delete the previous buffer when loading new result from quick-fix window?

In the quick-fix window, if I'm loading new results, the previous buffers stay which I don't want. I want only those buffers to stay which I open intentionally (e.g. to write new code, do diff of ...
1
vote
2answers
225 views

How to get the line numbers for all matches?

How can I get the line numbers of all matching strings in a buffer? Like in this buffer, I want to get the list [1,6,50] of all line numbers with matching strings. 1: test .... 6: test .... 50: ...
37
votes
4answers
7k views

How do you “chomp” a string in Vim?

Suppose you run the following piece of vimscript: let @z = system("date") This will put a string version of the current date into the z register, but the string will end with a newline that I don’t ...
0
votes
1answer
126 views

Un-tab the cursor

Is there a way in vim to move backwards a tab as it does move forward a tab? For example, if my line is: * * * * * * hello | = 4 ^ ^ cursor ...

1
3 4
5
6 7
24