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.

VimScript (also called VimL) is a scripting language embedded into Vim. It can be used to create plugins and customize Vim to suit your needs.

Documentation

Tutorials

1573 questions
74
votes
6 answers

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 operation systems I am using.
muffel
  • 1,027
  • 1
  • 8
  • 7
51
votes
6 answers

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: #Do stuff without arguments I have tried…
iProgram
  • 1,589
  • 2
  • 15
  • 25
48
votes
1 answer

Use conditional operators AND or OR in an IF statement?

This is probably an incredibly simple question, but I did not find any answer so far (I must lack the right sources, and I don't know where to search in vim's help). I have a condition and I would like it to include 'AND', like if (condition1 .AND.…
Feffe
  • 1,761
  • 2
  • 14
  • 21
48
votes
1 answer

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. " Jump to first character or column noremap H…
Jezen Thomas
  • 595
  • 1
  • 4
  • 6
42
votes
5 answers

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 want. Is there a built-in way (similar to Perl’s…
bdesham
  • 2,983
  • 2
  • 18
  • 20
41
votes
3 answers

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.
iProgram
  • 1,589
  • 2
  • 15
  • 25
28
votes
6 answers

How can I really have some fun in Vim?

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 free time I write a book in it. I go to meetups…
statox
  • 49,782
  • 19
  • 148
  • 225
24
votes
1 answer

How do I check whether a given directory exists?

I need to determine whether a certain path exists and points to a directory, like the -d test in the shell. I know about the filereadable() function, which does basically this for files: filereadable({file}) *filereadable()* …
bdesham
  • 2,983
  • 2
  • 18
  • 20
23
votes
6 answers

Vimscript - Surround word under cursor with quotes

I'm writing a Vim plugin which will need to surround the word directly under your cursor with a quotes. I have tried using simple solutions which use commands like "b" and "e" executed in normal mode, in combination with other cursor position…
Ryan Fredez
  • 545
  • 1
  • 3
  • 10
22
votes
1 answer

if else endif oneliner in VIM

I have this oneliner in my vimrc but it does not work : if has("patch-7.4.710") | set listchars+=space:· else | set listchars+=trail:· | endif VIM says : E518: Unknown option: else Can you help me ?
SebMa
  • 2,968
  • 2
  • 12
  • 15
21
votes
1 answer

What is the meaining of '#' symbol in function name?

I would like to know what is the meaning of the # symbol in function names e.g.: execute pathogen#infect()
Alex
  • 347
  • 2
  • 11
18
votes
2 answers

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&vim some sort of special syntax, as in foo & bar? Or is it more like…
Runium
  • 1,237
  • 10
  • 20
16
votes
3 answers

How can I append text to the current line?

I'm currently trying to figure out vimscript and I stumbled upon the append() function. The documentation states that you can specify the line to which an expression should be appended to, so I tried: :call append(line('.'), Foo()) Foo() returns a…
Cookie Thumper
  • 181
  • 1
  • 1
  • 4
15
votes
3 answers

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 is only {file} as a place where to perform…
Al Berger
  • 393
  • 1
  • 11
14
votes
1 answer

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" : "another long string" into setlocal variable_name =…
Jcao02
  • 432
  • 3
  • 13
1
2 3
23 24