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
1
vote
1answer
22 views

Find the location of a directory at runtime to provide a default directory

I want to move some scripts that I have made to some sort of standalone plugin. The content would look like myplug/ plugin/ mydefaultdir/ For the scripts, I require a set of files which could ...
1
vote
2answers
61 views

Insert text in the middle of a string vimscript

I'm trying to make a function in vimscript that converts markdown to html files using pandoc and putting that converted file in a specified directory. Currently i am putting the file in a directory ...
2
votes
2answers
74 views

How to get line numbers of a different window

I would like to get these line numbers of a different window without moving to that window. line('w0') line('w$') line('.') line('$') As for the first two, we can use getwininfo([{winid}]) which ...
3
votes
1answer
46 views

What is the #{} syntax in Vim?

I just noticed this in a Vim help page: popup_beval(s:balloonText, #{mousemoved: 'word'}) What is the #{mousemoved: 'word'}? It looks like a dict? I tried using :help #{, but that doesn't show any ...
2
votes
1answer
59 views

How can I merge two dictionaries in Vim?

I have two dicts: :let defaults = {'hello': 'world', 'bye': 'jupiter'} :let override = {'hello': 'mars'} How can I merge the keys from override so that I end up with a new dict like so: {'hello': '...
1
vote
2answers
351 views

How to delete a line from a variable?

Inside a function, saved multiple lines of external command output to a variable. How to delete a line from the variable? Like first line. I can run let tmp = split(variable, "\n") to assign the ...
2
votes
0answers
16 views

How to identify the last DiffUpdated event?

The DiffUpdated event has been added in patch-8.1.0397. Sometimes the event occurs a few times in a session. For example, when 2 files are opened in diff mode, ":e!" generates the event 3 times. As ...
1
vote
2answers
35 views

remove extra (^@) from visual selection

I'm writing a function to execute an external command using visual selection. I've noticed that if by mistake the entire line is selected, including the new line char the extra ^@ character makes the ...
1
vote
1answer
33 views

di in vim/fortran

I have tried without any luck, but can anyone kindly let me know if di is possible for language like vim/fortran which has structure like do loop Something end do UPDATE: command di', di"...
1
vote
1answer
33 views

How to use the result of a function in a Vim keymap?

I have a function in Vim script that returns a string. " Return first directory with ".git" folder, if none is found " return the current directory function! s:project_root() for vcs in ['.git']...
1
vote
1answer
46 views

Find project root relative to the active buffer

I can use the finddir function to find a parent folder that contains a .git folder (project root), like this: let dir = finddir('.git/..', ';') However, this only finds project roots that are parent ...
2
votes
1answer
38 views

Update external file based on VIM mode

Currently I have my vim set up to update the statuslline based on what mode the editor is in. Like if I'm in insert mode then the statusline turns red. Magenta in replace mode. Green in command ...
1
vote
2answers
79 views

Review: git branch in statusline

I am learning vimscript, and below the part of my .vimrc used to display the current git branch in the statusline. I am aware that there are ready-made options out there, but this is more of an ...
0
votes
1answer
31 views

Ultisnips Sinppets in current scope on blank line

Background I'm using UltiSnips in conjunction with some autocomplete plugins. I have this line controlling the behavior of enter inoremap <expr> <cr> \ !empty(UltiSnips#...
0
votes
2answers
33 views

Return cursor to an initial position after pasting text from a function

in my plugin, i am joining XML tags together depending on a mapping a use. It also uses so i can make XML snippets repetitive. After inserting the text into a buffer, i would like the cursor to ...
0
votes
1answer
53 views

Run vimscript function only once although v:count1 > 1

I have a function that accepts a count of iterations, its command is defined with -range: command -nargs=1 -range DocbkPrintTag :call s:DocbkPrintTag(<f-args>) and to output <listitem> &...
1
vote
0answers
62 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:...
1
vote
1answer
31 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
1answer
38 views

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

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 ...
1
vote
1answer
78 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 ...
6
votes
2answers
219 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
38 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
2answers
48 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"...
0
votes
1answer
38 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
46 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: &...
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 ...
1
vote
1answer
40 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 ...
3
votes
2answers
81 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 ...
1
vote
0answers
62 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 = [] ...
2
votes
1answer
69 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 ...
1
vote
1answer
152 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(...
0
votes
2answers
117 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 ...
2
votes
0answers
84 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
24 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 ...
1
vote
1answer
26 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&...
0
votes
1answer
18 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
27 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
54 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
19 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 ...
0
votes
1answer
43 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
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
43 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
21 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
35 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
52 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 ...
0
votes
1answer
37 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 ...
0
votes
0answers
35 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 ...
2
votes
2answers
119 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 ...
1
vote
1answer
37 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 ...