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,592
questions
1
vote
2
answers
81
views
How to add a third argument to a popup_menu() callback function?
So far, I know that you can pass only two arguments to popup callback functions. I am wondering if there is any way to pass a third argument? Shall I rely on some sort of closure or use some "...
0
votes
1
answer
10
views
What would a template header look like for use in a vimscript file (found in `$HOME/.vimrc`, et. al.)
What would a template look like for the header portion of a vimscript file that is commonly found in a plugin, or files found under Vi/Vim configuration (i.e., $HOME/.vimrc directory?
0
votes
3
answers
40
views
Multiple nesting in syntax highlighting
I've got a EBNF that needs to be Vim-syntaxed:
header :== 'header' ( '{' 'header1' ( '{ 'header2' nest_3? 'trailer2' '}' )? 'trailer1' '}' )? 'trailer'
Railroad diagram gets me:
And I'm struggling ...
0
votes
2
answers
25
views
syntax highlighting needs rejoining back to common regexes
Is this Vim syntax not capable of rejoining a sequence of regex after a fan-out of choiceing (syntax region) or nextgrouping (syntax match)? Or is it an issue of following the keyword from a group ...
0
votes
1
answer
31
views
Is it possible to redirect the content of a wildmenu to a variable?
Say that I type :cd <tab>. I get displayed a menu with all the directories in pwd. I am wondering if I can store the content of such a menu into a variable.
For example, if :cd <tab> ...
0
votes
0
answers
32
views
Cannot run file in ftdetect folder using Vundle
I am using Vim 7.4 on Linux with Vundle and Git. I am writing my own plugin called potion (following an example in the book LEARN VIMSCRIPT THE HARD WAY by Steve Losh) that is stored in my GitHub ...
0
votes
0
answers
23
views
How to bind [limit] textyankpost to '*' special register [clipboard]
I've tried a lot of things, but basically event.regname is `` for "*y
autocmd textyankpost *
if v:event.regname =~ '[8+*]'
call system('win32yank.exe -i --crlf', @")
endif
In ...
0
votes
1
answer
35
views
vimscript function suggest in command-line mode?
At home I have Ubuntu LTS and my gVim command-line mode displays a horizontal list of vimscript functions as you type them after you type :call.
At work we run Windows and gVim, but the same ...
-1
votes
2
answers
46
views
How to insert multiple lines from function?
From https://vi.stackexchange.com/a/28026/47188 I know that by defining in vimrc:
" Insert text at the current cursor position.
function! InsertText(text)
let cur_line_num = line('.')
let ...
0
votes
1
answer
50
views
Copying the previous block of code
// some
// code 1
// some
// code 2
// cursor here
I wish to quickly copy and paste the immediate previous block of code (2). By a block, I mean all code that is between two empty lines (...
1
vote
3
answers
42
views
How to get the last non-blank line of a terminal buffer running a specific program?
As per text. I have a terminal buffer running ipython and I want capture the last non-blank line.
I tried the following:
var bufnr = bufnr('IPYTHON')
term_getline(bufnr, line('$'))
term_getline(bufnr, ...
1
vote
1
answer
62
views
Get return value of range function
In vimscript, when I want to store the return value of a function, I do
let a:foo = Function()
But I now have a ranged function.
I would like to store its return value, ideally via something like the ...
0
votes
3
answers
179
views
Recommended way of scripting: Ex commands or vimscript functions?
While scripting I could achieve the same result both through Ex commands and vimscript functions, for example:
var filename = "foo.txt"
exe "new" filename # Ex ...
0
votes
1
answer
23
views
Provide bash vars or at least develop ~ through let variable
To activate lsp I use this on my .vimrc:
call plug#begin('~/.vim/plugged')
Plug 'yegappan/lsp'
call plug#end()
let lspOpts = #{autoHighlightDiags: v:true}
autocmd User LspSetup call LspOptionsSet(...
1
vote
0
answers
29
views
Modify ALE coloring for style errors
I am using neovim with ALE and I want to change the coloring of style errors in general for any language and particularly in python using flake8, in the following code of my configuration file I try ...
1
vote
0
answers
36
views
Possible to use the 'comments' option to check if a line is commented?
I am looking for a way to check if a line is commented or not. It should not be a filetype specific but should be commonly usable for a lot of filetypes. Note that there are single-line and multi-line ...
0
votes
0
answers
25
views
Is there an equivalent of system() for capturing commands outputs or programs running in terminal buffers?
I am aware that system() capture the output of shell commands.
I am wondering if there is a similar command for capturing the output of commands sent to other type of interpreters running in terminal ...
0
votes
2
answers
42
views
Select current Line from normal mode without changing cursor position AND without selecting the new line character at the end
What I am asking about can be done using multiple ways but none of them fully achieves what I want. For an instance :
0vg_ selects the current line without the new line character at the end but ...
1
vote
1
answer
44
views
How to make an user-defined command that is repeatable with . operator
I've been trying to make a dot-repeatable (.) command that should work in both visual and normal mode. The command in question searches for a [] on a line and turns it into a [x], and vise versa.
It ...
0
votes
1
answer
49
views
Setting "g:jedi#use_tabs_not_buffers" option in lazy.nvim in lua
I've started recently to use lazy.nvim to load plugins.
I'm also trying to move the configuration from vimscript to lua, as well.
Most changes seem to be straightforward, but there's one that I am not ...
1
vote
2
answers
79
views
Is there a vimscript command equivalent to ya"?
Depending on the settings, if I ya" then I yank all the text between two double-quotes (including the double quotes).
I am wondering how to create a function with a similar effect, namely a ...
-1
votes
3
answers
141
views
Problem using the edit command in a function defined in vimrc
I am attempting to write a vim function that I would like to be loaded automatically when vim starts, thus I am putting it in my vimrc (but maybe that is wrong?). When called during normal editing, it ...
-1
votes
2
answers
60
views
What is :file in ex-mode?
It's not a command, it's not a builtin.
I don't know what it is; when I do :help file I get filename instead.
I want to know what it is because I want to pass a vimscript argument to it; but I try to, ...
0
votes
1
answer
34
views
How to quote fzf output as a string?
I created the following function:
function! Meow()
call fzf#run({'source': "echo \"aaa\nbbb\nccc\n\"", 'sink': 'echom'})
endfunc
My goal was to print the selected text from ...
1
vote
0
answers
35
views
Is there an equivalent to tmux clear-history in vimterminal?
In tmux there is a command which clears any additional history that may have shown up in the buffer.
Does vim have a similar function for clearing out a vim terminal?
1
vote
1
answer
51
views
is there a way to drop in my netrw location info into my jumplist
I'm aware that from a file I can type :Rex to go back to my location in Netrw Directory Listing. My muscle memory is deep here, is there a way to drop in my Newrw Directory location into my jump list?
...
0
votes
0
answers
27
views
Set the current line limit for jumping in Vim
I want to set a limit for the use of e. Basically e is for jumping forward to the end of words, but I do not want to go to the next line. I just want to jump to the end of all the words in the current ...
0
votes
1
answer
45
views
Renumbering in Vim: g<C-A> won't work in vimscript function
I'm trying to use the feature g<C-A> in a vimscript function to renumber a visual selection-ed list, but it never does the renumbering.
function! ReNumber()
execute "normal! g$\<C-...
0
votes
2
answers
45
views
Why does ":normal gv" keep removing one line from my visual block?
I'm trying to create a vimscript function that does a substitution on a visual block and then highlights the visual block again with gv. For instance:
function! MySubstitution()
s/foo/bar/
...
0
votes
0
answers
61
views
undofile without changing :undo
I think of writing as saving, and quitting as committing. Recently I discovered "undofile" which while wonderful breaks my save/quit mental model. I'd like for ":undo" with "...
1
vote
1
answer
27
views
if endif oneliner failure in VIM
I followed QA_1.
I use vim 9.1.0 instead of nvim which seems to also have the following bug and I have the following in foo.vim at line 67:
if g:LOG_MSG==v:true | echow "g:mode_class " | ...
0
votes
1
answer
37
views
Backspaces in script are not interpreted in playback
I recently learned of the -w option to record inputs. Trying to "play them back" with -s, it seems the playback doesn't perfectly reproduce the edits in at least one way
backspaces, <80&...
-1
votes
2
answers
88
views
system() without shell
Is there a way to execute a host OS command directly, without spawning a shell that in turn runs the command? Preferably passing an argument list, in execvp() style? For example
" hypothetical
...
1
vote
1
answer
45
views
How to make a function as a change?
I can define a vimscript function, for example
function GoUp()
while line(".") > 1 && (strlen(getline(".")) < col(".") || getline(".")[col(&...
1
vote
1
answer
63
views
Getting buffer name in a shell script
I have a shell script meant to run within vim. I'd like it to insert the name of the file I'm editing but I can't figure out how to do it. Is there a way to, perhaps, call bufname() from within a ...
0
votes
2
answers
48
views
Trying to display current mode leads to vimscript where variable is undefined inside function
I have following in my .vimrc
set laststatus=2
set showcmd
set wildmenu
function! UpdateStatusline()
let currentMode = mode()
if currentMode ==# 'n'
let currentMode = "Normal&...
1
vote
1
answer
43
views
Remove needless repetition of words from a text including repeated words with apostrophes
This expression, run interactively within Vim:
:%s/ \v(\w+('\w+)*)\_s\1/ \1/gi
It removes needless repetition of words.
In this way it turns this:
the the it it them them it's it's then then and this ...
1
vote
1
answer
475
views
How do I enhance the '~' command to toggle the "+/-" signs as well?
I need to make a report about investment everyday. It requires a lot of changes of the sign of figures. (from - to + or from + to -)
Is there a simple way to overload (extend) the ~ command (switch ...
2
votes
2
answers
150
views
Do we need to escape backslash in character in Vimscript?
As title, specifically, is it correct that one of the backslashes in the following regex is redundant in vimscript:
syntax match MyGroup "[a-zA-Z0-9_:\\]"
I tried to ask Copilot but while ...
1
vote
2
answers
108
views
Press CTRL+W in a vimterminal programatically from vimscript?
Say my cursor is in a Vim terminal.
Normally I press Ctrl w Ctrl w to flip to from the Vim terminal to my buffer.
How do I do that with vimscript?
I tried the whole CTRL+SHIFT+V thing when writing the ...
0
votes
1
answer
49
views
Is there any way to change the colour of individual tabs?
It's possible to change the colours used for the whole tab bar, but is it possible to set the colours used for individual tabs?
That way I could colour-code tabs based on the file path, or extension, ...
0
votes
1
answer
63
views
Go to error messages' `:help`
How can I search the help entry for the last errors after the execution?
Example
" try to run a command that doesn't exist
:qwerty
E492: Not an editor command: qwerty
I usually use :echo errmsg, ...
0
votes
1
answer
141
views
Get default autocomplete list using Vimscript
If I type an unfinished word in Vim (in insert mode) and press CTRL+N I get a list of autocomplete suggestions.
(this list contains words being used in that file and other files that are currently ...
1
vote
1
answer
134
views
Going to insert mode at the end of command with lua function
I am using Neovim and I want to go to insert mode at the end of this command.
vim.cmd([[command! DunB lua run_only_current_file("below") ]])
I have tried | startinsert and | :startinsert.
...
0
votes
1
answer
115
views
E194: No alternate file name to substitute for '#'
I have a problem with adding a keymap to delete all my buffers.
Namely, I used the following map in my init.vim file (source):
nnoremap <leader>B :%bd|e#|bd#<CR>
And I get the following ...
2
votes
1
answer
127
views
How to catch the last WinResized event?
The WinResized event is useful to know the change of window height and width. It works fine upon :resize and CTRL W<. But when a user drags and drops the status line or vertical split bar to ...
0
votes
2
answers
104
views
Count whitespaces between cursor and preceding non space character
In case I have the following line
// Component: <Component name here> |
where | is the cursor marker. How can I count, using vimscript, the total number of white spaces ...
1
vote
1
answer
76
views
Vim in tmux and WSL: cannot highlight using ctermbg
I'm using Vim inside tmux, which runs in WSL (due to work reasons). As per documentation, I decided to change my Visual highlighting style using :hi cterm=NONE ctermbg=<insert-color-here>. ...
2
votes
2
answers
165
views
Vim script: How to swap a line with multiple lines?
In a Vim function, I want to append \ and carriage return after AND.
I modify the line using the following expression:
let new_line = substitute(new_line, ") AND (", ") AND \\\n (",...
1
vote
0
answers
106
views
How can I handle whitespace of the path with nvim_buf_get_name?
I am using Neovim and I use this code to get the full path of the current file.
local currnetPath=vim.api.nvim_buf_get_name(0)
I want to use this variable for opening the current HTML file, so I need ...