Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
0answers
70 views

How to escape paths for findfile() and finddir()?

I have run into an escaping problem with the path argument to findfile({name}, {path}) / finddir({name}, {path}). In my code path is a directory, obtained via fnamemodify(<file>, ':h'). Until ...
1
vote
1answer
108 views

How to visually select a pattern only on current line using vimscript?

I'm trying to write a vimscript function that will allow me to map a key to select a regex match on the line my cursor is on. This will help with selecting strings for use with ctags. For example, I ...
1
vote
0answers
97 views

Toggle UltiSnips

I have this following mapping in my .vimrc " Toggle search next with blink and without blink let s:enabled = 0 function! NextMatchToggle() if s:enabled unmap <buffer> n ...
3
votes
0answers
54 views

Why does vim CursorMoved event triggered in this script?

I'm writing a vim script. When fun() is called, I want a new window of 3 lines height is opened, with the content of register h displayed. And then, when the user moved the cursor, like hjkl, the ...
1
vote
3answers
49 views

Repeating a macro to create lines of text

I am pretty new to vim and hence trying to learn some of its powerful features and ofcourse top of the list is macros. So i am trying to create a pattern like this. <tag>var 1</tag> <...
3
votes
1answer
450 views

Sending command to different tmux pane from vim

behave test language need to execute different lines of the behave feature file, for example, if I want to test the line number 99, I'll need to input the following line in the terminal behave ...
3
votes
0answers
38 views

Completly silencing commands like `dd`, `:delete` of old vim versions (7.4.152)

Discl. I'm perfectly aware of :silent :delete or silent :normal dd, I'm also aware of execute(). My context is that I run unit tests with vimrunner on travis, with the version of Vim currently ...
1
vote
1answer
60 views

How to “dereference” variables in keymappings?

