The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
37
votes
5answers
10k 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 ...
13
votes
1answer
7k views

How to use a variable in the expression of a 'normal' command?

How can one use a variable when executing something via normal! in vimscript? Example: function! MyFunction(someArg) normal! (a:someArg)l endfunction This should move the cursor someArg steps ...
18
votes
2answers
924 views

The simplest way to start Vim in private mode

I want to be able to easily start Vim in a private mode. Let's define a private mode as one that utilizes this set of commands: set history=0 set nobackup set nomodeline set noshelltemp set ...
18
votes
1answer
2k views

What is the difference between single and double quoted strings?

What is the difference between single and double quoted strings? Is there a way to get a variable expanded inside a string, or do they always need to be joined like: 'Hello, ' . s:name . '!'
7
votes
1answer
778 views

Is there any way to distinguish between neovim and regular vim?

I was trying to migrate to neovim from vim. But in the end, there's some plugins which require python3 support and neovim package doesn't build with python3 by default( I'm on ubuntu, install neovim ...
4
votes
3answers
1k views

How to format a mapping to an if statement?

I'm had some trouble defining a mapping in my .vimrc. I want <leader>sv to source my .vimrc, but first I want to write, if I'm currently editing it. Goal The intention of the code is this: if ...
4
votes
1answer
344 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 ...
2
votes
1answer
492 views

How to remove inner content of html tag conditionally?

I've html file (e.g. curl -o page.html http://example.com/) where I would like to remove inner html block for given html tag. I've the following code which works: $ ex -V1 page.html <<-EOF /&...
1
vote
1answer
133 views

Unmapping filetype mappings

I'm trying to unmap some key sequences mapped by python filetype plugin. While I know a better way, I'm still curious if it can be done with autocommands. Here's what I've got so far: augroup ...
25
votes
6answers
4k 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 ...
16
votes
4answers
554 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, ...
32
votes
3answers
6k 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 ...
15
votes
3answers
2k views

Why does vim allow integer division by zero?

I just discovered that vim obviously allows division by zero: :let a=42/0 :echo a prints 2147483647 (which is the value of a). Is this documented somewhere and why does vim allow division by zero?
10
votes
1answer
820 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 ...
6
votes
2answers
2k views

How to iterate over buffers in Vimscript

How can I iterate over the current open buffers and say, load the buffer numbers into an array in vimscript? I know there exists arrays or similar data structures in vimscript. I know that every ...
6
votes
1answer
304 views

Display current subroutine/subprogram in statusline

I am currently coding fortran, and I have huge "subprograms" (called "subroutine" in fortran). So I would like the name of the current subroutine (the subprogram my cursor is currently in) to be ...
9
votes
1answer
584 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" : "...
6
votes
4answers
644 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
4
votes
1answer
777 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 % ...
0
votes
1answer
381 views

How can I disable square-bracket-prefixed mappings, so I can then remap a single-press square bracket without having to wait for the “timeoutlen”?

I was looking through the default mappings for square brackets, and I really don't need most of that functionality. I would like to disable these mappings, then use nnoremap [ [[ and nnoremap ] ]] to ...
7
votes
2answers
644 views

vimscript conditional based on grep on current buffer

I'm looking for a way to execute some code within a function conditionally depending on the presence of some text within the edited file. I found a way to do it which works but doesn't feel very "...
6
votes
1answer
243 views

Is there an autocmd-like event for when operator pending mode is entered?

I'd like to make a plugin to display currently pending keys while in operator-pending mode. As the first part of that, how would I register an autocmd to run when operator-pending mode is entered? I'm ...
6
votes
1answer
528 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 ...
5
votes
1answer
445 views

Interrupting (blink-highlighting) function if mapping is invoked again

I have an adapted version of Damian Conway's Die Blinkënmatchen in my ~/.vimrc that "highlight-flashes" search matches as I step through them with n / N: " 'hlsearch' makes it hard to tell which is ...
5
votes
1answer
227 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
2answers
137 views

Replace text and move cursor to end of replacement in insert mode

How can I perform a search-and-replace and leave the cursor at the end of the replacement? I want to replace $...$ with \(...\) as I type in insert mode. Notice that I can't use an abbreviation, ...
1
vote
4answers
206 views

How to write incremental lines in Vim?

There comes a time where I'm in a situation of downloading multiple files. And the name of files are in series. Something like. http://www.example.com/files/images/img01.jpg http://www.example.com/...
1
vote
1answer
35 views

How to use the result of a function in a Vim keymap?

I have a function in Vim script that returns a string. " Return first directory with ".git" folder, if none is found " return the current directory function! s:project_root() for vcs in ['.git']...
1
vote
1answer
138 views

Visual mode toggle block commenting with vimrc command

I am trying to get vim to do block commenting and uncommenting of highlighted lines while keeping the correct indentation level. I am so frustratingly close. let b:commentChar='//' autocmd ...
0
votes
0answers
45 views

How to get the same message and error behavior as normal `n` when calling `normal n` in function

I wrote a vimscript function that prevents the cursor from changing its location on the screen when I press n: function! my_n() let l:start=line("w0") let end = line("w$") let cursor = ...
21
votes
2answers
6k 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 ...
11
votes
2answers
1k views

Is it possible to use a delegate or to pass a function as argument in Vimscript?

I am trying to create a small plugin to learn vimscript, my goal is to create some functions processing a selected text and replacing it with the result. The script contains the following items: Two ...
14
votes
4answers
1k views

How to reverse every 4 lines?

First of all, with this being my first post here, I'd just like to say that I've found VIM to be a great tool and the forum here to be very helpful in finding answers to questions, with lots of ...
6
votes
1answer
885 views

Visual scrolling/visual <C-e> and <C-y> across wrapped lines?

This has been asked on stackoverflow before, but it seems it still has no solution. Perhaps that has changed with Vim 8.0. I'd like to be able to scroll (i.e. scroll-wheel, or <C-y>/<C-e> ...
3
votes
1answer
3k views

Most annoying slow-down of a plain-text editor! [closed]

I am a happy user of VIM, except for some bits which I really want vim to improve on. One main issue is frequent slowdown of VIM spoiling the amazingly productive text-editing experience on a fastest ...
10
votes
2answers
1k views

How can you use vim as a stream editor? [duplicate]

Like most programmers, I perform a lot of repetitive tasks. In optimising my workflow, I'm taking some of those repetitive tasks, and refactoring them into shell scripts. One thing that I'm trying to ...
8
votes
1answer
4k views

vimL sleep within a function

I'm trying to define a function that will make it easier to see where the cursor is location by putting cross-hairs around it for 100ms. Here's my attempt: function! Flash() set cursorline ...
7
votes
2answers
812 views

Drawbacks of using Python to develop new code in a VIM plugin

In one of the vim plugins I use, we have been thinking about using python vs vimscript going forward (https://github.com/python-mode/python-mode/issues/813#issuecomment-344754563). I understand that ...
5
votes
1answer
850 views

Why `NERDTree` doesn't trigger the autocommand `BufEnter`?

I am writing a vimscript function which should keep in a consistent state a "home made buffer manager". The idea is that I want to keep a trace of my buffers in the tabs they were open in. This "...
13
votes
2answers
2k views

How to get the current byte offset in whole file

I saw that you could display the current byte offset in the statusline using %o, but I found no function or command which does the same. Is there a way of getting the current byte offset ...
10
votes
3answers
776 views

How to grep in ex command output?

How does one search for a pattern in ex command output? For example, how to search for a file name pattern in the output of :scriptnames command? In the help for all flavours of grep and vimgrep there ...
10
votes
1answer
1k views

Prevent refresh of screen until function completes

I have a function that does a lot of moving and outputting of text into the current vim buffer, and when I run it, seeing all that happening at blinding speed is a bit disconcerting. How can I ...
9
votes
1answer
1k views

How to check whether Vim is built as a 32-bit or 64-bit application?

How do I check if Vim is compiled as 64-bit or 32-bit from within vimscript? Specifically on Windows.
8
votes
1answer
164 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 ...
6
votes
3answers
2k views

Within a function, Is there a way to determine if vim is in insert mode?

Within a function, is there a way to determine if vim is in insert mode (or was in insert mode prior to calling the function)?
6
votes
1answer
374 views

How to allow count *before* my custom operator?

I'd like to define my own operator. Vim's builtin help has a nice little tutorial on it, where they show you can create your own operator with opfunc and g@: nmap <silent> <F4> :set ...
5
votes
2answers
211 views

Is there a better way to create this “semi-strong” left motion?

I'm pretty new to vimscript, and I wrote this little function to map H so that the cursor will go to the first non-whitespace character of the line, or to the beginning of the line if the cursor is ...
4
votes
3answers
556 views

Run a function once on every paragraph

I'm trying to write a plugin that highlights overused words. After much effort I managed to write a function (and a command, :Ditto) that will highlight the most used word in the file or in a ...
4
votes
2answers
349 views

Vim syntax highlighting for ChatScript language?

I'm looking for a ChatScript language Syntax highlighting, of course for the Vim editor. ChatScript is a great (underrated) open-source language to build chatbots dialog flows scripts, made by Bruce ...
3
votes
1answer
190 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 ...