James Franco
James Franco

Reputation: 4706

First vim function - invalid function

I am trying to write my first vim function (toggling hidden chars). This is what I have so far

set nolist
set listchars=space:_,tab:▸\ ,eol:¬
nnoremap <leader>c :call showHiddenChars()<cr>   "<---Calling function here

let g:showhiddenChars_is_visible = 0

function! showHiddenChars()
    if g:showhiddenChars_is_visible
        set nolist
        let g:showhiddenChars_is_visible = 0
    else
        set list
        let g:showhiddenChars_is_visible = 1
    endif
endfunction

However when I run it I get the error invalid function showHiddenChars Any suggestions. This is my first vim function.

Upvotes: 1

Views: 70

Answers (1)

yolenoyer
yolenoyer

Reputation: 9445

User function names must begin with an uppercase letter (unless they are script functions with the s: prefix, or autoload functions using the foo#bar() syntax).

Change your function name from showHiddenChars to ShowHiddenChars and it should work as expected.

Upvotes: 3

Related Questions