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
2answers
432 views

How do I make abbreviations expand for minimal prefixes?

I want to create abbreviation for a large word, say configuration. Vim command works even if we type part of it. Example, s[ubstitute]. When you type s, su, sub, subs, subst, substi, substit, etc., ...
32
votes
2answers
11k views

Extract the result of a shell command to a variable in a .vimrc file?

In my .vimrc file, I would like to store in a variable the result of an external command, in my case: $ echo $LANG So that my .vimrc file would have : let language = output(!echo $LANG) if language ==...
4
votes
1answer
646 views

Current VimL script path from inside a function

How do I get the path to the currently executing VimL script from inside a function? I know from outside a function, you can use expand('<sfile>'), but if you call that inside a function, you ...
3
votes
1answer
643 views

Copying just the matches to a register?

I'm trying to copy just the matches in my regex search to a register in VIM on windows. That said, I found the following script for doing this: function! CopyMatches(reg) let hits = [] %s//\=len(...
0
votes
2answers
988 views

How to remove line breaks in xml tags?

I often have to write XML where text-width has been manually set by another editor: <context> <p>Here is a paragraph about some stuff that happened and someone did a nice ...
1
vote
0answers
135 views

How to compare two positions in a buffer?

Suppose i've got two different positions in a buffer returned by getpos() function: p1 = getpos("v") p2 = getpos(".") Is there a simple or elegant way to find out which one is before the other in ...
1
vote
1answer
52 views

How to write the output of `:au` in a file

I am debugging a plugin, and to do so saving the output of au into either a file or a temporary buffer would help immensely. Is there a way?
7
votes
1answer
247 views

What is a ^@ in vim?

I'm running a Vimscript that retrieves the result of a message and redirects it to a vimscript variable. When the contents of the vimscript variable are displayed, it has a ^@ in it. What does that ...
2
votes
1answer
506 views

Adjust syntax highlighting for region included with syn-include?

I have a terminal color scheme that makes the default highlighting settings for diffs relatively hard to read. To address this, I’ve added my own custom settings inside of ~/.vim/after/syntax/diff.vim:...
4
votes
2answers
1k views

How to make an autocommand run for closing a window?

There is a (moderately complicated) way to make an autocommand that only runs when windows are created, but I want to have one for when they are removed as well. The reason is that whenever a window ...
6
votes
1answer
1k views

How do I use a variable with an ex command?

I wrote a moderately complex routine for Vim and I need to programmatically set the height of windows. The way to do this is with :resize [N] as the help says. But my invocation didn't work until ...
3
votes
1answer
127 views

How to display the counts of lines in a git patch / hunk?

In git when patching you have to count: The "leave alone" lines The "remove" lines The "add" lines The "leave alone" + "add" lines I've found ways to count all of these... %s/^ / /n "leave alone" %...
27
votes
6answers
5k views

How can I really have some fun in Vim? [closed]

I love Vim. I spend my whole life using it: At work I develop code with Vim, I edit config files with it, I write my emails with it. At home I write my todo lists and my buckets lists with it. On my ...
3
votes
2answers
315 views

How to restore a search highlight state after searching for trailing space?

I would like to: First, save the current highlight state (nohlsearch? or hlsearch?). ...the current cursor position and the current search pattern. Then search for the trailing spaces, highlighting ...
7
votes
1answer
599 views

Why is there a limit on the number of function arguments?

I am reading :help :call, which states the following: Call a function. The name of the function and its arguments are as specified with :function. Up to 20 arguments can be used. This makes me ...
5
votes
1answer
2k views

Is there a function which can return a list of matching text for groups in a regex?

Bash can natively match regular expressions in the [[ ]] construct, using the =~ operator. When it matches something, the result is stored in the BASH_REMATCH array variable. BASH_REMATCH contains, in ...
11
votes
2answers
480 views

Is there a way to detect if I'm recording in vimscript?

Is there anything like eval("is_recording()") that I can call in my vimscript to find out if I am currently recording a macro? I would have thought this works: eval("mode(1)") but that just ...
2
votes
1answer
540 views

