Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set numeric variables in vim functions

Tags:

vim

I'm trying to write a function that calls setlocal to set some variables to the param(s) that I pass in. But I'm getting the error Number required after =: tabstop=...

function! MyFunction(param)
    setlocal tabstop=param
    setlocal tabstop=a:param
endfunction

Both lines will fail. Is there some sort of variable interpolation I'm missing?

like image 559
jjt Avatar asked Aug 29 '12 03:08

jjt


1 Answers

You need to define the option as an &option variable. For example:

fun! MyFun(param)
   let &l:tabstop = a:param
endfun

See :help let-&. The &l: is listed a little below that tag showing that it is for the equivalent of setlocal. Basically, when you want to set an option to an expression instead of a defined value then you need to use let &option= instead of set option=. Use let &l:option= instead of setlocal option=. There is also &g:option to set the option globally.

like image 174
Conner Avatar answered Oct 22 '22 06:10

Conner