Skip to main content
edited tags
Link
Martin Tournoij
  • 63.3k
  • 26
  • 199
  • 274
Source Link
Aaron Shen
  • 2.5k
  • 3
  • 24
  • 38

How to put custom functions at bottom?

I want to organize my vimrc better, so I want to put all the custom functions at bottom:

"different setting between different os
if MyDetectOS() ==? "windows"
    set rtp+=~/vimfiles/bundle/Vundle.vim/
    let path='~/vimfiles/bundle'
else 
    set rtp+=~/.vim/bundle/Vundle.vim
endif
if MyDetectOS() ==? "linux" 
    set clipboard=unnamedplus
else
    set clipboard=unnamed
endif



function! MyDetectOS()
    if has("win32") || has("win16") || has("win64")
        return "windows"
    elseif has("mac") || has("macunix")
        return "mac"
    elseif has("win32unix")
        return "cygwin"
    elseif has("unix")
        let l:uname = substitute(system("uname"), '\n', '', '')
        if l:uname ==? "linux"
            return "linux"
        else
            return "unix"
        endif
    endif
endfunction

If I put the MyDetectOS function at bottom like above. Then I'll get errors like below:

E117: Unknown function: MyDetectOS
E15: Invalid expression: MyDetectOS() ==? "linux"

Why it doesn't work?