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
1 answer
44 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 ...
NeoZoom.lua's user avatar
  • 1,392
1 vote
2 answers
58 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 ...
leeand00's user avatar
  • 3,491
0 votes
1 answer
37 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, ...
Len's user avatar
  • 125
0 votes
1 answer
32 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, ...
ranemirusG's user avatar
0 votes
1 answer
117 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 ...
Alexanus's user avatar
  • 119
1 vote
1 answer
54 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. ...
mohamadi_arch's user avatar
0 votes
1 answer
35 views

init.vim: 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 ...
satk0's user avatar
  • 101
2 votes
1 answer
121 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 ...
Rick Howe's user avatar
  • 353
0 votes
2 answers
76 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 ...
xyx's user avatar
  • 422
0 votes
4 answers
83 views

How can I camel-case extant lowercase text?

I use vim for coding. I have a disability where some of my fingers hurt and I have trouble holding down shift and a letter to produce uppercase. The same goes for parentheses. How can I convert ...
Joselin Jocklingson's user avatar
1 vote
1 answer
58 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>. ...
linhns's user avatar
  • 11
2 votes
2 answers
75 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 (",...
Fisher's user avatar
  • 1,086
1 vote
0 answers
29 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 ...
mohamadi_arch's user avatar
0 votes
0 answers
27 views

How to detach/disable a buffer-update callback in nvim

In vim, we can implement a vim script, which monitors text changes in details, with listener_add(), listener_remove(), listener_flush(). In nvim, nvim_buf_attach() is available to attach a callback. ...
Rick Howe's user avatar
  • 353
1 vote
3 answers
108 views

How to swap lines programmatically in file?

Suppose, we have a perl file where we want to swap shebangs located in the first line: "#!/usr/bin/perl -d" <-> "#!/usr/bin/env perl" The first one runs the file with ...
user4035's user avatar
  • 133
0 votes
1 answer
53 views

Have Neovim automagically invoke external program on the Neovim-saved file while exiting

I have the following python code stored in my $HOME/bin/email-process #!/usr/bin/python3 from sys import argv # open up the email contents file infile = open(argv[1], 'r') # read it into an array ...
user3236841's user avatar
1 vote
1 answer
66 views

Script in autoload is not running

I'm using Linux, Vim (nox) 9.0, and Neovim 0.9.4; I have both environments synchronized. What would prevent a .vim file in ~/.vim/autoload/ or ~/.config/nvim/autoload/ from autoloading? The only ...
LiamF's user avatar
  • 185
0 votes
1 answer
50 views

Best way to downport funcrefs and partials from 8.2 to 7.4

The 8.X version of vim introduced new possibilities for the function() command: the ability to create Partial functions or to package funcrefs with arguments. The difference of the function() help is ...
Laurent''s user avatar
  • 103
0 votes
1 answer
34 views

Is there an efficient way to delete the duplicated block with same start and end to keep unique?

Description I have many large size files may including the same function definition. The block description is start with .start .* and end with .end In this example there is one duplicate definition ....
M_Sea's user avatar
  • 157
1 vote
1 answer
92 views

Put the mutiple search or replace results into different split window

Dsecription I am using :g/regex to do global search and it always list --More-- So I need to click Enter or Space to see the full results, it takes too much time. I found one way to achieve my goal ...
M_Sea's user avatar
  • 157
1 vote
1 answer
56 views

How to save the files when global replace completed in one command line

I have so many huge size of files and always need to do search and replacement so I map the command as nnoremap aa :let i=1 \| g/regexp/ s/^/\=printf("%1d. ",i)/g \|let i =i+1\|:w! 1.txt ...
M_Sea's user avatar
  • 157
1 vote
1 answer
204 views

How is the right hand side of an <expr> binding evaluated?

I like using <cr> to save a file, except in a quickfix window where I want <cr> to enter the directory or file shown. Here's one way to achieve this (works as a .vimrc by itself). I'm ...
Greg Nisbet's user avatar
  • 1,839
3 votes
5 answers
220 views

How can I determine the Linux distro in vimscript?

In shell I do conditional stuff depending on distro like this: eval "$(source /etc/os-release && typeset -p ID)" if [[ $ID =~ ^(rhel|fedora.*|amzn|ol|rocky|almalinux)$ ]]; then ... ...
paradroid's user avatar
  • 367
0 votes
1 answer
25 views

Recursive fold only up to &foldlevel?

I often use zC to close nested folds under the cursor. However this command is not useful in files with a single, global level-zero fold (e.g. fortran program...end program and latex \begin{document}.....
Luke Davis's user avatar
  • 1,397
0 votes
1 answer
62 views

Calling variables from SHELL and using them in Vim config (vimrc) [closed]

Question I am trying to use variables from SHELL inside my Vim configuration file, now, I have researched how to do this and asked ChatGPT about how as well. It is possibly due to the specific ...
Ella H's user avatar
  • 13
1 vote
1 answer
45 views

How can I use Regex in helpgrep?

I would like to use Regex in helpgrep. For example, searching for lines or sections that contain two words. Something like :helpg 'word1' & 'word4' to find this line as my result: word1 word2 ...
mohamadi_arch's user avatar
0 votes
1 answer
96 views

When I use helpgrep, how can I highlight my search results?

I'm using :helpg session in my Vim. I would like to highlight the pattern in the results like :set hls does for normal search. Is there a way to do this?
mohamadi_arch's user avatar
1 vote
1 answer
151 views

Why so % does not work when vimrc changes with another editor?

I opened a file in Vim. Then opened vimrc file with another editor (VsCode) and made some changes. I would like those changes to be reflected in my Vim session. I tried :so % but it didn't work ...
mohamadi_arch's user avatar
0 votes
2 answers
70 views

Why doesn't echo % do anything in command mode?

I read the section of current-file in the document. (see :h current-file) And I have a question. if % stands for the current file name, why I can not use echo %?
mohamadi_arch's user avatar
1 vote
1 answer
71 views

What is the meaning of lbr in Vim?

I write set lbr in my vimrc file but I don't know the meaning of that. What does this option do? I know it's about line-breaking but I need more explanation. This is from the Vim document and I can ...
mohamadi_arch's user avatar
0 votes
1 answer
66 views

How to show the clock and battery usage in lightline?

I have Lightline installed for a more detailed statusline. Unfortunately, any time I do something like this set statusline+=%{strftime(\"%H:%M\")} it seems like Lightline will override it, ...
Patrick O'Brien's user avatar
2 votes
1 answer
55 views

How to use function argument in a mapping?

Let's take a look at the example below. function! Print (text) echo a:text endfunction function! Mapping_test (parameter) nnoremap m1 :call Print (a:parameter)<CR> nnoremap m2 :call ...
Artur Pyszczuk's user avatar
1 vote
1 answer
50 views

Using the completion function for a command that is passed as an argument to another command

Is it possible to programmatically get a command's definition so that its completion function can be called manually? Alternatively, is it possible to define a command such that the first argument is ...
Pak's user avatar
  • 1,114
1 vote
1 answer
58 views

How can I match a regexp containing newlines?

When developing a vim plugin I'll publish soon, I want to highlight a text contained in a variable g:last_completion_text. Here below the code to define an highlight group named PrompterCompletion ...
Giorgio Robino's user avatar
0 votes
0 answers
50 views

How to use <Leader> in a normal command today?

The answer to the question with the same title doesn't seem to work for me. Not sure if the behavior has just changed overtime. To reproduce the issue, open Vim via vim -Nu filebelow.vim, where the ...
Enlico's user avatar
  • 2,184
2 votes
1 answer
143 views

Neovim paste without overwriting register w/ Lua

So I know with vimscript you could make paste not overwrite your register with this: vnoremap p pgvy And I've tried a few ways to get this to with with Lua such as: vim.api.nvim_set_keymap('n', 'p', '...
Zach B.'s user avatar
  • 123
1 vote
1 answer
84 views

What are the escaping rules of command arguments?

The following does nothing: :file /tmp/[some file] or: :file "/tmp/[some file]" The following set's the file to /tmp/[some file]: :file /tmp/\[some file] What are the rules that :file ...
KamilCuk's user avatar
  • 265
1 vote
1 answer
49 views

How to configure my own highlight for Vim editor in Linux using ~/.vimrc and ~/.vim/colors/mycolors.vim files? [closed]

I want to configure and customize my own syntax highlight for Vim editor in Linux Ubuntu 20.04. In my home directory, I created two files, ~/.vimrc and ~/.vim/colors/mycolors.vim. Here is the full ...
morris's user avatar
  • 11
1 vote
1 answer
110 views

How to generate random string with required length in Vim?

I am using this code for console log nmap cll yiwocll<Esc>p I wanted to add some random string inside this console log, assume 10 characters symbols length. How to achieve this?
hden mila's user avatar
1 vote
1 answer
45 views

How do I get size of "whole" Vim instead of a single window?

I want to create a floating window, with the width of the entire Vim viewport. I had used winwidth() function, but I've encountered problems when windows are split. I could get a list of windows in a ...
szym.mie's user avatar
2 votes
1 answer
109 views

Make { ( and ) } normal mode motions skip blank lines

Normal mode ) } and ( { navigate paragraphs and lines but they don't skip blank lines. (They land on them.) This is obviously the preferable behavior when writing code, but when writing "normal&...
Anthony's user avatar
  • 55
1 vote
2 answers
153 views

Is there a Vim plugin for testing VimScript patterns?

I'm new to VimScript and trying to learn how to construct patterns. Is there a Vim plugin like RegExr.com for testing patterns?
Samuel Bacay's user avatar
-1 votes
1 answer
56 views

Is It Allowed to Assign popup_create() To a Variable?

I know it returns the window ID, but when I run the function that does what's on the question title, it keeps telling me that a 'List is required'. I don't know what's going on. " Check the type ...
Samuel Bacay's user avatar
0 votes
1 answer
108 views

Does Vim Cache the Output of system()?

Does it? I'm not sure. I'm getting this error, and it seems to be looking for a nonexistent cache folder: E282: Cannot read from "/var/folders/yh/z3ydby_56qz7mltrddsv3lqw0000gn/T/vi3voZp/0" ...
Samuel Bacay's user avatar
1 vote
1 answer
98 views

How Do I Turn a String into URL Encoded String?

I'm trying to turn a JSON format string into parsable URL encoded string. Here's my process: " Read the contents of the file separated into lines let lines = join(getline(1, '$'), '\n') " ...
Samuel Bacay's user avatar
0 votes
2 answers
53 views

How to convert a string into a list of matching and non-matching substrings?

I have a list that I'm trying to filter. I'm planning to separate a string into parts of the string that matches a pattern and parts that doesn't. Like if the string is: <h1>hello</h1> ...
Samuel Bacay's user avatar
1 vote
2 answers
132 views

VimL: check if Lua is supported

How do I check if Lua is supported? From my .vimrc, I only want to put an if around a Lua heredoc so that my config works in plain vim or versions of neovim which didn't support Lua (pre 0.5.0?). What'...
Tom Hale's user avatar
  • 2,631
1 vote
1 answer
66 views

Using marks in custom functions/plugins without changing user's marks

I am looking for a way to save and restore marks at the beginning and end of my custom Vimscript function. I am writing a plugin and I don't want my plugin to change any of the user's marks, so I ...
matko031's user avatar
1 vote
1 answer
144 views

Is there a hotkey to jump to the beginning or end of a python if statement in Vim?

I use VsCode with the Vim plugin. In other languages using Vim to jump to brackets is good enough, but python if statements don't have brackets. I have found no Vim plugin or macro for this, is it ...
red888's user avatar
  • 193
1 vote
1 answer
49 views

Syntax highlighting of a submatch

I have the following syn match specialNumber /1/ contained syn match normalNumber /\d/ contained syn match line /^\d$/ contains=specialNumber,normalNumber hi def link ...
xvf99680's user avatar

1
2 3 4 5
32