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.

1
vote
0answers
36 views

How to flush job output in vim8?

Trying to do something with job output in exit_cb or close_cb, but it's all buffered, how to flush it. e.g.: function! s:exit_cb(job, status) echom getbufline(s:bufnr, '$') endfunction function! s:...
0
votes
1answer
35 views

Are the contents of highlighted content saved to a register [on hold]

Let me briefly explain what I am trying to do. I work on an air gap network. Anything not native to Red hat, or that I do not write is out of the question. The most popular two IDE's are VIM/GVIM ...
0
votes
1answer
37 views

vim FIGlet question: “-w76--” after every output

I love the plugin vim-FIGlet but I every time when I run :FIGlet ..., it always produces a text shape of -w76-- right after. For example, this is the output of :FIGlet demo: _ ...
1
vote
1answer
18 views

Is it possible to run a script on a register content and send its output to another register on Vim?

Let's consider that I have the following bash script called time.bash: #!/bin/bash date -d @$1 This script converts the epoch timestamp to its corresponding date as the following: $ ./time.bash ...
0
votes
0answers
29 views

Alarm for inactivity

I want to know if there is a way to setup vim (internal feature, plugin) in such a way that it would raise an alarm (bell, flashing screen, anything) if there were NO changes to the find within a ...
3
votes
2answers
121 views

What's the functional difference between the key notations “\<xxx>” and '<xxx>'?

I stumbled recently upon a mapping in the Vim Tips Wiki that uses an expr-quote: nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR> and realized it still worked ...
0
votes
1answer
37 views

Using %:p when path has space in it

I have this bit of vim script: nmap <F9> :w<cr> \:execute 'silent !tmux new -ds blah'<cr> \:execute "silent !tmux send-keys -t blah '%:p' Enter"<cr> \:execute 'silent !...
0
votes
1answer
36 views

Are there function equivalent to vim shortcuts?

It seems like I need to use a lot of shortcut tokens to do what I need in vimscript - which is making my code unreadable, so are there regular function calls for that? For example, I need to write ...
0
votes
1answer
29 views

vimscript to search recursively in parents directory for the existence of a file?

Help! I am looking for a vim script function: The function takes "currentDirectoryPath" and "fileName"; starting from "currentDirectoryPath" it will search recursively for the existence of "fileName"...
-1
votes
1answer
34 views

What alternative to capture groups should I use in VimScript?

I understand that Vim does not support regex capture groups. The problem I am trying to solve is being able to easily capture parts of lines. For example, given the following line of python source ...
0
votes
2answers
40 views

Find the function name associated with a number

I'm trying to debug an error in a vim plugin. The only clue I'm getting regarding the location of the error is this message: Error detected while processing function 190[2]..191[15]..218: line 27: &...
1
vote
0answers
58 views

Live search in temporary buffer

Faced a problem that I cannot force the buffer with results and the input field to work together, but not in turn (like in CtrlP) function! s:SearchByListFiles(all_files, query) let searched = [] ...
1
vote
1answer
36 views

How to find a executable file inside a folder?

