Stack Exchange Network

Stack Exchange network consists of 174 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.

1
vote
1answer
24 views

Is there any `setvirtcol()`?

I'm looking for a way to precisely set the cursor position given a virtual column. Is there only :exe "normal! ".vcol."|"? NB: I need virtual columns as they're the only thing that I'm able to ...
2
votes
1answer
32 views

vmap and visual block: how do I write a function to operate once for the entire block?

I'm trying to write a simple function that wraps a visual selection of lines with Markdown ``` lines. Here's what I currently have: function! MarkCodeBlock() " Add Markdown code-block delimiters ...
1
vote
1answer
34 views

Check if key is already bound in vimscript / Map key only if not mapped already

I'm wondering if it is possible to check in vimscript if a key (or key combination) is already bound? I know about the :map command which lets me see visually which keys are bound to what actions, ...
1
vote
1answer
37 views

Function to toggle set colorcolumn

I like the set colorcolumn=80 option which highlights the column at 80 characters, however I find it annoying when working with multiple split windows. I'd like to have an option to enable or disable ...
3
votes
1answer
58 views

How to jump to a character offset in a buffer?

Vim has the command :goto to go to a byte offset in a buffer. Is there an equivalent for a character offset? If not, is there a better way to implement it than repeatedly testing the cursor's ...
0
votes
1answer
51 views

Function Unable to Fail: Breaks Macros

Vim functions do not seem to be able to fail without spitting out 3 unnecessary lines. For example, take this set of functions and maps: " NEXT / PREVIOUS " ~~~~~~~~~~~~~~~ " n and N always search ...
3
votes
0answers
31 views

How can I watch variables when debugging Vimscript?

I would like to have another pane active when debugging a Vimscript function which would show the values of chosen local variables and function arguments dynamically. Currently I have to echo or let ...
0
votes
1answer
29 views

What are the allowable characters in identifiers?

In Vim, what characters are allowed in identifiers, such as variable names and function names? I looked up the help for both variables and functions and neither one defines the allowable character ...
2
votes
0answers
36 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
29 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
68 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 ...
2
votes
0answers
26 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
41 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> <...
1
vote
1answer
62 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
25 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
24 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
55 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 ...
0
votes
0answers
35 views

Vim observe text edits in insert mode

I'm building a program that analyzes text in real time or live while the user is editing. The idea is to send all changes or text edits from insert mode to a separate process. The separate process is ...
1
vote
1answer
31 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
18 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
27 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
28 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 ...
0
votes
0answers
24 views

Why getchar() catches Ctrl-c depending on mapping?

Why getchar() catches Ctrl-c depending on mapping? I was using getchar() to catch Ctrl-c within a script a everything was passing correctly until I tried to charge it in vim without configuration (...
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
44 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
50 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
38 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
42 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
30 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
38 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
30 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
34 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
41 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
28 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
0answers
18 views

Is it possible to set up vim to autocomplete from a file in command mode

I have the following function: function s:Test() { let l:build_dir = $HOME.'/path/to/repo/.build' let l:node_modules = l:build_dir.'/node_modules' let l:bin_dir = l:node_modules.'/.bin' ...
0
votes
1answer
31 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 ...
0
votes
0answers
30 views

Is there anyway to look at the implementation of default commnads in vim

Talking about the default vim commands, I imagine that most basic commands are implemented in C++, but some are simply vimscript functions that use other commands. For example, ci" might be using T"...
1
vote
1answer
39 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 ...
0
votes
0answers
24 views

In Vim 8.0, how to jump to virtual column in a script?

I used to be able to use cursor(lnum, 1, vcol) to jump to line lnum and virtual column vcol. For some reason, now, in Vim 8.0, this no longer works; the cursor always jumps to the start of the line. ...
1
vote
2answers
182 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
31 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
35 views

Make viminfo file marks [0-9] only have 1 mark per file?

I plan to use the ~/.viminfo file marks (the ones that record the ten most recent lines and files) with fuzzy searching via grep so I don't have to type vim /full/path/that/is/very/nested/to/certain/...
0
votes
0answers
18 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
93 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
44 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
69 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
34 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
197 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
55 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:...