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
60 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
1answer
46 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': '...
3
votes
0answers
78 views

Why does vim CursorMoved event triggered in this script?

I'm writing a vim script. When fun() is called, I want a new window of 3 lines height is opened, with the content of register h displayed. And then, when the user moved the cursor, like hjkl, the ...
2
votes
2answers
73 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
45 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 ...
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 ...
2
votes
1answer
62 views

How do I pass a full filepath to a function in a Vim plug-in?

I have an exe program that checks for certain errors in a text file. I want to create a shortcut (like \+M) to run that exe file against the text file. My exe file's path is C:\Users\xyz\Documents\...
1
vote
2answers
350 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
1answer
73 views

Operator pending mode remaps not working

I'm trying to build a vimscript can be used with the Dvorak Simplified Layout. I.e., given that the keys on the keyboard plugged into the computer are laid out in the Dovark Simplified Layout (and the ...
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#...
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 ...
0
votes
2answers
126 views

Set cursor in quickfix on autocmd event

I need to set cursor position when opening quickfix window. I have tried autocmd BufEnter * call cursor(2, 2) It doesn't set cursor for quickfix buffer immediately after I have opened it. UPD: I am ...
2
votes
2answers
90 views

How to set group of tabs and 1 single terminal in Vim 8?

I am a Vim beginner. I know you can do :tabnew file1 file2 to have Vim open up a bunch of files name file1, file2 spread across as tabs. I know you can move forward and backward between tabs. My ...
6
votes
4answers
591 views

Store the number of matches in VimScript function?

Is there any way to store the number of matches in a variable in a VIMScript function? For instance I'm using: %s/,//gn
16
votes
4answers
519 views

Set the paste option, but for one insertion only

I want to have a quick way of setting the Vim 'paste' option, inserting some text, and reverting to the previous value of 'paste'. A typical use case insert the OS clipboard content literally, ...
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"...
6
votes
2answers
215 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 ...
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
69 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
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 ...
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 ...
3
votes
3answers
949 views

Autocompletion Plugin for vimscript?

In recent days I use a lot of vimscript and it would be helpful to have some autocompletion. Like when I write jo the autocompletion would recommend me to write join. I have installed YouCompleteMe,...
2
votes
1answer
109 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 ...
4
votes
1answer
1k views

How to I get around “normal” exiting visual mode?

I'm trying to write a vimscript function that moves the cursor all the way up or all the way down without changing the column. (similar to the way :set nostartofline works). It works, but when I ...
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 ...
1
vote
1answer
98 views

function: sort output alphabetically

This function outputs data between braces as joined lines in a quickfix window. The output is sorted based on line numbers. I'm searching for a method to sort the data alphabetically. I tried 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> &...
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"...
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 ...
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 ...
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:...
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 ...
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: _ ...
0
votes
1answer
42 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
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
1answer
37 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
43 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
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 = [] ...
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 ...
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 ...
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 ...
2
votes
0answers
83 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
148 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 ...
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&...
1
vote
1answer
66 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 ...