I have the path of a folder in a variable, and for a custom debugging script I am making, i need to find an executable file inside that folder (the executable find is guaranteed to exist, but not to ...
0
votes
1answer
24 views

Print Command Without Hitting Enter

Suppose I map a key to enter a command in the command buffer, but without hitting enter: function! BuildSystemTask() if inProject() "generic function that checks if I am in a buildable project ...
0
votes
1answer
61 views

How to create new operator by using existing operator with current motion?

function! OperatorFunc(type, ...) " how to call another operator with current motion? " do other stuff endfunction Is it possible to get motion text? such as get iw from yiw
1
vote
0answers
52 views

How does vim receive f1-f4?

Literal terminal code of <f4> is: ^[OS result of set <f4> is: t_k4 <F4> ^[[14;*~ They are totally different, unlike results of f5-f12 (which are the same except the ...
3
votes
2answers
74 views

Insert external file and modify each line from script

I'm trying to make a function to insert license header from external file on first line in the buffer. The script is: fun InsertLicense() if filereadable('LICENSE') let ...
2
votes
0answers
49 views

Vim+Tmux: How to switch between Tmux Windows and Vim Tab Pages Seamlessly using the Alt Key?

In Vim I can switch between tab pages with :tabnext- to go left and tabnext+ to go right, simulating the tabs on an IDE. In Tmux I can switch between windows using <prefix>p and <prefix>n ...
1
vote
1answer
46 views

How do I check whether a given directory exists?

I need to determine whether a certain path exists and points to a directory, like the -d test in the shell. I know about the filereadable() function, which does basically this for files: filereadable(...
1
vote
1answer
74 views

Integrating ranger into neovim

I am trying to get ranger working inside neovim in a sensible way. The official vim plugin provided by ranger works perfectly in ordinary vim: <Leader>r launches ranger in full screen, q exits ...
0
votes
2answers
106 views

Using a special key in function

I am trying to remap <PageUp> key to call this function: function! PageUp() let l:line = line('.') if(l:line != 1) if(l:line != winline()) :set syntax=off ...
1
vote
1answer
22 views

Alert sound when using <C-L> etc. mappings

I've got these mappings in my .vimrc: nnoremap <C-Tab> :tabn<cr> " cycle tabs nnoremap <C-S-Tab> :tabp<cr> " cycle tabs backward nnoremap <C-J> <C-W><C-J&...
1
vote
1answer
63 views

How to change string at specific byte index nicely?

I want to change 3rd byte of a string to x, i'm currently using this code: let s = s[:1] . 'x' . s[3:] It's a bit awkward, i wish i can do let s[2] = 'x', but that's not allowed. Are there any ...
0
votes
0answers
41 views

Can I script VIM to process a list of diffs?

I often need to keep several directories synchronized across two or three machines. I will periodically run diff -qr local/path mounted/remote/path > diff-list.txt to get a list of what is ...
0
votes
1answer
122 views

Integrating autocomplete and snippets

I'm trying to set up an autocompletion/snippet workflow that's a bit complicated. This is stemming from needing a better workflow for latex. Right now I'm using coc.nvim and UltiSnippets but I am ...
1
vote
1answer
17 views

How do I make the current tab's windows equal width but leave their heights?

I know <C-w> = equalises window sizes but I often want to keep the heights as they are. I have set noequalalways in my .vimrc as leaving it on ruins layouts when temporary windows open (like ...
0
votes
1answer
17 views

How do I move to the beginning of a visual block from a vimscript function?

Suppose i have several lines of text: line1 line1 line2 line2 line3 line3 I want to create a vimscript function that has the following result: <itemizedlist> <listitem><para>line1 ...
1
vote
0answers
23 views

What is the correct character for splitting a string on line breaks in Vimscript?

Consider the following text file. line1f line1n line2 Suppose I visual select this, yank it into register a, and then pass it to the following vimscript function: function TestSplit(block) for x ...
1
vote
2answers
50 views

Is it possible to perform a visual block selection programmatically using line and column numbers?

I've looked around in :help V but haven't found anything of this sort, but was wondering if there's a function I can call from vimscript that would visually select a region based on (row, column) ...
0
votes
0answers
17 views

Running a command after makeprg successfully runs

I have a workflow where I build on one machine and copy the result to a different machine for testing. Currently I use vim-dispatch for running make in the background. What I would like to be able to ...
1
vote
0answers
40 views

blue warning suppression, zip folder [closed]

Is there a way I can remove the blue warnings that appear when editing a file from a zip folder in vim? Is there some setting I can apply in the vimrc file? Sorry, they are not really warnings but ...
0
votes
0answers
34 views

Is there a particular name for when you pre-set a bunch of registers used for a specific task at hand?

For example one could have many of these for different tasks (with different values for different registers based on the task): function !RegisterTemplateTest() # Set contents of said register ...
0
votes
2answers
34 views

How to create a function to `hash` buffer content

I want to create a function that I can call to replace a specific string pattern with md5sum of current buffer. I have no experience writing VimL before and can't figure out the way to do it. This ...
0
votes
1answer
17 views

Check nerd tree is open function

I'm trying to create a simple function in vim which lets me map <leader>b, <leader>n, and <leader>0 to execute a function that checks if a nerd tree is open then cycle tabs and do :...
1
vote
0answers
27 views

Vimscript infinite loop

I'm trying to combine fzf-bibtex with UltiSnips so that I can search my bibliography file and insert a BibTeX key automatically. I use the following function from fzf-bibtex (which calls the binaries ...
2
votes
0answers
48 views

How to use register in a script without side effect?

I want to create a function like this: function Foo() copy something from buffer into a register do something restore register endfunction Foo must have no side effect, every register ...
1
vote
1answer
53 views

How do I make this vimscript function (taken from another question here) 'forget' about a previous search term?

Based on the accepted answer to this previous question, I put the code below in my .vimrc, which changes the color of my statusline depending on whether my search (started with / or ?) yields results ...
0
votes
2answers
55 views

How to match autocmd pattern for unique file

I'm trying to make autocommands that will run only when the buffer is a man page (:Man) but I can't get the right pattern as i'm not too familiar with regexp and globs. here's what i've tried so far: ...
0
votes
1answer
36 views

Why doesn't this `:execute` command work?

I was looking at this question on Unix & Linux Stack Exchange, and I thought I could write an answer for it using Vim. I ran the following for a quick test, and was surprised to find it didn't ...
6
votes
3answers
2k views

Within a function, Is there a way to determine if vim is in insert mode?

Within a function, is there a way to determine if vim is in insert mode (or was in insert mode prior to calling the function)?
2
votes
2answers
111 views

imap <space> to _ (underscore) when writing function names in python files

the goal is to be able to write functions names that follow PEP8 as easily and naturally as writing this sentence. there are many types of situations that need handling insert _ (underscores) for ...
0
votes
0answers
32 views

How to stop a function when <esc> is pressed? OR how to catch a <esc> signal in vimscript?

I have a function which calls another function that reads user input from input(). function! fun1() call fun2() endfunction function! fun2() let temp = input("Please input:") endfunction What I ...
7
votes
1answer
355 views

How to source a part of a file

I can source a file, e.g. my vimrc with :so % or :so <filename>. But what do I do when I need to source only part of a file. I want some way to visually select a portion of the file with :h v ...
2
votes
0answers
38 views

Is it possible to call searchpair or searchpairpos on string instead of current buffer?

searchpair or searchpairpos works only on current buffer. Are there similar functions work on string instead of buffer?
0
votes
1answer
48 views

Are there any built-in functions to search sorted list?

Are there any built-in functions to search sorted list? Such as binary_search, lower_bound, upper_bound, etc.
1
vote
1answer
26 views

Vi shortcut to execute line under cursor as a command

I am searching for a way to execute a line under the cursor as a command. I assign it to a combination of <Leader>el and basically I found a way to do it with :exe !@u but the issue I have here ...
0
votes
1answer
44 views

How can I get vim to type continuously, rather than holding in place for keymappings?

For the purpose of this question, imagine that I have set iab phil philosopher In vim, as far as I know, the default display pattern when typing out the characters "phil" at the start of the word is ...
1
vote
1answer
43 views

Vimscript or macro to “rotate” column 20 (or n) vertically?

Given an integer n and a block of text, rotate every character or element in the n-th column up or down to the next position that exists. A line with more than k characters. A longer line with more ...
0
votes
1answer
40 views

Problem with conditional mapping <expr>

I am trying to reproduce this vimscript code function! NormalRemap() :nnoremap <silent> <nowait> I I :nnoremap <silent> <nowait> a a :nnoremap <silent> <...
5
votes
3answers
843 views

How can I get the character at the cursor position in a multibyte aware manner?

Consider the following line: € € This file is encoded in UTF-8 and between the two Euro marks is a Tab character (the Stack Exchange software expands this to spaces). The byte value is: e2 82 ac ...