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
0 votes
1 answer
20 views

Vim custom command to execute 'c""<Esc>P'

I am trying to write a custom command that executes the following: 'c""<Esc>P', namely cut visually selected text, insert ""and paste the cut text into the quotes. I have ...
  • 3
-1 votes
2 answers
44 views

What's the difference between `:e foo.ext` and `:n foo.ext`

As title. Sorry for being possibly a very simple question but could anyone rephrase the answer so it can be easily understood by a beginner?
  • 1,131
0 votes
1 answer
17 views

`Cmd+V`/`Ctrl+V` pasting has an extra new line

In init.vim I have: set clipboard^=unnamed,unnamedplus In order to ensure text is yanked into the system clipboard. In Neovim, I select the lines in line mode (V) and copy them with y: a b c In a ...
0 votes
1 answer
31 views

How to make the 81st column stand out in Lua?

Like this for Vim, I'm trying to convert (with no success): matchadd('ColorColumn', '\%81v\s*\zs\S', 100) from vimscript to a Lua autocmd: autocmd({'BufRead'}, { pattern = "*", ...
  • 157
0 votes
1 answer
14 views

User-defined commands that call the same functions but with different arguments

I am trying to create a command that calls the same function but with different arguments, like the following: def g:MyFunction(a: string, b: bool) if b echo "foo" else ...
  • 225
0 votes
0 answers
29 views

nvim-treesitter not working; throws error E5113

I just installed nvim-treesitter and it throws me this error message when starting nvim: Error detected while processing /home/MYUSERNAME/.local/share/nvim/plugged/nvim-treesitter/plugin/nvim-...
user avatar
0 votes
2 answers
40 views

How to search within a vimscript function

I'm trying to write a vimscript function that will search for a ruby class definition. My function correctly goes to the top of the file to start the search, but then doesn't move to the given class ...
  • 101
1 vote
2 answers
119 views

Call original gf after remapping gf to custom function

gf doesn't work for absolute links used in Azure DevOps yaml files, p.e. - template: /devops/template/my-template.yml (It only works without the leading slash.) This is why I have created my custom ...
  • 207
0 votes
1 answer
24 views

How to use `syn` in regex match?

I'm trying to follow a link using <CR> in a markdown file. I was giving a look into the native markdown syntax file vim ships with and found a few that use the syn command syntax syn region ...
0 votes
0 answers
16 views

How can I replicate a block of text with a pattern replaced?

I have a bunch of blocks of text across multiple files that reference a common symbol (a number). I need to create several copies of this with the symbol replaced with different values of the number. ...
  • 101
0 votes
0 answers
13 views

Check if cursor is inside a pair of quotes

What I'm looking for is basically a programmatic version of vi", va', etc. Say my cursor is at |: function_call(arg, "stri|") I want to be able to find the location/range of the quote ...
1 vote
1 answer
24 views

term_start won't open terminal in the desired position

If I run term_start('zsh', {'term_name': 'MYTER','vertical': v:true}) I get the expected behavior, but if I run term_start('zsh', {'term_name': 'MYTER','belowright': v:true}) will produce E475: ...
  • 225
0 votes
2 answers
33 views

Vim9script commands from command line result in E1124. Is it normal?

If I run e.g. :var a = 1 from the command line I end up in E1124: "var" cannot be used in legacy vimscript. Running on MacVim 9.0.1276. Is it normal behavior?
  • 225
0 votes
1 answer
36 views

How to predefine functions in syntax file?

I have a syntax file for CSV files. To be able setting the separator, there is a function ChangeChar() and the syn match ... terms are variable. To initialize it ; is used. But to call the SetMatches()...
  • 207
0 votes
2 answers
28 views

How can I use 'while' and 'if' in Vim script properly to turn off highlight automatically?

Consider: This is my code in Vim. As the code comment describes, I want to remove highlight when the cursor moved. Currently, I highlight will remove when entering insert mode, but it can still be ...
0 votes
1 answer
32 views

Vim: mapping tab to ctrl space only if the cursor is in front of a non whitespace character

I am using the jedi-vim extension and really don't like pressing ctrl-space to bring up auto-complete. I would like to use tab, but also obviously when coding I need tab for indentation as well. I ...
  • 1
0 votes
1 answer
28 views

