People who code: we want your input. Take the Survey

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
10
votes
1answer
3k views

Usage of the =~ operator

I'm a little confused on VimScript's regex comparison operators. If I look through :h =~? my understanding is that =~ can be used to do a regex match (with the ? making it case-insensitive). But ...
2
votes
1answer
569 views

Plugin config settings: Newline “\n” returns ^@ control character?

I'm trying to configure the NERDCommenter plugin to handle multiline ruby comments (i.e., nested inside =begin and =end). The relevant setting is something like this: let g:NERDCustomDelimiters = { ...
3
votes
2answers
242 views

Vimscript `if` on based on highlighting file

I a have PHP syntax highlighting file in ~/.vim/syntax/php.vim. Thus, PHP functions are highlighted differently than my own custom functions and Wordpress functions. Therefore, VIM does have a way to ...
20
votes
3answers
2k 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 ...
2
votes
1answer
59 views

Can't seem to get syntax information when in insert mode

This is for an indent function that should maintain the indentation should the cursor happen to be in a string region. It maintains the indentation when I hit == in normal mode but changes when I open ...
5
votes
2answers
1k views

How to setup in `~/.vimrc` a mapping for `colorscheme` to toggle `solarized` between `dark` and `light`?

Both background and colorscheme in ~/.vimrc are badly misbehaving! I have setup solarized to work on vim and it can manually toggle between background light/dark. My general settings in ~/.vimrc are: ...
7
votes
1answer
768 views

How to convert hex to binary in Text mode?

I'm trying to convert hex values to binary. For example, I have got some text file containing: 0.0 010111010 B4 0.1 001001011 A3 ... And I'm trying to convert B4 to 10110100, and A3 too. But I ...
4
votes
1answer
328 views

Why do I need to use unicode for a control character in a mapping using <expr> and a function?

