Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 4939

A scripting language embedded into Vim. It can be used to customize Vim to suit your needs and to create plugins. Also called VimL.

10 votes
Accepted

Adding text to the left margin

I think what you are referring to is called a sign by vim. Adding a sign seems to be a two-step process. First you define what it looks like, then you place it where you want. The basic syntax to de …
saginaw's user avatar
  • 6,876
7 votes
1 answer
621 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 rec …
saginaw's user avatar
  • 6,876
6 votes
1 answer
93 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 s …
saginaw's user avatar
  • 6,876
3 votes
Accepted

Mapping { with Vimscript

.') =~ '\S' return "\n{\n" else return "{\n" endif endfunction inoremap <expr> { <sid>InsertBrace() Edit If your vim version doesn't support vimscript functions, you could try …
saginaw's user avatar
  • 6,876
4 votes
1 answer
439 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 will paste the conte …
saginaw's user avatar
  • 6,876
3 votes
Accepted

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

You can represent the set of non-digit characters with the atom \D or with the expression [^0-9]. So, if your definition of an invalid string is any string containing a non-digit character, you could …
saginaw's user avatar
  • 6,876
3 votes

Append to global variable and completion

If you want g:myvar to be a string, you could define the following commands :AddMyvar and :RemoveMyvar: command! -nargs=1 -complete=customlist,s:CompleteMyvar AddMyvar \ if !exists('g:myvar' …
saginaw's user avatar
  • 6,876
1 vote
2 answers
2k 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 …
saginaw's user avatar
  • 6,876
3 votes
Accepted

Match "n" or more words

I don't know if it's correct, but to check if a string contains 3 words or more I would type this : :echo 'some random string' =~ '\v\s*(\w+\s+){2,}\w+\s*' For 4 words or more : :echo 'some random …
saginaw's user avatar
  • 6,876
3 votes
1 answer
1k 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 …
saginaw's user avatar
  • 6,876
4 votes
1 answer
1k 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('.') " Chec …
saginaw's user avatar
  • 6,876
3 votes
2 answers
2k 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 left / right. …
saginaw's user avatar
  • 6,876
22 votes
Accepted

How can I source a visual selection of vimscript?

So suppose you've got a line of vimscript in a file and want to source it quickly, you can copy it with Y, then source it on the command line with : :<C-r>" and enter. … In summary, you : copy your line of vimscript with Y switch to command mode with : hit <C-r> to enter the registers prompt type " to call the unnamed register hit backspace to delete the ^M character …
saginaw's user avatar
  • 6,876
8 votes
4 answers
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: Tho …
saginaw's user avatar
  • 6,876
6 votes
1 answer
458 views

Fixing lag due to vim-troll-stopper plugin

I don't know a lot about vimscript, but I noticed that the problem is not binary : vim is not quick then suddenly completely slow. The more I switch buffers, the more it is slow. … In the 14th chapter of Learn Vimscript the Hard Way, the author says that if you create an autocommand and define it twice, even though the autocommand is the same, it will be executed twice : When …
saginaw's user avatar
  • 6,876

15 30 50 per page