I just learned about vimscript. I'm trying to write a small vimscript that'll kinda copy what this does, but more verbosely and very explicitly. (The first case would case typing a ( will insert ()) "...
4
votes
1answer
78 views

Sort lines ignoring leading component

I would like to sort some lines, ignoring a leading part of them. Here's an example from my .spacemacs file: '( better-defaults elixir emacs-lisp erlang evil-commentary ...
1
vote
1answer
96 views

Give variable to makeprg

I'm trying to put the output of a command into a QuickFix list when a particular key is pressed. That command takes as its argument the word under the cursor, so my function looks basically like this (...
0
votes
1answer
38 views

[no]foldenable / foldmethod for each buffer but keep those settings persist for each buffer

I have two opening buffers and one has foldenable and foldmethod=indent, other has nofoldenable and foldmethod=syntax. I need that when I move between buffers, each buffer has it own fold settings ...
2
votes
1answer
73 views

Re-sync _folds_ from start

Vim has a handy feature in :syntax sync fromstart which allows me to fix syntax highlighting when it gets confused during an extended editing session. I map it to <leader>ss (reSync from Start) ...
0
votes
0answers
102 views

Vim still create backup/swap/undo folder under .cache when set nobackup/noswapfile/noundofile [duplicate]

I got a strange behavior of vim 8.1 1-279 / archlinux 4.17.14 This is vim under console but I believe there's no different. Vim force create ~/.cache/vim/{backup,swap,undo} folders even I set ...
1
vote
0answers
24 views

How can I prevent <CR> from moving the cursor downward? [duplicate]

In the vim help doc, it says: *CTRL-M* *<CR>* [count] lines downward, on the first non-blank character |linewise|. That is, in the normal mode, <CR> has the same ...
0
votes
0answers
52 views

how to write a self-contained color scheme

I'm making a simple colorscheme based on one I found on the vim website. https://www.vim.org/scripts/script.php?script_id=854 I'd like it to be declarative in the sense that the colorscheme is ...
1
vote
0answers
57 views

Monkey-patch plugin function

Is it possible to override an autoloaded plugin-function? I want to customize an airline-internal function just like this: diff --git a/autoload/airline/extensions/default.vim b/autoload/airline/...
0
votes
1answer
149 views

Match pattern and highlight it in modeline for a specific filetype

I need to match Issue in .conf filetype and highlight it with custom color but set in mode line instead of a fix in syntax/conf.vim file. The use-case is for each kind of document I need to highlight ...
0
votes
1answer
80 views

Statusline – update variables on file change

I'm currently learning Vimscript, but I'm stuck at a particular problem. I'm creating a statusline which shows the full path (~) of the file currently displayed in the buffer. Instead of just using %...
0
votes
1answer
54 views

Vim multi-line substitute/insert once on selected text

I tried to make a function function! WrapSelect (front, back) "puts characters around the selected text. execute '''<, ''>s/\%V\(\_.*\)\%V\(\_.\)/'.a:front.'\1\2'.a:back.'/' nohl ...
2
votes
1answer
204 views

Can't echo messages from inside async functions

CASE 1: Have your autocmd command be setup like this: autocmd User ALELintPost call SayHello() " ALELintPost is async And your SayHello function set up like this function! SayHello() abort ...
1
vote
1answer
72 views

how to know if the current file in the buffer is a (.)dotfile using vimscript?

I changed vim backup directory to be stored on .backup folder in my dotfiles local repo set undodir=$HOME/.dotfiles/backup//. it works well as expected but i want to separate actual dotfiles ...
0
votes
1answer
40 views

How to apply a custom highlight file?

I'm playing with Vim highlight, so I made the following (syntax.vim): hi Comment ctermfg=DarkGray hi LineNR ctermfg=DarkGray hi CursorLineNR ctermfg=Red hi String ctermfg=Gray hi PreProc ctermfg=...
6
votes
2answers
1k views

How do I check if Vim is currently recording a macro?

Is there a way to programmatically check if Vim is currently in the recording mode triggered by q?
0
votes
1answer
77 views

Do nothing in :windo if condition does not apply

Consider following autocommand if exists('##OptionSet') augroup update_netrw_window autocmd! autocmd OptionSet wildignore \ let currwin=winnr() \ | windo ...
1
vote
1answer
32 views

How to insert special keys (like <return>, <m-r>) into macro registers with script?

I tried let @q = '<return>' and it obviously won't work
0
votes
1answer
163 views

Open and Close Syntastic window with one mapping

I have :SyntasticCheck mapped to F8 in my .vimrc. map <F8> :SyntasticCheck<CR> This open the Syntastic window on a split. I would like to close it with the same mapping. Closing is done ...
1
vote
1answer
93 views

Show external command output in preview window

Lets say I have the following cmake file (with | being the cursor). cmake_minimum_required(3.2) project(myapp) add_exe|cutable(myapp main.cpp) Now if I go to terminal and consult cmake documentation ...
1
vote
2answers
867 views

How to check if a shell command exists

I'm now using silent! let l:status = system(l:command . ' > /dev/null') if match(l:status, '\cunknown') != -1 || match(l:status, '\cnot') != -1 echo 'command not found' return 0`enter ...
0
votes
0answers
142 views

Change color of character covered by cursor

I'm using xfce4-terminal and the cursor is green, which means that green text behind the cursor is not visible or is hard to see. Is there a way to force the etext behind the cursor to be some ...
0
votes
0answers
28 views

`vim.eval('a:items')` fails if 'a:items' contain `BOM HEADERs`

I am using a pluging ctrlp-py-matcher, which is using the python interface to vim. My VIM is compiled with python3 support VIM - Vi IMproved 8.1 (2018 May 17, compiled Jul 1 2018 10:45:10) Included ...
1
vote
1answer
115 views

What does g'\“” mean?

Also, how can I go about finding out what a sequence means? Lets say I see a command au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif and I ...
0
votes
2answers
80 views

String comparison not working as expected!

So I want to figure out the Operating System and execute a piece of code based on the operating system in my .vimrc. However, I'm not able to understand where I'm going wrong. let operating_system = ...
1
vote
2answers
122 views

Vim autocommand based on username - print message

I have a function in my bashrc that checks if a file is writable with [ -w "$1" ]. If it is, I open it with vim normally. If it's not, I open with sudo via sudo env HOME="$HOME" vim -u ~/.vimrc "$1" ...
0
votes
1answer
164 views

How to use a value stored in a variable in the command mode?

Consider the following function function! AbbreviationsOpen() "go to the first word of the last line normal G "store the word in the register named a let @a = expand('<cword>') ...
1
vote
1answer
285 views

How to print an option's value to standard output?

I'd like to know if a file uses LF or CRLF line endings. I'm on Windows with vim installed. I don't want to convert the files, just know which line endings they use. I know I can get the file format (...
1
vote
1answer
81 views

Toggle comments

I'm trying to cerate a function who toggle a block of code into comments. I did this: " Commenting blocks of code. filetype on augroup commentgroup autocmd FileType c,cpp,java,scala let b:...
1
vote
1answer
95 views

VimL functions to differentiate between File Exists and File Readable

Because on Linux, there is possible that file exists but is not readable by the user (I rather don't think it is feasible on Windows, but...), I seek for VimL functions to differentiate between those ...
0
votes
2answers
366 views

Operate on a visual selection by looping through the lines

I'm looking for an approach, in Vimscript, to operate on the text lines of a buffer by looping through lines of a visual selection. Specifically, my goal is very simple: I have a (vertical) list of ...
0
votes
1answer
37 views

How to invoke mapped `i_CTRL-W` in function

First I will describe what I am trying to achieve: In general I use set iskeyword+=- as I see this more usable (one should always put spaces around operators when needed). This is quite helpful, but ...
1
vote
1answer
49 views

Filter list of jobs (started with job_start()) by status

I have built a list containing the "job" object as returned by job_start. The code populating the list is: let g:sc_instances = get(g:, 'sc_instances', []) let l:job = job_start('my command and args')...
1
vote
1answer
61 views

Get <Leader> value as <Space> and not ' '

Given that I defined let mapleader="\<Space>", I would like to get in the vimscript the value of the leader as <Space> and not as ' '. The latter may be obtained by using get(g:,"mapleader"...
2
votes
0answers
53 views

How do I pass a full filepath to a function in a Vim plug-in?

I have an exe program that checks for certain errors in a text file. I want to create a shortcut (like \+M) to run that exe file against the text file. My exe file's path is C:\Users\xyz\Documents\...
1
vote
2answers
96 views

How to get all/global match results for a string?

With vim script I can do let found = matchstr("abbaba", 'a') and get back "a" as a result. How would I matchstr to get back a list of all matches for the string? found == ["a", "a", "a"] as in g/a/
2
votes
1answer
48 views

How to determine the bit-width of the Number type in Vimscript?

I want to figure out the bit-width of the built-in Number (integer actually) of Vimscript . In particular, I want to tell whether a 32-bit or 64-bit integer is in use. Currently I test whether the ...
1
vote
1answer
39 views

jobsend sends no data even though return code is 1?

So I am trying to send some json text to a python script with jobsend in neovim like this: let l:json_msg = json_encode(a:msg) call jobsend(s:vimwatcher_job, l:json_msg) If i echo l:json_msg I can ...
5
votes
1answer
65 views

Can I block vim from saving a file that isn't validated using an outside tool?

I'm trying to find out if it's possible to make the write ":w" command perform a forced validation for certain file types. My use case is that I want to prevent small typos and idention errors in ...
2
votes
1answer
206 views

VimScript “unknown function” on a lot of functions

So I have been writing a vim extension but it simply does not make sense to me. I am using nvim and clearly see the function chansend in the documentation yet I get "Unknown function: chansend" when ...
2
votes
1answer
85 views

Convert a search and replace to a function

Given this search and replace expression, which works fine on one or multiple visually selected lines: :'<,'>s/\v.{-}(`.{-}`).{-}(\\'.{-}\\').*/$this->execSQL('DELETE FROM \1 WHERE id = \2;')...
1
vote
1answer
79 views

BufNewFile doesn't work from ftplugin

I have below autocmd in my cobol.vim ftplugin file in ~/.vim/ftplugin/ augroup cobmods autocmd! autocmd BufNewFile * call s:CleanStart() augroup END This doesn't work when I open a file ...
3
votes
1answer
70 views

Is loadview conflicted with readonly mode?

When i used following code to keep my folder view, it seemed that vim -R and view don't work at all (Only [readonly] was shown but it didn't work at all). Is there any misunderstanding about it? " ...