Let's say I've got the word foo in a file, I copy it in register a ("ayiw) and I define the following mapping: inoremap <expr> <F3> "<C-r>a" If I hit F3 while in insert mode it ...
2
votes
2answers
1k views

How to test if Vim supports <C-g>U?

I would like to make some modification to the code of this plugin. It adds / changes some default keybindings. Among them are <C-b> and <C-f> which move the cursor one character to the ...
4
votes
1answer
909 views

How to save previous cursor position inside a function which has received a range?

I have the following code in a file: function! s:TrimWhitespace() abort range " Save cursor position, because the following substitution will move it let save_cursor = getpos('.') " ...
6
votes
1answer
3k views

How do I convert a String to a Number, catching invalid strings?

I am trying to convert a String '1' to a Number (int) 1 in a vimL script. I have used the built-in command str2nr() so far, however I was not able to write this in an elegant and effective way. ...
7
votes
4answers
2k views

Is it possible to populate the quickfix list with the errors of vimscript functions?

I often write functions in my ~/.vimrc or in ~/.vim/autoload/myfunctions.vim, which when executed result in an error such as: Error detected while processing function SomeFunction: line xx: ...
4
votes
1answer
121 views

Mapping { with Vimscript

I have been trying to map { in insert mode to the following if the line contains any character other than blank or tabs: <CR>{<CR> and to {<CR> if the line is blank (contains at most ...
3
votes
1answer
299 views

How to run a function without getting prompted to continue?

In order to keep my tags file up to date I wrote this function which runs ctags -R . whenever I save a file. function! UpdateCtags() " assume if a tags file exists - then current dir is ok if ...
8
votes
1answer
324 views

How to escape significant keywords from syntax files?

I came accross this line in a syntax file.. it does not work: syntax keyword Type Transparent I guess this has something to see with the fact that transparent is a significant keyword for Vim. What ...
15
votes
3answers
9k views

Substitute with pure vimscript (without `:s`)

I have the following in my vimrc: func! AddSpaceBeforeEqual() s/\([a-z)_0-9"'\[\]]\)=/\1 =/ge endfunc I'm using vint to lint my vimrc, and got the following warning : ...
2
votes
1answer
868 views

As an argument of a function, when does a variable name need to be quoted?

If I define the variable foo like this: :let foo = '~/Desktop' And I want to check the length of the string it contains, then I can type: :echo strlen(foo) The output is 9, which is right. If I ...
3
votes
1answer
1k views

How to execute a string of conditional commands which includes a shell command?

I currently have the following auto-command (in my vimrc) - autocmd BufEnter *.c nmap <F5> :Makexec<CR> \:if findfile( expand("%:p:r").".exe" ,expand("%:p:h") ) != ""<CR> \ :...
7
votes
1answer
571 views

When is it recommended to use the scope s: and the argument abort to define a function?

When defining a function, is it always recommended to use the scope s: to make it local to the script and avoid overwriting a function with the same name in the global namespace ? And is it always ...
2
votes
0answers
125 views

escaping a character included in a conceal command vimscript

I'm playing with conceal in help files to highlight / colour specific text strings which was working fine until I added the :print: example below. Using this concealed all the : as expected so I ...
1
vote
0answers
330 views

NERDTree file extension highlighting issue: c files not highlighted

function! NERDTreeHighlightFile(extension, fg, bg) exec 'autocmd filetype nerdtree syn match ' . a:extension .' #^\s\+.*'. a:extension .'$#' exec 'autocmd filetype nerdtree highlight ' . a:...
3
votes
1answer
93 views

How to surround all headlines with empty new lines in a markdown file?

I have the markdown file that uses # for headlines, like this one. #H1 Text one one ##h2 more Text #more H1s Even more text No I have the problem that some interpreters of markdown don't accept a ...
0
votes
1answer
52 views

Why does the <count> escape sequence insert the current line number in my user command?

I've added the following to my .vimrc in order to test how <count> works in a user defined command because I was noticing odd behaviour: :command! -count=1 CountTest :exe "echo " . <count>...
5
votes
4answers
3k views

How to pass control characters, e.g. <c-e> to a function in a mapping?

I often find myself accidentally pressing <c-e>/^E while in normal mode inside a terminal buffer. This causes the terminal buffer to scroll down and a line with a ~ is displayed, like when your ...
7
votes
1answer
574 views

Adding text to the left margin

Is there an easy way to add text to the left margin of a vim document (to the left of the line numbers)? I know that it is possible to do because plugins such as vim-signature do it, but I am curious ...
3
votes
1answer
355 views

Visually select a few lines given start and end positions in vimscript

I want to write a function that will remove blank lines given a set of visually selected lines by the user. After removing the blank lines, I want the input lines still be visually selected. How ...
0
votes
2answers
1k views

How to add a control character inside a string executed by the execute command?

I would like to have a mapping that opens a buffer with all the lines containing the word under the cursor. I know such a mapping already exists in vanilla vim in normal mode [I. But I don't like the ...
6
votes
1answer
78 views

When is a function or special character automatically evaluated / expanded and why?

Let's say I've got the following function : function! SomeFunction() return "/tmp/foo" endfunction If I type : :echo SomeFunction() The function is evaluated and the output in vim is the ...
3
votes
1answer
288 views

Escape return value key in mapping function

I want to create a function for a mapping. The key for the mapping is configured through a variable. How can I escape the key in the return statement so it works? This works: let g:some_key = "<Up&...
4
votes
1answer
2k views

How to write message strings to a file using vim script?

I would like to create two functions, one for sending a message string to Vim's own messaging system and one to dump the message string to a file. Now, I have already progressed in figuring this out ...
2
votes
1answer
251 views

Extra character after pasting yank text into command line

I have a line of vimscript in my buffer like: call MyFooFunction(1,2) and I'm trying to execute it quickly. So, I yank it (yy), invoke the command line (:), and paste it in with <C-r>" But, ...
12
votes
2answers
2k views

What to follow to create a vim plugin?

So my question is simple. Is it a good idea to learn vim scripting just to create vim or we should adopt some other more accepted languages to that. For example This link opens a YouTube videos which ...
1
vote
4answers
274 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/...
0
votes
1answer
1k views

How to make sure every 'echo[msg]' command is visible?

I have a couple of functions chained together to verbose messages in my status line in MacVim. I have noticed that in one particular occasion a line is blank and is not delivering the message it is ...
0
votes
1answer
195 views

split/join lists -> E492

I'm trying to join a list within a function like this: let mylist=split(globpath(&rtp, 'custompath/*')) mylist=join(mylist,"\n") But I'm getting: E492: Not an editor command: mylist=join(...
5
votes
1answer
1k views

How can I avoid warnings about unused variables?

I have some code in my ~/.vimrc that (simplified) looks like this: function! SomeAppendFunction() let failed = append(0, ["Some header text"]) endfunction command SomeAppendFunction :call ...
1
vote
1answer
174 views

Getting different behavior for different numbers of arguments in a custom command

I'm trying to make a custom Vim command to compile code without having to do :!gcc -Wall %:p -o %:p:r every time. So far, I've been using this: :command Com w<CR>! gcc -Wall %:p -o %:p:r But ...
7
votes
1answer
1k views

Is there a way to get the name of the current function in vim-script?

Is it possible to programmatically let a function knows its own name? What I am looking for is something which would allow me to write this code (or something similar): function! myUtils#TestMe() ...
13
votes
1answer
6k views

Get the current window/buffer/tabpage in Vimscript

In python, when using the vim module, it is incredibly simple to get the current window/buffer/tabpage: current_win = vim.current.window current_buff = vim.current.buffer current_tabpage = vim....
1
vote
0answers
144 views

How to undojoin changes made from neovim remote plugin on TextChanged

I'm writing a remote neovim plugin that automatically inserts parens into the buffer based on http://shaunlebron.github.io/parinfer/ What I'm struggling to figure out is how can I get :undojoin like ...
15
votes
5answers
3k views

How can I source a visual selection of vimscript?

If I have a couple of lines of vimscript that I want to test before putting in my vimrc, is it possible to visually select, then source them? I have tried make visual selection v, then motions to ...
4
votes
0answers
201 views

Set line breaks, word wraps and word searching for Thai and other non-latin languages

I can set the text width and can manually line break imported paragraphs with the following as an example. set textwidth=72 gqq I can also navigate English text files with the standard 'w' 'b' 'e' '*...
7
votes
2answers
1k 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 "...
3
votes
1answer
203 views

Match “n” or more words

I want to check if a string consists of n or more words. I use the following regex to check for 3 words, but the match returns true? :echo ' hello world ' =~ '^\(\s\{-}\w\+\)\{-3,}' How to make ...
13
votes
2answers
6k views

How to deal with string containing spaces in Vim script?

I have the following command in my vimrc: execute "set path+=".getcwd()."/**" It works well if current working directory is like /home/tamlok/my_work/. However, if the directory contains spaces, ...
6
votes
1answer
393 views

Fixing lag due to vim-troll-stopper plugin

I've recently installed a plugin called vim-troll-stopper. Some unicode characters are drawn exactly the same but have different meanings. I think they are called homoglyphs. Some programmers may use ...
6
votes
1answer
869 views

How to inspect the cursor position in Vim command line (Cmdline mode)?

How to inspect the cursor position in Vim command line (Cmdline mode) from Vim script? I would like to configure my Command-line mode key bindings in Vim to behave like in tcsh. In particular, i ...
5
votes
1answer
1k views

In an autocmd what's the use of the BufRead event?

I'm trying to learn a bit of vimscript and currently reading the 12th chapter of Learn Vimscript the Hard Way. In this page, the author says : A common idiom in Vim scripting is to pair the ...
2
votes
0answers
46 views

How to implement a check-in test for omni completion script?

I've been working in an omni-completion script for Vim that is becoming more and more complex. At this point I'm interested in implementing some kind of check-in regression test for the script. Any ...
0
votes
0answers
262 views

Window close event

For my vim plugin I try to catch an event when quickfix window is closed. I did it with BufWinLeave event. But it does not work when I have quickfix open on multiple tabs, because of 'Not when it's ...