We changed our privacy policy. Read more.

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
13
votes
1answer
2k views

Execute content of buffer as vimscript

I have a nofile buffer that contains vimscript, and I want to execute it. However, :so % will not work because it requires a saved file, not a buffer. Is there a vim command to do this by default? ...
7
votes
1answer
192 views

Is it possible to make a numerically-prefixed hotkey run a function that many times?

I find that if you enter a numeric prefix prior to executing an ex command, the convention that it applies is to set up the command to prep an operation across a line range. It is explained in the ...
8
votes
1answer
297 views

Run a cmap only when searching

I have the following mapping: cnoremap <silent> <CR> <CR>:echo 'Enter pressed'<CR> This works as expected; the :echo command runs every time I press <CR> in the command ...
4
votes
2answers
2k views

Check if value matches any regex in a list

I have encountered some situations where I need to check if a value matches a regex in a list of regexes. For instance, say I have a list of regexes which match filetypes: ['gundo', 'nerdtree', 'git*...
9
votes
2answers
2k views

Manipulate chars with their ascii code

Let say I have let l:letter = 'A' is there a function that takes l:letter ascii code and transforms it to 'B'? I mean something like let l:next_letter = l:letter + 1 I know there's <Ctrl-A> ...
11
votes
1answer
2k views

Several lines instructions

Is there a way to split a one-line instruction into several lines? For example, I'd like to transform setlocal variable_name = condition1 ? "1" : condition2 ? "0" : condition3 ? "a long string" : "...
3
votes
3answers
2k views

How to execute a command in an inactive window

I was playing around with the MiniBufExplorer plugin, and I thought it would be nice if the MBE window could stick to the bottom of my ViM screen, even if I specifically open a new window with e.g. :...
6
votes
2answers
2k views

How to programmatically visually select a text block?

Is there a way to select a text block (e.g. a first word "TODO:") programmatically (with some commands or functions from a script)? Not simply highlight, like with a search, but visually select like ...
4
votes
1answer
872 views

User-defined sorting precedence

Is there a way to define a sorting precedence regarding the line's pattern and then use it with :sort? For example, if I have these lines: 1 some text (foo) some other text 2 some text (bar) some ...
38
votes
4answers
8k views

How do you “chomp” a string in Vim?

Suppose you run the following piece of vimscript: let @z = system("date") This will put a string version of the current date into the z register, but the string will end with a newline that I don’t ...
2
votes
2answers
417 views

Tips for quickly formatting a single line of XML?

I have a log file with lots of web service XML data (example follows). Ideally I would like to just go to a line and type ,x to create pretty formatted XML for readability. Response XML: <...
3
votes
2answers
481 views

Highlight longest common subsequence between two files? line by line

I'm asking about some sort of specialized diff highlighting mode. I need to diff, line by line, files A and B, which look similar to this in vimdiff: A B repo/manipulate_1....
2
votes
2answers
744 views

Pipe shell command into buffer in real-time

I wrote this little function to update my plugins from within vim: function! UpdatePlugins() call system('for f in ~/.vim/bundle/*; do cd $f; git pull; done') endfunction command! UpdatePlugins ...
4
votes
1answer
900 views

How to make a movement function work with delete, yank, etc

In hope of answering Using the % command on a line without a bracket I tried to write my first Vim script. My thought was to check if there was a { on the current line. If there was one I wanted % ...
8
votes
2answers
2k views

How to design a command in a plugin that can be called from vimrc

I'm working on a plugin that allows users to create custom operators. The operators would apply a VimL expression to the motion or text object that the operator moves over. Keeping a clean user ...
8
votes
1answer
3k views

How to change the value of timeout for one key command?

What I want To temporarily change the timeout value for certain key commands Where I've looked From :help 'timeout' I have : The timeout only happens when the 'timeout' and 'ttimeout' options tell so. ...
9
votes
2answers
3k views

How to write condition with regular expression?

I'm aware of the following comparison: if @% == "/tmp/crontab.zi5NeVPGRc" set nobackup set nowritebackup set noundofile set noswapfile endif But how can I use regular expression? For example ...
2
votes
1answer
194 views

How do you get which "side" of the visual mode selection the cursor is on in vimscript?

I'm writing some vimscript and would like to preserve the cursor position after a yank occurs in visual mode. Ths issue is that I can't find any way to get the cursor position while in visual mode. ...
2
votes
1answer
44 views

How to repeat register on assignment to another register?

I'm trying to repeat register couple of times and assign it to another register whilst concatenating the strings. For example: let @d = '<td></td>' let @r = '<tr>' . 10@d . '</...
12
votes
2answers
2k views

Do VimScript functions have to start with a capital letter and if so, why?

Is there a good reason why VimScript functions that I put in my .vimrc or _vimrc have to begin with a capital letter?
3
votes
2answers
260 views

write a key command for a markdown comment

I've been messing about with file type specific commands this evening (which is going to be very useful) and I'm trying to write a markdown comment command at the moment. I'm not sure how to go about ...
7
votes
1answer
1k views

Writing modified buffer to a temporary file

I'd like to write the modified buffer I'm currently editing to a temporary file periodically. In the background I could then, for example, use external tools to analyze the file. I don't want to ...
11
votes
1answer
1k views

Is it possible to create custom "set" commands in my rc file and call them from a modeline?

I recently asked a question in which I learned that it is not possible to pass anything except parameters to :set in vim modelines. I understand the security concerns, but I'm wondering if there isn't ...
10
votes
1answer
2k views

Using a variable in a regex pattern [duplicate]

I'm trying to write a function that will delete each line that matches a pattern. But that pattern will change based on the words held in a list (made from a dictionary). I was thinking it would be a ...
60
votes
6answers
18k views

Detect OS in Vimscript

Can I retrieve the current operating system (Windows, Linux, OS X, ..) using pure Vimscript (no Python or Perl)? I want to enable different settings in my (synchronized) .vimrc for different types of ...
20
votes
2answers
6k views

How do I check the value of a Vim option in Vimscript?

In Vimscript, how can I check the current value of a Vim option? To elaborate, I want to make a command to switch from Full-GUI Mode ( guioptions=+tM) to Hacker Mode (guioptions=-tM). However, I can'...
3
votes
3answers
307 views

How do I extract the parameters from a URL in Vim?

If I type a URL and I want to extract the parameters from the query string quickly in VIM how would I do that? For instance if I have: http://www.somesite.org/page2014.html?utm_source=facebook&...
4
votes
1answer
231 views

Absolute script-file line-numbers in Vim-function errors

When Vim reports errors within a function it typically reports relative line numbers. For example: Error detected while processing function Foo: line 11: E123: Blah blah Here indicating the issue ...
3
votes
2answers
228 views

Scroll buffer-window whilst Ex-log open

From time to time I do a source of a script and N errors and warnings manifest. As the errors/warnings show it is impossible to scroll buffer/window. Cursor, at least in gvim is a bold white x. The ...
39
votes
3answers
16k views

How do I get the name and extension of the current file?

Is there a way to get the name and extension of a file using vimscript? If so I would like the name and extension separately.
43
votes
5answers
13k views

How to make a vimscript function with optional arguments?

I want to make a function that has optional arguments. In python I would do something like this: def functionName(arg1,arg2=false,arg3=false): if arg2: #Do stuff with arguments else: ...
4
votes
1answer
3k views

Vimscript save file

I am making a function to compile and run my application. I have been able to get it to run the shell command however I cannot get it to save the file. Here is my code so far. Try 1) function ...
9
votes
1answer
6k views

function to call shell script with arguments

I am making my own function to call a bash script that compiles and runs my program. Here is the code I have tried. function Compile_and_run(game, major, minor) !_compile a:game a:major a:minor ...
4
votes
1answer
654 views

Following a tag in a VimScript

I am working on an omni-completion script where I use taglist() to search for the existence of a certain word. After obtaining that tag I now need to quickly jump to where the tag is defined and ...
6
votes
1answer
612 views

Why don't I get syntax highlighting when I open a file in an autocmd?

While trying to devise a solution to How do I make vim look in a set of directories for a file, if it doesn't exist in the current directory?, I have got so far using Python: function LookupFiles ...
17
votes
2answers
3k views

Is cpo&vim a special syntax?

In scripts it is customary to do something like: let s:save_cpo = &cpo set cpo&vim ... script ... let &cpo = s:save_cpo To ensure nocompatible mode for the script. Is: set cpo&...
36
votes
2answers
11k views

What's the difference between let and set?

I don't know much of the theory behind Vim. It looks as if we set some variables, and let other variables. What's the difference, and when is one required over the other? Also, the solarized vim ...
14
votes
2answers
259 views

Automatically add a closing " or ' when inserting one, but only if the cursor isn't inside a string already

I've defined mappings in my vimrc to automatically enter close parentheses and braces when I enter opening ones with inoremap ( ()<esc>i. I'd like to do the same for " and ', but only when the ...
8
votes
2answers
379 views

Automatically delete closing pair without causing unbalanced pairs

I am writing a VimL function that, in insert mode, allows a <BS> through the opening part of a pair ([, {, etc.) to delete the closing part of the pair if it is the next character after the ...
7
votes
1answer
646 views

Can I pass a custom string to the 'gx' command?

I have a file like this: vi.stackexchange.com example.com duckduckgo.com I want to be able to open these sites with gx; this doesn't work because there's no protocol (http://) in front of these ...
4
votes
1answer
395 views

Making a box in vim via python

I am attempting to learn more about scripting vim and writing plugins with python, but I'm having trouble getting started. Although I've read :h python (first step, read the manual), I had trouble ...
6
votes
0answers
817 views

Resources for scripting vim with python [closed]

I love vim, I love python, and I dislike vimscript. So I would like to know how to write plugins (or throwaway scripts) for vim in python. Of course, the first reference should be :h python, but I ...
17
votes
4answers
831 views

Set the paste option, but for one insertion only

I want to have a quick way of setting the Vim 'paste' option, inserting some text, and reverting to the previous value of 'paste'. A typical use case insert the OS clipboard content literally, ...
2
votes
1answer
1k views

Autocommand groups syntax and usage [closed]

What are some of the ways to construct autocommand groups in the .vimrc? What is the benefit of grouping autocommands? Can you provide some materials on proper use of autocommand groups? Any help here ...
9
votes
1answer
984 views

Regex that prefers shorter matches within a match? (This is more involved than non-greedy)

I'm trying to create a script for performing fuzzy search inside a buffer. The main idea is to take some input, and insert .\{-} between every pair of characters, e.g. foo becomes f.\{-}o.\{-}o. This ...
7
votes
2answers
2k views

Jumping to a file in vimscript

Using gF I can jump to a file with the format foobar.py:27:6 to open foobar.py on line 27. My question is how I can make this jump in vimscript? For example, this won't work: execute "normal gF " . ...
6
votes
2answers
2k views

How do I search for a line that contains a pattern at column n

In writing some Vimscript to try to answer this question, I was exploring ways to "search for a line with pattern P in position X" (P is a search pattern, X is a number). One way to do this would be ...
5
votes
1answer
810 views

What is an effective way to learn vimscript? [closed]

Let's say I've been working with vim for some time; I've dabbled with my ~/.vimrc and copied-and-pasted some snippets in I find on the way, with minimal changes. I'm beginning to get a hazy ...

1
21 22 23 24
25