Pass local variables in a vimscript function to python

For example, I want to use default arguments: function! MakeOrgTable(...) let l:num_col = a:0 > 0? (a:0) : 0; python << EOF import vim vim.current.buffer[:]=make_table(vim.current.buffer, ...
  • 167
0 votes
1 answer
32 views

Is there any invisible string character that can be ignored by "set fillchars", in the status line?

Currently, I'm trying to make a pretty minimal custom status line that suits my needs. One element of it, however, is a diagnostics report that depends on another plugin (coc.nvim). With a function, I ...
2 votes
1 answer
54 views

Cannot open terminal ini nvim

I installed Plugin terminal using the vim-terminal plugin and try to execute :TerminalSplit bash but before the terminal open I got a warning message. Python 2 interface is not installed, using Python ...
1 vote
2 answers
46 views

Detect Editing of Directory

How do you detect if a directory is opened(with :edit) in Vimscript? I am lazy loading a file explorer and need it to load it before I open a directory. One approach I tried using an autocommand that ...
2 votes
1 answer
18 views

Can you select and execute VimL / VimScript inside another file?

Update: It is possible with '<,'>source. I figured it out right after writing this question, no need for the complicated workaround. I am gonna still let this question here and not delete it, ...
  • 172
1 vote
1 answer
67 views

How to check if the lua function is available in vim script?

On nvim, we can use 'v:lua' prefix to call a lua function in vim script. But can we check if the lua function is available, like exists('*funcname')?
  • 303
0 votes
2 answers
37 views

VimScript: Substitute string variable content for string variable name

I would like to the present working directory (:pwd) be changed across all tabs and subwindows at the same time. I tried: let PreferredPWD=expand('%:p:h') " The desired working directory " ...
1 vote
1 answer
22 views

Highlight a single word that would be encountered after a specific word

I want to highlight the next word encountered after a specific word (e.g.: "class"). In other terms, the next word after "class" should be highlighted with the highlight group that ...
0 votes
0 answers
23 views

Remove words from comments in vim autocompletion

I have looked for similar questions but I was quite surprised to not find anything similar... either I am the first person on this planet to have this issue, or I have searched using bad keywords. ...
  • 109
0 votes
1 answer
33 views

How to use a variable from register in command mode?

I have a list of cities London Madrid Paris Brasil I want to write a macro, that will add a ul tag and wrap each city in to an li. I think, i need to create a variable like: let i = 4 Than to write ...
  • 37
0 votes
1 answer
28 views

How do I use variables with the delete command? (i.e., how to expand/reference variables for command arguments?)

I'm using variables for line numbers, and I want to delete a range of lines using these variables. How do I do that? let x = 5 let y = 20 " I want to delete the range of lines from x ...
0 votes
1 answer
50 views

Stop flushing the last command when hitting enter

Suppose I wrote this command: command! -nargs=1 E echo ' -> <args>' and when user feeds an argument, :E abc I intend to see the following effect as they hit Enter: :E abc -> abc Of ...
0 votes
1 answer
41 views

Go to file with gf from :terminal

I often keep a :terminal open on the right of a vertical split, and on the left keep a window open for files: ------------------------------ | | | | file buffers | :terminal ...
0 votes
0 answers
26 views

Sort wildmenu list alphabetically

EDIT #2 - directory setup I set up a testing directory with the following: mkdir ~/Desktop/tester1 && cd tester1 touch aa.{js,css,html} touch aaa.{js,css,html} touch bb.{js,css,html} touch bbb....
1 vote
1 answer
22 views

Use contents of copy-paste buffer in command

I would like to use the content that reside in the current copy-paste buffer in a Vim command. For example: nnoremap <leader>hi <cmd>echo "copy-paste-buffer-content"<CR> ...
  • 13
0 votes
1 answer
43 views

vnoremap to sort highlighted lines by length not working as expected

I found a command that would sort highlighted lines by their length and wanted to make a mapping for it so that I could avoid typing it every time. vnoremap ,s :<C-U>'<,'> ! awk '{ print ...
0 votes
1 answer
26 views

How to define default values for variables defined in ftplugin?

Say that I have defined two files python.vim let b:foo="py" let b:bar="thon" cobol.vim let b:foo="co" let b:bar="bol" and that I placed both of them in ~/.vim/...
  • 225
1 vote
1 answer
45 views

User function unexpectedly returns the same output every call

UPDATE As @Matt pointed out g:jsonTemplate is a list that needs to be copied. I originally thought that multiline strings were strings and overlooked the varible assignment detail after debugging. The ...
-1 votes
1 answer
33 views

What's the corresponding command of `CTRL-Y` and `CTRL-E`?

As title. I know that I can just press CTRL-Y/E to scroll, but now I need to use a script to execute them. What are the commands?
  • 1,131
0 votes
1 answer
180 views

How to know that neovim is started by zsh command "git commit" from my terminal emulator?

As title. I'm building a plugin and this is the last step. I've configured my .zshrc so that git will use neovim as its texteditor program to enter commit messages in interactive mode. The on-going ...
  • 1,131
-1 votes
2 answers
33 views

How to apply a command to all tabs?

As title. I want to call a command to all existing tabs to close all windows of specific filetype. How to do so efficiently?
  • 1,131
0 votes
1 answer
21 views

How do I override indent/html.vim's attribute indent behavior

Stated Purpose I'm trying to override Vim's HTML attribute indent behavior. This question is specific to ft=html. Vim has always inserted too many spaces when indenting HTML: <div> <div ...
0 votes
1 answer
36 views

Is it possible to disable showing `-- VISUAL LINE --` hint in the command line?

As title: I have a plugin that needs to show something in cmdline but now the space is occupied by: -- VISUAL LINE -- Any hint to get rid of it?
  • 1,131
0 votes
1 answer
56 views

How to move buffer between tabs?

As title. And I also need to know how to specify a tab to move to. So I expect the syntax would look like this: :movebuf <buffer_id> <tab_id>
  • 1,131
0 votes
0 answers
23 views

Highlight line number column with manual fold start and end markers

I'm new to folds and just trying to use them. I understand that foldmethod=indent will automatically show folds in the foldcolumn. But I think I generally don't want to use those auto folds but create ...
  • 101
0 votes
0 answers
12 views

Why `<C-h>` is mapped to backspace even if I remove all the insert-mode keymaps of `<C-h>`? [duplicate]

As title. I'm using NeoVim and there is a syntax to remove all mappings of specific key-comb. in specified mode: vim.keymap.del('i', '<C-h>') But after the call :imap <C-h> shows: i <C-...
  • 1,131
0 votes
2 answers
95 views

How to select all text and delete in vi?

Is it possible to select all the text and delete it it in vi other than hitting backspace?
  • 1
1 vote
2 answers
70 views

Insert Result of an Internal Vim Command into Text/Buffer (e.g. vims echo command)

Question I want to have basically the same as :read ![external command], but instead the external command I want to read the output from an internal command. Example Shells echo / external command: :...
  • 172
0 votes
1 answer
48 views

Is it possible to detect key-release event in NeoVim?

As title. I want to simulate the App-switching feature of macOS cmd+tab. To do so I need to detect the release of some key to trigger my lua function. Any idea?
  • 1,131
0 votes
0 answers
26 views

understanding and modifying an include-search map command

I found a useful map at the include-search ([I) help. map <leader>1 [I:let nr = input("Which one: ")<Bar>exe "normal " . nr ."[\t"<CR> This opens the ...
0 votes
0 answers
19 views

in vim: how to transfer the contents of one .swp to another swapfile

I have very often following incidence: I begin a new program to edit in vim. After a time I have with this name the current file, the current swap file and many backups with filename-suffixes .WE-01 .....
1 vote
0 answers
24 views

Is there a way to map remap 0<C-d> in insert mode

I'm doing a plugin which modify how shift works and remap <C-d> in insert mode. Every thing works well but I have a problem with 0<C-d>. It is a built-in mapping which reset the ...
  • 156
0 votes
2 answers
131 views

How to execute all autocmds of a specific augroup?

As title. I just randomly come up with this question. To do so one would need to iterate over all autocmds in the augroup. Is this possible?
  • 1,131
0 votes
2 answers
29 views

Is there a way to get vim to print human-readable output of type()?

How to convert the output of the type() function, which is a number, into a verbal format, e.g. as described in help v:t_...? To write my own mappings seems to be too cumbersome. Presumably there ...

1
2 3 4 5
30