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
703 views

How to pass a shell command to a vim function and execute it in the neovim terminal?

I've recently switched to neovim (NVIM v0.4.4) from vim. Previously in my .vimrc file I had these two mappings that allowed me to run javascript and c++ files inside vim. nnoremap <f4> :!node %&...
user avatar
  • 111
1 vote
1 answer
72 views

Redirect output to a persistent window that respect window layout

So this is a continuation of my adventures into creating my first plugin ;-) Today's issue is that I want to execute some shell command, and redirect the output to a separate window that respects my ...
user avatar
1 vote
1 answer
54 views

Character level buffer modification

It is possible to modify buffer at the line granularity. E.g. :py3 vim.current.buffer[0] = "abc". But it deletes the attached marks even if a single character is replaced. Is it possible to ...
user avatar
  • 381
0 votes
1 answer
61 views

smart single or multiple character deletion of x

I want vim to ignore whitespace copy Default cut x will work same but When i cut one whitespace character or a visual block of whitespaces with x, vim register won't copy like this thread, Vim ...
user avatar
  • 121
0 votes
0 answers
65 views

Does vim have support for processing its comma-separated options?

Vim has comma-separated dictionary options like 'comments' and 'listchars': :set comments? comments=s:--[[,m: ,e:]],:-- :set listchars? listchars=tab:⇥ ,trail:␣,extends:⇉,precedes:⇇,nbsp:⚭ Commas ...
user avatar
  • 495
4 votes
4 answers
1k views

How to open current directory in File Explorer by vim?

The problem is solved My purpose is that: I use vim to edit my m-file and debug it in Matlab. There is no easy-to-use interface plugin between vim and Matlab in Win10. So I just edit m-file in vim ...
user avatar
0 votes
0 answers
19 views

how can i define g:errorMessageString as a List?

related to this thread Multiple error messages in vim message history How can i define g:errorMessageString as a List? Can anyone help me fix this? i am using this code in my vimrc but i don't know ...
user avatar
  • 121
0 votes
0 answers
38 views

How can vim show multiple files are changed on disk?

How can vim tell me which buffer is changed on disk among multiple buffers? related to this thread, @b-layer helped me my current vimrc code: set autoread autocmd FocusGained,BufEnter,CursorHold,...
user avatar
  • 121
0 votes
1 answer
40 views

How can vim tell me which buffer is changed on disk among multiple buffers?

I am using this code in my vimrc if a file is changed outside vim, it shows File changed on disk. Buffer reloaded. set autoread autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * if mode() != 'c' |...
user avatar
  • 121
0 votes
1 answer
47 views

Cycle through a list of letters in multiple groups - Code review

This is a follow up question to Cycle through a list of letters in multiple groups where I asked how to cycle a group of letters. I got a bunch of great tips and this is my follow up question. This is ...
user avatar
0 votes
1 answer
93 views

How to test if the current file is in some directory?

I want to have a piece of vimscript (a custom formatter) only apply if the current file is inside some directory. How can I tell whether the active buffer is within a particular directory?
user avatar
2 votes
4 answers
687 views

How do I change the word under the cursor?

I've written a little function that changes a 'CamelCaseWord' to a space separated 'camel case word': " Convert a CamelCase word to space separated words. function! s:converFromCamelCase(arg1) ...
user avatar
  • 31
6 votes
1 answer
1k views

how to include multiple commands nested inside a single `autocmd BufRead...`?

