Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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.

170 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
0 votes
0 answers
39 views

vim execute not working in script

I am using a plugin that expands the word template by a template but only if the word template is followed by a tab. I am trying to write the word new then in insert mode jump to the end of the line ...
user avatar
0 votes
0 answers
33 views

activate vim-lsp on single JavaScript files

vim-lsp's typescript-language-server doesn't seem to work or get activated when working on single JavaScript files or projects that are (I think) under version control. Is there a way to configure ...
user avatar
0 votes
0 answers
37 views

The dilemma of using both space-tab and tab

Now I have to learn some makefile. I only need to use the plain-old tab in this file. In other ones I want to happily keep my 4-space-tab. My current idea is to find a way/script so that I can toggle ...
user avatar
  • 731
0 votes
0 answers
31 views

How to determine the cursor is close to the last line of the file?

As title. I have the following script and I want to set scrolloff to 0 when the cursor is approaching the last line of the current file. vim.cmd [[ augroup switchScrolloffTopBottom autocmd! ...
user avatar
  • 731
0 votes
0 answers
43 views

Auto update a buffer opend in a split when it changed?

I'm writing TypeScript and there is a command npx tsc --watch that will (over)write to an output file every time the source file is changed. I open one split for each of these files. But when I save ...
user avatar
  • 731
0 votes
0 answers
45 views

in vimscript how to write the code a CTRL-C to be executed

I run a sourced vimscript like this: exec 'g#' . WE_var_searchmode . ' ' . WE_var_pattertosearch . '#exec " A | B | C | make_CTRL-C | ... | LAST " ' The outer execute '...' is needed to ...
user avatar
0 votes
0 answers
83 views

vim problem when in "try" ... "catch" an "if" is between

When a vim script is to be watched for errors and interrupts, try is put somewhere near the beginning and catch after a long sequence of code. In this sequence of code it is very probable to have some ...
user avatar
0 votes
1 answer
38 views

How to (1) get depth of execute-nesting and (2) interrupt the global command?

From a sourced file I am running my vim script. The aim of the script is to run :global. I am searching for \\%(pattern1.*/)\@<!pattern2 The patterns are variables, so I use execute; for the work ...
user avatar
0 votes
0 answers
15 views

Handling softlink directories in Windows

I'll edit the title as soon as I think of a way to succinctly word my question. I have the following for my statusline: set stl=%{expand('%:~:.') It gets the current filename's fullpath and truncate ...
user avatar
  • 2,830
0 votes
0 answers
51 views

Vim :redir + :execute prepends the executed command and blank lines to the output

I have the following function and command, which is supposed to save the output of a command to a scratch buffer: function! ScratchCapture(cmd) abort echo a:cmd " Run and capture output in l:...
user avatar
0 votes
0 answers
29 views

Inserting Visual Blank Space Without Modifying Buffer

Question In vim 8, is it possible to insert visually blank regions into a window without modifying the underlying buffer? Backstory I am writing a plugin (my first!) to assist me in updating patch ...
user avatar
0 votes
0 answers
122 views

Is it possible to execute a vimscript from the command line?

I don't know very well how to work with vimscript... Because of that, I'd like to find a way where I can easily test what I'm trying to accomplish on my vimrc file, with some prints like on other ...
user avatar
  • 375
0 votes
0 answers
62 views

Mouse navigation not working in VIM

I started using VIM today and I found out that we could use the mouse pointer to go to a line in vim using set mouse=a But unfortunately, it is not working here is the config file https://pastebin.com/...
user avatar
0 votes
1 answer
42 views

Need help to make a by-default `:RunWithFile` of this toggle function

related to this post, How to make a toggle function in .vimrc that toggles multiple configs of almost same type? @BLayer's code func! MapRunCmd() abort if exists("b:rwfcmd1") && ...
user avatar
  • 111
0 votes
1 answer
52 views

How to get the union/merge of dictionaries?

I'd like to combine two nested dictionaries following these rules: if value is not a dictionary, override the key in resulting dictionary if value is a dictionary, compute union of the two. Example: ...
user avatar
  • 101
0 votes
0 answers
24 views

how to mkview *.cpp file if and only if a fold is made within the file?

My init.vim code cd ~/Documents/cp set backupdir=~/Documents/cp/vimtmp// set directory=~/Documents/cp/vimtmp// set undodir=~/Documents/cp/vimtmp// set viewdir=~/Documents/cp/vimtmp// augroup ...
user avatar
  • 111
0 votes
0 answers
52 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
  • 485
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
  • 111
0 votes
0 answers
37 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
  • 111
0 votes
1 answer
67 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
0 votes
1 answer
95 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
  • 695
0 votes
0 answers
25 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
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
0 answers
45 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
0 votes
0 answers
34 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
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
0 answers
128 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
117 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
0 answers
128 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
  • 731
0 votes
1 answer
112 views

Useful script to manage buffer and window?

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 the split, but: If ...
user avatar
  • 731
0 votes
0 answers
65 views

How to run vimscript function on visually selected lines of text?

I'm editing DocBook XML files and sometimes I need to format the using an external xmlformat command. it is easy to run do this on the whole buffer of text, but how can i achieve the same only for a ...
user avatar
0 votes
0 answers
51 views

Tool for convert multi files vimrc into single file

i try to collect my .vimrc files into single file is there anyway to generate single file using vimscript depending on source vimscript keyword or python code example of my .vimrc if isdirectory($HOME....
user avatar
0 votes
0 answers
132 views

inoremap doesn't work

Question summary Currently I'm writing a pull request for this vim plugin which should set commas and semicolons automatically. At the moment it looks if it should set a comma/semicolon/double point ...
user avatar
  • 388
0 votes
0 answers
297 views

E716: Key not present in dictionary: "3"

I have this global at the top of my .vimrc: let DevEnv = { 'enabled' : 0, 'open_dirs' : 0, 'term_bufnr' : 0 } One of my .vimrc functions calls: exec 'bd! ' . g:DevEnv.term_bufnr Note that g:DevEnv....
user avatar
  • 143
0 votes
0 answers
131 views

Print command output on terminal on vim exit

I am trying to run shellcheck upon exiting vim, however I do not get the output of the command I run. I've tested running something like touch foo instead, and I managed to see the file being created, ...
user avatar
  • 303
0 votes
0 answers
23 views

How can I know when a real file is closed/opened from/into a visiable window?

What I'm trying to do is, when a window is closed(bw,bunload)/opened (NOT fzf, quickfix q:, buftype=nofile, etc..) resize all the other windows. This code works but I was wondering if there was a ...
user avatar
  • 223
0 votes
1 answer
184 views

Solving issue with clang-format-vim.py saving new buffer

Summary I configured vim to call clang-format.py following the steps in the clang documentation for vim integration. But when I save a new buffer the plugin fails. I'm new to vimscript and trying to ...
user avatar
0 votes
0 answers
247 views

How to set statusline for specific buffer

I want to use netrwm instead of nerdtree. I have my own statusline but I don't want it to be displayed in netrw. Nerdtree had it's own option for it (let NERDTreeStatusline="") which made it ...
user avatar
0 votes
1 answer
294 views

regex and matchstr to get final directory and file in path

I am wondering about a regex that would enable me to get the final "directory/file" from a path. I'll explain the reason why. After using vim for 20+ years, I've finally had cause to edit &...
user avatar
0 votes
0 answers
261 views

vim: is possible to use mouse to move lines around

Question: Is possible to use mouse to move lines around? Requirements & Clarification I do know keyboard solutions. normal mode ddp d2j'}p dapggp alike. cmdline commands, :co. '<,'>m'a etc....
user avatar
  • 881
0 votes
0 answers
188 views

Load scripts one after another

I have a syntax highlight, that is presumably overwritten by another script. When I execute :scriptnames, it shows ~90 scripts. The syntax script is around number 40. Is it possible to manually load ...
user avatar
  • 133
0 votes
0 answers
59 views

Execute vimscript without saving first?

From my two previous questions, I learned about using :source %, @", and other tricks to execute vimscript. But as I noticed, :source % needs the file to be saved first, furthermore, @" and ...
user avatar
0 votes
0 answers
126 views

How to hide a buffer thru vimscript, with buffer number or buffer name

I'm trying to make a plugin that hide and show a terminal window on the bottom of the window, but i can't find a reliable way to hide a specific buffer, i tried using hide but you only can hide by ...
user avatar
0 votes
0 answers
47 views

Tagbar line numberings being overwritten

I'm trying to use the Tagbar line numbers: " Show line numbers (0 = none, 1 = absolute, 2 = relative) " note: this doesn't work well and is often overwritten by rnu settings let g:...
user avatar
  • 1,767
0 votes
0 answers
110 views

How to clear and write current buffer in a function

New to vimscript. I'm writing a function that I want to be able to clear the contents of the current buffer and write this to the corresponding file (or alternatively, clear the contents of the file ...
user avatar
  • 155
0 votes
0 answers
28 views

How can I display text differently from how it is actually stored?

I am making a custom syntax partially based on Markdown. I want to display links differently from how they are stored in the file. For example, [About me](about.md) in the file should be displayed as ...
user avatar
  • 801
0 votes
0 answers
32 views

hlexists() for hilight group name or syntax groupname, or both?

My understanding of how hlexists() work is that it checks for groupname. I am assuming that there are two kinds of groupnames: highlight syntax Does it work not only on groupname provided by the hi ...
user avatar
0 votes
1 answer
168 views

How to bind these keys to prevent recursive binding in Vim?

I have been trying to do :noremap j k and :noremap k j which works but instead of going up it goes slanted up and down. I want j to move up and k to move down which is opposite in vim. I also tried :...
user avatar
  • 103
0 votes
0 answers
16 views

redirect doesnt save error

Errors, ie python errors, appear in :messages. And yet, they are not present in the file generate by redir >> fil. I wish they would be added too. Any chance? For example, these lines aren't ...
user avatar
  • 1,124
0 votes
0 answers
107 views

vimscript: Efficient way to extract portion from line of text

I have a plugin that does syntax highlighting and folding for a kind of data file. The syntax and folding are both dependent on textual values in specific places (columns) of current line of text. ...
user avatar
  • 113