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
4
votes
3answers
2k views

Autocompletion Plugin for vimscript?

In recent days I use a lot of vimscript and it would be helpful to have some autocompletion. Like when I write jo the autocompletion would recommend me to write join. I have installed YouCompleteMe,...
2
votes
1answer
587 views

How to create a function with persistent output in the bottom of window?

I want to create a function which would have the same behavior as for example :tabs (the screenshot is in french but I'm sure most of you will see what I mean): I for now I have the folowing command ...
5
votes
4answers
2k views

How to shorten the result of `ls` to get only the file name and not the whole path?

I've been using Gvim for a while, but lately stopped using GUI options and went to just commands. :ls is used all the time, but I have a huge project and it is hard to see the file name quickly in the ...
9
votes
2answers
4k views

Include symbols in <cword>

expand(<cword>) gives me the word under the cursor, but it excludes symbols such as @ or .. For example, if I call it at the end of @word, it will get me word and exclude the @. Is there a way ...
6
votes
3answers
5k views

Read file from vimscript variable

I can run this snippit of code within a vimscript block: 0read /home/user/.vim/bundle/vim-lorum/lorums/lorum.js As expected, it puts the contents of "lorum.js" into the current buffer But, I need ...
2
votes
1answer
878 views

change color of section dynamically in vimscript

Is there a way to set the text color of an ad-hoc selection in vimscript? Something like: " change the text color of the first three rows to red :1,3 call changeTextColor('red')
13
votes
2answers
2k 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 ...
1
vote
1answer
749 views

Execute shell command in new buffer without switching to it

I want to execute a shell command in a new buffer from within Vimscript, but do not want to move the focus (cursor) out of the current active buffer. Currently I'm using the following function: ...
10
votes
1answer
2k 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 ...
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 ...
15
votes
2answers
423 views

Does Vimscript have an official name?

The name of the language sometimes known as Vimscript is a topic of debate. Some places use Viml (or is it VimL?), others Vimscript. Does it have an official name, and if it does, what is it and since ...
2
votes
3answers
229 views

How to find non duplicate <type:keywords> of a file?

I need a vim shortcut to display all non-duplicate struct names in the file being edited. I have made this C program which does this, however I have to leave the editor and execute the program in bash ...
2
votes
1answer
126 views

vimscript documentation header @tag reference?

Dumb question, but I can't find the answer in vim.org or Wikia - is there a reference for the @ tags (@Author, @License, ...) at the top of some of the vim scripts in the registry? For example, ...
4
votes
1answer
620 views

Vimscript insert after cursor

I am aware of the startinsert command which switch to insert mode as if the i key was pressed. With the ! it behaves like A. Do you know if there is some kind of option to go to insert mode like we ...
1
vote
2answers
75 views

Don't close regular + help window at once, reset a variable on keypress

I have this function and mapping: fun! TwiceToQuit() sil! q if v:errmsg == 'E37: No write since last change (add ! to override)' echohl ErrorMsg echo 'No write since last ...
1
vote
1answer
2k views

How to safely 'override' existing syntax highlighting file?

Okay the /usr/share/vim/vim74/syntax/sh.vim file that came with my system was apparently buggy, so I want to replace it with the version by "Dr. Chip" I know that I really should not edit the files ...
16
votes
2answers
982 views

How do I generate Vim documentation from Markdown notes or inline comments, or are there better ways to add documentation?

This is kind of two questions in one. Lately I've been spending a lot of time learning vimscript in-depth, learning vim's internals & taking my first steps writing vim plugins. During this process,...
11
votes
2answers
4k views

Vimscript: Help with Autoloading, Scope & <SID>

I've been working on modularizing & converting a code in my vimrc into some self-contained and reusable bundles/plugins plugins. I've run into an issue with autoloading & scope that I'm having ...
3
votes
1answer
394 views

Plugin nnoremap insert <CR> instead of executing command

I am writing a vim plugin that at one point define a buffer only mapping : function! s:DoStuff() tabnew " ... nnoremap <buffer> q :tabclose<CR> endfunction call s:DoStuff() ...
5
votes
3answers
1k views

How can I make a search in vimscript let n and N look for more?

I'm writing a script that does a search like so: normal /needle^M. This works like I want, except that I want to be able to use n or N to repeat the search. In case it helps, here's the full ...
1
vote
0answers
177 views

Using an environment variable name as function argument [closed]

I'm trying to figure out how to use an environment variable name in a function, passed in as a function argument, i.e.: function! myautoloadfunc#set_default_env_var(name, value) if empty($a:name) ...
6
votes
1answer
3k views

Copying a String to a Variable or a Register from Within a Function

I want to write a function which copies, say, the last word of the next line which contains keyword into a variable say var or any named register say l. I did something inelegant: function! ...
2
votes
2answers
159 views

Understanding Vimscripts Through an Easy Example

I want to write a function which takes two strings this and that as its arguments and replaces all instances of this with that. So the function should look like: function! ReplaceThisWithThat(this, ...
2
votes
1answer
829 views

Searching For a String Stored in a Register From Within a Function

If I have something stored in the named register n, then from the normal mode hitting /<C-R>n would search for what is stored inside the register. But suppose I want to write a function which ...
3
votes
3answers
3k views

How do I trigger an autocommand when user enters/leaves command mode

I'm using a really clever plugin that changes the line number style (relative/normal) contextually. Basically when you enter insert mode you have normal line numbers and when you leave insert mode it ...
3
votes
1answer
1k views

Get the offset/position of the current window in the layout

There may be any number of nested vertical and horizontal splits on a Vim screen. I'd like to find the (x, y) coords, in terms of columns and lines inside Vim, of the top-left corner of the current ...
1
vote
2answers
163 views

Persist autocmd per file (not per filetype) without vimrc

I have some autocmd triggering on TextChanged, that I want to have persisted between Vim restarts. I could make a big if-elseif construct in the vimrc, sure, but I prefer saving the autocmd only for ...
10
votes
1answer
5k 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 ...
5
votes
1answer
510 views

How do you convert between non-literal strings and literal strings?

I was writing a small plugin, when I decided that I should give the option of customizing which key triggers the plugin's function. Here is an example of this: let g:foo_key = "\<Tab>" While ...
6
votes
2answers
2k views

How do I conditionally set :colorscheme?

My .vimrc chooses my preferred color scheme (solarized) which is installed via plugin management system. Yet on some systems which don't have that plugin the :colorscheme solarized command runs but ...
36
votes
1answer
19k views

Call a Vim function silently

I wrote a little Vim function that moves the cursor to the first character of the current line. If the cursor was already on the first character, then the cursor is moved to the first column instead. ...
0
votes
1answer
258 views

Avoid Redraw When Running External Command

I do some automatic setup in my vimrc that calls git clone, before any other plugins (such as dispatch.vim) are installed. It's called after some other messages are displayed using echom, and I'd like ...
2
votes
1answer
628 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 /&...
4
votes
1answer
293 views

How can I get the syntax ID of a named group?

synID() lets you get the syntax ID associated with a particular character at a particular line and column. This syntax ID is useful for querying other aspects of the syntax highlighting group (such as ...
4
votes
1answer
158 views

Is there a way to make preprocessor definitions in vimrc?

I'd like to create a new symbol to use in my vimrc that's <normal>, so I do not have to type <C-\><C-N> to get to do the "go to normal mode" command, nor clutter the vimrc file with ...
3
votes
1answer
860 views

How to add an item to Vim context menu?

I want to add a new item to Vim context menu. I select a word, right click on the word, select the new menu item, auto delete rows contain selected word. How should i do?
14
votes
1answer
2k 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.
4
votes
2answers
1k views

How to check if file is binary?

Is there any way to determine within Vim that the file which I'm editing is either in text or binary format? For example: vim http://example.com/ vs: vim http://cdn.sstatic.net/vi/img/apple-touch-...
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
185 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
292 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
823 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 ...
37
votes
4answers
7k 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
407 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
466 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....