Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use variables in my .vimrc?

Tags:

vim

I have a small problem with "tab size" and different project, some like 2 or 4 and the Linux kernel like 8 spaces per tab.

And this is not a big problem since I can just change a couple of settings in my .vimrc

set tabstop=4 set shiftwidth=4 set softtabstop=4 

But that is 3 lines I need to change...

It would be nice to have one line with a variable with the number 2,4 or 8.

A little bit like

let l:tabsize=4 set tabstop=l:tabsize set shiftwidth=l:tabsize set softtabstop=l:tabsize 

But this don't work...

Do you know how to fix this?

Thanks Johan


Update: This solves my little problem.

let tabsize = 4 execute "set tabstop=".tabsize execute "set shiftwidth=".tabsize execute "set softtabstop=".tabsize 
like image 555
Johan Avatar asked Feb 17 '10 21:02

Johan


People also ask

What is let G in vimrc?

l: local to a function. g: global. :help internal-variables. Follow this answer to receive notifications.

What is silent in vimrc?

<silent> tells vim to show no message when this key sequence is used. <leader> means the key sequence starts with the character assigned to variable mapleader -- a backslash, if no let mapleader = statement has executed yet at the point nmap executes.

What is let in Vim?

It can assign a value to. a variable, e.g. let vi = 'vim' an option, e.g. let &tw = 40. a register, e.g. let @a = $HOME . '/vimfiles'

How do I comment in Vimscript?

Comments in Vimscript start with " (a double quote), not // . If you want to execute a normal mode command, like % or dd , you can use normal! % or normal!


1 Answers

you can't use variables on the rhs in the .vimrc.

try :help feature-list for more info. for unix vs windows for example (not sure what your projects are):

if has("unix")     " do stuff for Unix elseif has("win32")     " do stuff for Windows endif 

might work, or another example is

execute "set path=".g:desktop_path 

If g:desktop_path contains spaces, you will have to escape those, either in the original setting of g:desktop_path or when setting 'path', e.g.,

execute "set path=".escape(g:desktop_path, ' ') 

See

:help let-option :help execute :help escape() 
like image 164
volvox Avatar answered Oct 08 '22 09:10

volvox