Should I use single or double quotes in my .vimrc file?
Asked Answered
O

1

20

What’s the difference between single (') and double (") quotes in Vim? Does it make speed differences? Is it better to use one or another when running functions inside it? Does it matter at all?

I’m interested specifically in their use in the .vimrc file.

I’m asking because I find people use both in the same thing, and I’m wondering what are the differences. I tried to Google this, but wasn’t able to find anything.

Outsmart answered 17/11, 2012 at 22:51 Comment(4)
When writing functions the best you can do to improve performance are two things: use python for long computations and use as less lines (commands) as you can (lines are parsed each time executed and it is most of time the slowest part. Vim does not have VM). Some examples: replace :if conditions with ternary operator, cycles with map()/filter(), using let [a,b,c]=[…] in place of three lets.Rapid
Writing as if you are short on characters also has effect (removing indentation, using exclusively the shortest forms of commands, removing spaces whenever possible …), but for obvious reasons (it produces completely unsupportable code) don’t use this unless you are using VimL code generator (it is the third technique: things like 2html which have a bunch of :if conditions that are always true or false during a single run highly benefit from generating a function where unnecessary branches are removed).Rapid
Here is an example of the code that uses the third technique.Rapid
Related: https://mcmap.net/q/663797/-is-there-different-between-single-quote-and-double-quote-in-vim-command-modeLagging
E
24

Double quotes allow for interpolation whereas single quotes do not.

For example, using double quotes :echo "foo\nbar" will output foo and bar on separate lines whereas :echo 'foo\nbar' will not interpret \n as a line break and will output foo\nbar literally.

For more info on different types of quotes type :h 41.2 for the help file and read the part near the end of the section with the heading STRING VARIABLES AND CONSTANTS.

This said, don't confuse quotes for strings with the double quote at the beginning of a line comment. Single quotes never start line comments, only double quotes do.

Endoergic answered 18/11, 2012 at 0:33 Comment(1)
Little note: direct references to corresponding chapters in help are :h expr-quote and :h expr-'.Verticillaster

© 2022 - 2024 — McMap. All rights reserved.