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
0
votes
0answers
38 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
337 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
62 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
72 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
172 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
68 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
136 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
94 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
206 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
63 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
89 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
253 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. ...
4
votes
2answers
579 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
197 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
120 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
262 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
451 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
30 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. ...
5
votes
1answer
142 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 ...
3
votes
2answers
129 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
250 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
280 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
127 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
35 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
447 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
77 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
208 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
432 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
405 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 ...
4
votes
2answers
304 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" " ...
2
votes
1answer
418 views

Binding toggle comment to <C-/>

I installed NERDCommenter plugin and its default bindings unfortunately conflict with my own. For instance I use <Leader>-c and <Leader>-v to emulate CTRL-c and CTRL-v. And since IDEs ...
1
vote
1answer
61 views

how do i open a new window with a new buffer, containing a variable?

I'm trying to write a plugin: I have a variable with some text. I want to: create a new buffer place the contents of that variable in the new buffer open a new split that displays the new buffer ...
1
vote
1answer
68 views

How to convert register contents to something readable similar to :register command?

Let's assume there is a macro stored in register 'r' I can obtain the contents of this register by executing getreg('r'), but if I print this then it can often be unreadable. I noticed though that ...
1
vote
1answer
42 views

Why does :! open -a terminal or :! start cmd create totally new “applications”?

Edit: on Windows, looks like it's opening in sysWOW64 instead of system32. Any ideas why? Title. Basically, both of these commands are supposed to open a new console, the former on my mac and the ...
2
votes
1answer
379 views

Making terminal buffer unlisted

I'm configuring my scripts to work with terminal in VIM and have a question regarding :h special-buffers. Among mentioned kinds there were the following: unlisted The buffer is not in the buffer ...
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
116 views

Custom command to go to file whose name matches the current word under cursor?

Let's say I'm editing this text in vim: People are helpful. and I am in normal mode, with my cursor currently on the h letter of the helpful word. How could I built a custom command that when run ...
2
votes
3answers
269 views

Guard packadd to not load an optional non-existent package

I have an "optional" plugin that depends on python (pack/habamax/opt/myplugin) in my settings I have the following: if has('python') || has('python3') do some setup packadd myplugin endif ...
1
vote
2answers
228 views

Write buffer list to file

I would like to have a file that contains all files that I opened with vim in the past. I know that there is the viminfo file but I want to have just a file with the filenames. For this I would like ...
4
votes
1answer
274 views

tell vim to add default extention to word under my cursor before opening file

Lets say I have text This is result file output_20DeC. Let's say my cursor is on o. When I use the command gf, it should open output_20Dec.txt file. So how do I tell vim to add a default extension to ...
8
votes
1answer
3k views

What's the difference between `/x` and `:/x`

Assume buffer content: aa bb yy xx aa bb What's the different between /xx and :/xx?
2
votes
1answer
83 views

How to comment List item?

There are times I want to comment List items: let test_data = [ \ " description in comment \ complicated_data0 \ \ " description in comment \ complicated_data1 ... ...
1
vote
2answers
249 views

Make a buffer active by its number

I'm configuring a terminal buffer and now I have the following problem. I have only one terminal buffer and I need to make it active by its number to avoid lots of CTRL-w j/k/l clicks. Here is what I ...
0
votes
1answer
67 views

function variable scoping and arg types problems

I'm trying to make a small extension/bug fix to a plugin I rely on (referenced as Plugin in the code snips), therefore I'm constrained by its existing API. I've got the functionality I want somewhat ...
3
votes
1answer
211 views

How to create command with -register and <reg>?

I have never used :h :command-register and :h <reg> , trying to find an example, but failed to grep \-register from my installed plugins, The built in :h :delete support a count and an optional ...
2
votes
3answers
893 views

Toggle terminal buffer vimscript function

I'm new to vimscript and writing a function to toggle a terminal buffer. Here is what I tried: let g:toggle_term = "<C-j>" let g:term_buf_nr = -1 function! ToggleTerminal() if g:...
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 ...
5
votes
2answers
231 views

Is it necessary to always add ! to function and command

I can't remember start from when and why, i always add ! to function and command: function! .. ... endfunction command! ... But :h E122 says: When a function by this name already ...
1
vote
1answer
76 views

Autoreload vimrc when writing to vimscript files

I wanted to have my vimrc automatically update when I write to a .vim file using this autocmd: autocmd BufWritePost *.vim,$MYVIMRC source $MYVIMRC But for some reason when I have this enabled and ...
1
vote
2answers
69 views

Move cursor and screen together

I am implementing a smooth scrolling function for <C-u> and <C-d>, which just sleeps for a few milliseconds and then moves the screen up (<C-y>) or down (<C-e>) one line: ...

1
5 6
7
8 9
24