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
0 answers
26 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?
leeand00's user avatar
  • 3,577
1 vote
1 answer
39 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? ...
lando2319's user avatar
  • 133
0 votes
0 answers
20 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 ...
mohamadi_arch's user avatar
0 votes
1 answer
38 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-...
wxz's user avatar
  • 155
0 votes
2 answers
40 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/ ...
wxz's user avatar
  • 155
0 votes
0 answers
45 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 "...
user19087's user avatar
  • 101
1 vote
1 answer
19 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 " | ...
An5Drama's user avatar
  • 125
0 votes
1 answer
32 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&...
Adam's user avatar
  • 103
-1 votes
2 answers
68 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 ...
usretc's user avatar
  • 374
1 vote
1 answer
38 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(&...
athos's user avatar
  • 195
1 vote
1 answer
48 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 ...
MDeBusk's user avatar
  • 416
0 votes
2 answers
38 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&...
Wakan Tanka's user avatar
1 vote
1 answer
36 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 ...
Kes's user avatar
  • 663
1 vote
1 answer
471 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 ...
Charles Jie's user avatar
2 votes
2 answers
124 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,462
1 vote
2 answers
66 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,577
0 votes
1 answer
41 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
37 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
124 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
72 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
48 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
77 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
  • 464
0 votes
4 answers
90 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
63 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
90 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
50 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
40 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
110 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
  • 157
0 votes
1 answer
58 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
85 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
52 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
99 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
205 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
222 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
31 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
65 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
46 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
101 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
159 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
76 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
89 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
83 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
61 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
52 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
64 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
57 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,194
2 votes
1 answer
178 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
2 3 4 5
32