I want to make several keybinds and options set for certain files based on their location. Is there a more elegant way than... autocmd BufRead,BufNewFile /tmp/wiki-tag-reports/* nnoremap <Enter>...
user avatar
  • 705
0 votes
1 answer
101 views

how to conditionally re-bind <Enter> key depending on file

My vimwiki plugin has Enter key bound to the function to create a "hyper"-link to another file (and if it already is a link then open the linked file to view/edit). I want to be able to jump ...
user avatar
  • 705
0 votes
2 answers
38 views

Function only executing first "execute" statment

I'm trying to make a vmap that takes a count and then indents all the highlighted lines so that the top one is more than the line above it, while keeping all the lines' relative indentation. I have ...
user avatar
  • 421
0 votes
1 answer
177 views

Can I define a function with '#'-namespace in a file with hyphen '-' in its name?

I often see #-namespaces in plugins source code, e.g coc#status(), fzf#run(), fugitive#extract_git_dir. I would like to use namespaces in my own config, mappings and commands source code also. But I'm ...
user avatar
1 vote
0 answers
30 views

cannot run `:normal s<CR>` just for nerdtree (opens file vertically splitted)

what im trying to achieve: use <C-V> to paste text in normal mode in current buffer use same <C-V> to vertically split a file from nerdtree what i know: when you are with your cursor in ...
user avatar
1 vote
0 answers
122 views

neovim, vimscript execute keystroke from function

I am trying to execute a keystroke from function when its called. However, it does not work. function SmartNERDTreeFocus() if expand('%') =~ 'NERD_tree.*' normal <C-w><C-p> ...
user avatar
  • 141
0 votes
0 answers
26 views

`echohl` not highligthing with custom color, but its working with the defaults

in my init.vim (.vimrc) file i have this: hi TerminalGreenColor guifg=#6bd676 function! EchoInitVimReloadedSuccessfully() echon " -- [ " echohl Identifier echon "init.vim&...
user avatar
0 votes
1 answer
67 views

How to create an abbreviation that matches a regular expression

I'd like to create an abbreviation that will change the following (in a markdown file): - list item 1 into this: - list item 1 Whenever I type - f it should be expanded to - f (from 1 space to 3 ...
user avatar
  • 163
0 votes
1 answer
87 views

How to curry a function in vimscript?

I am trying to curry a function in Vimscript to map an operator. I have a function written in Lua, and I want to pass 'n' or 'v' to that function, depending on the mode that trigger that mapping. ...
user avatar
0 votes
1 answer
187 views

Define default value to a variable

I want to assign an expression to a variable, and if it has no value, use some default. On almost every programming language I can use something like: let linked_hl_id = hlID(l:linked_group) || 114 ...
user avatar
  • 121
0 votes
0 answers
29 views

different highlight if a certain highlight is on

I'm writing a function to highlight current word, but on commented out lines, I want a different highlight to apply. Example: Notice how the word exists is highlighed, but on a grey commented out ...
user avatar
  • 121
0 votes
1 answer
46 views

Assign value based on filetype [duplicate]

I want to assign value based on filetype. I am using UltiSnips plugin and want to have one set of bindings for one filetype and another set for everything else. Something like if &ft='vimwiki' ...
user avatar
1 vote
2 answers
143 views

How to apply alternating caps?

Fast way to type or change to AlTeRnAtInG CaPs?
user avatar
  • 381
1 vote
0 answers
70 views

Center-align command bar and/or tabs bar

I'm often using vim fullscreen on an extrawide monitor (multiple splits, including terminals). Because both the command bar and the tabs bar span the full terminal width and are left-aligned, commands ...
user avatar
  • 333
2 votes
2 answers
81 views

Making functions react to keypress

Im very new to vim scripting. I have the following script in my .vimrc: If there is no user input aka I press <CR> => go to recent buffer If input is 'd' => delete all buffers except for ...
user avatar
  • 33
0 votes
1 answer
32 views

How to put sync region start=<this> into a variable?

I have the following code: com! -nargs=* ShFoldFunctions <args> fold ShFoldFunctions syn region shFunctionOne start="^\s*[A-Za-z_0-9:,][-a-zA-Z_0-9:]*\s*()\_s*{" end="}&...
user avatar
  • 173
1 vote
2 answers
84 views

Manipulate the dot command without editing text in insert mode

I need to manipulate the dot command without directly editing the buffer for a plugin I'm developing. The plugin needs to manually append text to the dot command that will be executed while in insert ...
user avatar
  • 145
0 votes
0 answers
47 views

Emulate Emacs-like Mode

I'm used to Emacs different modes, that is: Setting up functions/setting once entering a specific Mode Renaming the statusbar with the name of the Mode "Cleaning up" (resetting setting to ...
user avatar
1 vote
1 answer
27 views

vimscript to insert function result is not inserting with proper formatting

I have a function that I want returning pre-indented xml: function! InsertStep() let stepTemplate = "<step index=\"\">\n \ <description></description>\n \ ...
user avatar
  • 113
1 vote
2 answers
126 views

How to substitute filename on reading or opening new file

We have rather complex file structure and I would like simplify opening file independently where am I in the filesystem at the moment. Let's say we have a project_folder and several files in it: /...
user avatar
  • 123
7 votes
2 answers
1k views

Why is `let foo = $HOME/bar` invalid?

Why is let foo = $HOME valid and let foo = $HOME/bar invalid in vimscript? I have tried let foo = "$HOME/bar" but it is the equivalent of foo = '$HOME/bar' in shell script, $HOME is not ...
user avatar
  • 173
2 votes
1 answer
45 views

vimscript to skip a block of text with lines containing similar words

I need a little help with some vimscript-ing. I have a huge log file with multiple blocks of text resembling the following: [log file start] ... ... Information: Setting NDR rule shield_rule on net a ...
user avatar
  • 21
1 vote
1 answer
115 views

Auto pairing using strings instead of characters

I'm already aware of existing solution to automatically "surround" sentences/word/etc (eg: auto-surround, vim-surround, etc) but those (as far as i know) don't support using normal strings ...
user avatar
0 votes
0 answers
35 views

Chronologically store visual selections in a buffer

My goal is to enhance the usage of gv with counts, in order to access older selections quickly. Such that 2gv would reselect the selection made before the last. Vim doesn't have events for entering ...
user avatar
  • 1
2 votes
1 answer
178 views

Passing arguments function with --argument or -a format

Is it possible to pass arguments to Vimscript functions with the --argument or -a format, similar to arguments in the command line? I am writing a command that submits a job in a remote machine. I ...
user avatar
  • 255
0 votes
0 answers
31 views

Measurement/ tracking the time for editing a file (overall and statistics)

I use vim for coding and also for writing scientific articles and book chapters. It would be very interesting to know the time I spent on a file. For example how many hours or minutes the buffer was ...
user avatar
0 votes
1 answer
165 views

How to detect the change that from insert mode to normal mode, so I can implement Auto-Save?

I want to do the following: autocmd changeFromItoN * if &readonly == 0 && filereadable(bufname('%')) \ | silent update | endif That is: I want to implement the ...
user avatar
  • 771
0 votes
0 answers
140 views

Open file in new tab or split if current file has changes in fzf.vim

I have been using :Files to get a list of files using fzf.vim. Although whenever I hit enter to open a new file and the current file has not been saved I get an error message saying No write since ...
user avatar
0 votes
1 answer
234 views

Remove text specifying mode "INSERT" in bottom vim line

In the bottom two lines, you'll see the statusline saying "INSERT", and the line where you enter commands showing -- INSERT -- This is quite redundant, and I would like any recommendations ...
user avatar
  • 3
0 votes
1 answer
146 views

how to autocmd BufWritePost stdout to tidy upon :w?

tldr; How do pass stdout of BufWritePost to an external command? On command line I can run cat index.html | tidy -indent -modify I'm trying to call tidy automatically when I :w This is what I have so ...
user avatar
0 votes
1 answer
24 views

how vi automatically collapses {}

I always come across a lot of code wrapped in {}s while reading, and I wondered if there was a way for vi to automatically fold these {}s instead of manually marking them.
user avatar
0 votes
0 answers
139 views

Let .js files be recognized as .jsx files?

I just figured out how to combine those creepy plugins to work together to achieve the following auto-indent: before / after pressing o: But then this only works on file extension .jsx as shown above,...
user avatar
  • 771
1 vote
1 answer
182 views

How to detect whether the current line is empty line?

I want a command mapping to detect whether the current line is blank, and perform a different action for each case it detects: true of false. How do I do this?
user avatar
  • 771
0 votes
1 answer
61 views

Is it possible to dynamically set the `let var="string"`? [closed]

I'm playing around with my .vimrc as usual. I have a colorscheme which displays differently with let ayucolor="dark" let ayucolor="mirage" let ayucolor="light" I'm ...
user avatar
  • 771
0 votes
1 answer
163 views

How to temporarily change file encoding?

I'm using a plugin which can show the minimap for the file I'm editing. The plugin can only works with utf-8. Does anyone know how to dynamically/temporarily change the encoding in Vim, so I can make ...
user avatar
  • 771
2 votes
1 answer
240 views

How do I work with vim9 and unicode?

I've found myself in a bit of an interesting situation. I'm writing a plugin in which I need to do a tiny bit of line parsing. Given a file: æøå It's easy to verify that col('.') returns 1, 3, and 5 ...
user avatar
0 votes
1 answer
142 views

How to suppress error message of autocmd command when the `silent` doesn't work?

I'm using Coc.vim and I've created an issue on their GitHub, but I'm not sure about whether this can be done by modifying the line I'm using: autocmd CursorHold * silent call CocActionAsync('doHover') ...
user avatar
  • 771
1 vote
1 answer
273 views

How to run additional command in nnoremap?

I have the following lines in my .vimrc: nnoremap <nowait><silent> ¡ :colorscheme tokyonight<CR> nnoremap <nowait><silent> ™ :colorscheme tone<CR> nnoremap <...
user avatar
  • 771

1
3 4
5
6 7
28