Function to refactor indents and tabs

I'm writing a vim function to set hard tabs and refactor indents in a whole file. This is the function: function RefInd() :set tabstop=4 softtabstop=0 noexpandtab shiftwidth=4 gg=G ...
4
votes
1answer
2k views

How to use a range function in a normal command?

:set cc=1,5,9,13,17 The command above here can create a series red lines on the edited file in vim whose version is lager than 7.3. Why can't write it as :set cc=range(1,17,4) ?
4
votes
2answers
1k views

How to move the cursor to the next match in VimScript?

How does one move to the next match in Vimscript? The way you would when matching an expression and then hitting n?
7
votes
4answers
1k views

Store the number of matches in VimScript function?

Is there any way to store the number of matches in a variable in a VIMScript function? For instance I'm using: %s/,//gn
2
votes
1answer
1k views

How to get info on set cc=number?

set cc=10 The simple command for vim version greater than 7.3 can create a red line from top till bottom on the 10th column. I want to get more info about "set cc=number" such as 'can make the line ...
5
votes
2answers
373 views

Skip over character in insert mode, even at the end of a line

I have this map in my .vimrc: inoremap <C-space> <C-o>l So that, eg, if I'm in insert mode: I can just type <C-space> to move out of parens: It all works great in the middle of a ...
3
votes
2answers
1k views

How to handle a nested dictionary with mixed key/values?

I would like to create a dictionary variable for a vimL script. That dictionary will hold information related to a folder structure. However, I have a bit of hard time designing this variable and also ...
5
votes
1answer
291 views

Putting the value of an argument into part of a regex in vimscript?

