Jon49
Jon49

Reputation: 4606

vim: E14 Invalid Address, reassign variable inside if statement

I'm trying to make my tab spacing dependent on file type. But I get the error E14 Invalid Address on line 3.

function! Tabs()
  let t = 4
  if (&filetype ==? 'yaml') || (&filetype ==? 'yml')
    t = 2
  endif

  " size of a hard tabstop
  let &tabstop=t

  " size of an "indent"
  let &shiftwidth=t

  " a combination of spaces and tabs are used to simulate tab stops at a width
  " other than the (hard)tabstop
  let &softtabstop=t
endfunction
autocmd! BufReadPost,BufNewFile * call Tabs()

Not sure what I'm doing wrong.

Upvotes: 1

Views: 672

Answers (1)

romainl
romainl

Reputation: 196886

You must always use :let to assign a value to a variable:

let t = 2

Note: although it is not strictly required, it is somewhat customary to put spaces around the operator for :let:

let &foo = 1

And it is mandatory to avoid spaces for :set:

set foo=1

Upvotes: 3

Related Questions