Skip to main content

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
3 answers
38 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, ...
Barzi2001's user avatar
  • 640
1 vote
1 answer
40 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 ...
Feffe's user avatar
  • 1,771
0 votes
2 answers
102 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 ...
Barzi2001's user avatar
  • 640
0 votes
1 answer
19 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(...
user3313834's user avatar
1 vote
0 answers
18 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 ...
Jorge L. de Oz's user avatar
1 vote
0 answers
35 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 ...
Rick Howe's user avatar
  • 363
0 votes
0 answers
24 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 ...
Barzi2001's user avatar
  • 640
0 votes
2 answers
36 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 ...
pic810's user avatar
  • 1
1 vote
1 answer
34 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 ...
melvio's user avatar
  • 617
0 votes
1 answer
23 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 ...
Jir's user avatar
  • 103
1 vote
2 answers
74 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 ...
Barzi2001's user avatar
  • 640
-1 votes
3 answers
134 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 ...
efru's user avatar
  • 13
-1 votes
2 answers
51 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, ...
leeand00's user avatar
  • 3,601
0 votes
1 answer
22 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 ...
user4035's user avatar
  • 179
1 vote
0 answers
33 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,601
1 vote
1 answer
46 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
25 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
40 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
42 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
57 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
21 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
33 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
75 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
40 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
  • 207
1 vote
1 answer
56 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
  • 436
0 votes
2 answers
41 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
41 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
474 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
131 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,510
1 vote
2 answers
79 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,601
0 votes
1 answer
43 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 has moved to Codidact's user avatar
0 votes
1 answer
45 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
134 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
90 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
76 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 ...
satk0's user avatar
  • 101
2 votes
1 answer
126 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
  • 363
0 votes
2 answers
82 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
1 vote
1 answer
68 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
124 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
69 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
55 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
  • 363
1 vote
3 answers
115 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
  • 179
0 votes
1 answer
66 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
102 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
58 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
36 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
116 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
57 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
210 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,849
3 votes
5 answers
225 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
  • 377

1
2 3 4 5
32