Is it possible to pass a variable to a function in vimscript, and then use that value in a search and replace regex? For example: function! AddTW5Links(tiddlerSetName) %s/\(*\+\)\(\[\[\(.*\)\)\...
3
votes
1answer
1k views

How can I convert this remap to a <expr>?

N.B. my question title might be poor, so feel free to improve it. Background I want to write a command to move my cursor to the body of my email, add blank lines, and change to insert mode. Previously,...
3
votes
2answers
327 views

How to display messages for a particular file type?

Is there any way to display messages in vim depending on the filetype being edited? It would be good if the messages pop after some specified time interval. Use case We tend to forget style guide ...
1
vote
2answers
785 views

Casting in VimScript/VimL

Is there a syntax to cast from one character type for another? For example can you cast from a char to an int? I tried: let my_var = (int)some_char It is not valid code.
19
votes
2answers
2k views

What is the difference between set and :set (commands with or without a leading colon)?

I was looking at Tim Pope's vim-sensible plugin and I noticed this in the README... See the source for the authoritative list of features. (Don't worry, it's mostly :set calls.) When I looked at ...
18
votes
5answers
2k views

After copying a visual selection to keyboard, return to original location

My cursor is in the middle of a paragraph when I decide suddenly I need to copy that paragraph: So I type vip to select the paragraph visually: Now I hit cmd+C to copy to clipboard (this may vary on ...
2
votes
1answer
110 views

Skip a map in a specific circumstance

I currently have the following map setup to allow me to quickly create a pair of parens by tapping ( twice, leaving the cursor between them for more typing: imap (( ()<left> Separately, I have ...
2
votes
1answer
480 views

How to add some text to selected text and reselect it again in visual mode?

I'm using QuickRun to execute php files or part of php code by selecting it in Visual Mode. I have this mapping in my .vimrc nnoremap <leader>r :QuickRun<CR> vnoremap <leader>r :...
4
votes
2answers
979 views

How to visual select from vimscript

In Mac OS, I am trying to write a function that will say the current paragraph without moving the cursor, but something doesn't seem to work. This is what I have so far: function! SayIt() let l:...
6
votes
2answers
3k views

Append to global variable and completion

I would like to create a global (configuration) variable that ideally would work as a comma separated list but that we could also append to it. The idea is to have the same behavior as when using += ...
3
votes
2answers
3k views

What's the difference between call and execute?

E.g., in this snippet if words[0] == "\"spellgood:" call remove(words, 0) for word in words execute "silent spellgood! " . word endfor endif taken from "The first ...
8
votes
3answers
2k views

Tutorial for vim programming? [duplicate]

I am a veteran user of vi. When I started using it, there was basically nothing... Now, we have vim. But, how do I program it? Where does one start? With help? Not sure this is a good start.
5
votes
3answers
4k views

How to access a custom python module inside vim?

This is a Python 2.7 question. I have a custom python 2.7, that I have compiled and have been using successfully across my system. My custom python has the YAML modules installed as well. The system ...
5
votes
1answer
532 views

Vim Function to Send Highlighted Text to a Git Commit

Problem: Suppose I have the following text in my vim buffer: This is a commit msg. Suppose further I have a git repo located at ~/my_repo. Goal: Make a vim script so that I can highlight the text ...
2
votes
0answers
80 views

How do I resolve Error E108: No such variable: “b:eclim_tab_id” in textfmt plugin v3.0?

I manually installed the txtfmt plugin (Brett Stahlman's The Vim Highlighter) ver 3.0. After trying to run :MakeTestPage, I get the following error: Error detected while processing function <SNR&...
3
votes
1answer
222 views

How I can make inputdialog() behave like input() on GUI?

I use dbext.vim for any database related work so I have several connections configured on my _vimrc and when I need to switch between them I use the DBPromptForBufferParameters that this plugin ...
8
votes
2answers
793 views

How safe is it to use an unknown `_vimrc` or `vimscript` file?

I do not know if this question should be asked here or not. In almost every language, malware exists. Is the same also applicable for vimscript? Suppose vim is running with high system privileges. Is ...
1
vote
1answer
337 views

How can I get path from vim-rooter's function and run it with QuickRun's makeprg?

How can I run vim-rooter's function FindRootDirectory() instead of /vagrant/my_project? I have tried multiple variations like: set makeprg=FindRootDirectory().'/app/Console/cake test '.expand('%:p') ...
4
votes
2answers
607 views

How to run custom console command and output results to QuickRun without pressing any key on keyboard?

Thanks to @muru I was able to run and output the data to QuickRun by the :make command and this setting in my .vimrc: set makeprg=/vagrant/my_project/app/Console/cake\ test\ app\ Console/Command/...
6
votes
1answer
994 views

How to cut/trim line in statusline?

I'm trying to cut string returned from fugitive plugin. It returns branch name of current file. By default returned string is Git(branchname) and this is why I want to get rid of odd Git(..) wrapper. ...
2
votes
2answers
185 views

How can I get path from vim-rooter's function and add it to another path VIM

I have this in my .vimrc let $ROOTPATH=FindRootDirectory() nnoremap <leader>ct :!clear<CR>:!$ROOTPATH/app/Console/cake test %:p<CR> Is there a way I can write this in one line? ...
2
votes
1answer
221 views

BufWritePost not working after navigating using netrw

I'm trying to deploy some static content upon writeing a buffer with an autocmd: augroup dep autocmd! autocmd BufWritePost myProject/frontEnd/** :call s:deploy() augroup END The s:deploy ...
4
votes
1answer
353 views

Does Vim compile user-defined functions?

If I define a function in my vimrc (or in a plugin), Vim will load it and I can use it. But what's happening under the hood after my vimscript is parsed? Is it transcoded down to C and compiled? Is ...
6
votes
3answers
435 views

Vimscript file rewrites itself and complains of a mismatched endfor

I want to remap <C-i>*character* to i*character*<Esc> for easy inserting of single characters. This is what I've written: let printable_characters = [ '!', '"', '#', '$', '%', '&', '''...
6
votes
2answers
744 views

Auto sorting of lists of include files

Many sections of stuff we right is such that it could be automatically formatted by user defined rules. Here are a couple of examples: List of include files in languages such as C. It is customary to ...
3
votes
1answer
271 views

Slow startup time unrelated to plugins

When I open vim (or gvim) on MacOS X, the window opens immediately, but there is a pause of about a second before the cursor appears. I've profiled my plugins, but their startup times don't account ...

1
18 19
20
21 22
24