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
1answer
31 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' |...
0
votes
1answer
40 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 ...
0
votes
1answer
21 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?
1
vote
4answers
388 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) ...
2
votes
1answer
222 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>...
0
votes
0answers
25 views

Is there a way to detect whether a `:normal` command is executing, or if the input is actually typed in?

Ideally, I'd like to have different behavior for those two cases. For macros specifically, there is reg_executing, but I don't know about any way to achieve the same for a general :normal command. (I ...
0
votes
1answer
52 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 ...
0
votes
2answers
37 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 ...
0
votes
1answer
46 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 ...
1
vote
0answers
19 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 ...
1
vote
0answers
37 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> ...
0
votes
0answers
21 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&...
0
votes
1answer
27 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 ...
0
votes
1answer
46 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. ...
0
votes
1answer
42 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 ...
0
votes
0answers
27 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 ...
0
votes
1answer
24 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' ...
1
vote
2answers
67 views

How to apply alternating caps?

Fast way to type or change to AlTeRnAtInG CaPs?
1
vote
0answers
30 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 ...
2
votes
2answers
66 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 ...
0
votes
1answer
23 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="}&...
1
vote
2answers
67 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 ...
0
votes
0answers
35 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 ...
1
vote
1answer
23 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 \ ...
1
vote
2answers
65 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: /...
6
votes
2answers
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 ...
2
votes
1answer
25 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 ...
1
vote
1answer
109 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 ...
0
votes
0answers
29 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 ...
2
votes
1answer
57 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 ...
0
votes
0answers
28 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 ...
0
votes
1answer
33 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 ...
0
votes
0answers
46 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 ...
0
votes
1answer
53 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 ...
0
votes
1answer
40 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 ...
0
votes
1answer
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.
0
votes
0answers
62 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,...
-1
votes
1answer
36 views

How to detect whether the current line is empty line?

I want to detect whether the current line my current on is only composed of non-visible characters, and return true of false, and use this check to trigger some nnoremap mapping, how?
0
votes
1answer
52 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 ...
0
votes
1answer
74 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, while, my mother tongue is Chinese so I wrote comment in Chinese. Does anyone know how to ...
2
votes
1answer
110 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 ...
0
votes
1answer
56 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') ...
0
votes
1answer
40 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 <...
0
votes
1answer
63 views

Useful script to manage buffer and window?

Given the scenario: I want to create a vertical split from current buffer for reference another file/the same file. After I've done with this split I don't want to see this buffer-for-reference in ...
0
votes
1answer
43 views

Using a multiline closure to execute commands in vimscript

I'm writing a script in which I am in need of closure functionalities. Take this function, for instance: func! SetOpNorm(norm_comm, motion_key = 'y') let l:norm_comm = a:norm_comm let l:...
1
vote
1answer
65 views

How to search for vue components with vim's gf?

I want to go to a vue component file. Vue component filenames are written in PascalCase: ExampleComponent.vue In html (or in my case blade.php) the ExampleComponent.vue is instantiated by <example-...
0
votes
1answer
105 views

How to get the buffer type of the current buffer?

I'm writing mapping, and I want to decide whether I have to do additional actions when current buffer type is a drawer called Fern, here is my command currently nnoremap <nowait><silent> ; ...
0
votes
1answer
39 views

How to run internal (Neo)Vim ":Command" from external Terminal?

I'm using MacOSX, and I have script on Terminal, and since I will probably forget how to update everything inside Vim/NeoVim, is it possible to pass command, e.g. :PlugUpdate, to nvim/vim so that I ...
0
votes
1answer
111 views

pylint default filepath in ALE

I am trying to set up my pylintrc file in vim, but am having some difficulty getting it to read from the correct path. It seems to work when I have the file in the directory that contains the vim file ...
0
votes
1answer
29 views

Get path to parent directory and use it in a nnoremap command?

Say I have a nnoremap and I want to pass the path of parent directory of current file to it, so the command can use this information. I have read this answer: How can I see the full path of the ...

1
2
3 4 5
25