Tuesday, January 5, 2016

vim function problem w/numeric arguments

Hi,

I'm having this problem: I define a function as

function SetTabs(w)
set sw=a:w
set tabstop=a:w
( some other settings )
endfunction

When I try to use the function as:

call SetTabs(4)

I get an error on the first line:
Number required after =: sw=a:w

I tried coercing a:w into a number 'width' that I then try to use to
set sw=width
These are some of the ways I tried that did not work:
let width = str2nr(a:w)
let width = str2nr(a:w)*1
let width = str2nr(a:w)*1.0
also tried dividing instead of multiplying and adding or subtracting 0 or 0.0.

I tried to convert in two steps such as:
let width = str2nr(a:w)+1
let width -= 1
I tried changing 1 to 1.0, I tried first subtracting, then adding.

Neither attempt has worked.

Any pointer to what I'm doing wrong will be greatly appreciated.
(I'm using vim 4.3 on either bash or tcsh under Mac OS 10.7.5).

Thank you in advance,

Jomar

PS: My idea for this function is to quickly change sw and tabstop when I'm editing files from colleagues, some of which use sw=2, some sw=3, some sw=4.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: