In an effort to automate addition of plugins in vim based on the filetype I decided to create a simple function in my .vimrc file. I am using Vundle as plugin manager and as required by Vundle, filetype should be switched off. I decided to save filetype in a variable and use it afterwards within the the plugin list inside Vundle. Here is the relevant .vimrc section:
set nocompatible " be iMproved, required
filetype plugin indent on
let var = &ft
echo var
function Plugin_set(var)
if (a:var == "python")
Plugin 'Python-mode-klen'
else
Plugin 'scrooloose/syntastic'
endif
endfunc
"Vundle Section Begin
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" All of your Plugins must be added after the following line
Plugin 'Tagbar'
Plugin 'VundleVim/Vundle.vim'
Plugin 'surround.vim'
Plugin 'better-snipmate-snippet'
Plugin 'bling/vim-airline'
Plugin 'Tabular'
Plugin 'rodjek/vim-puppet'
call Plugin_set(var)
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
I am getting no output at the line "echo var" where I would expect the filetype to appear. Then of course the if statement evaluates to false and else is used no matter what actual filetype I am opening.
But when I am trying to give the same commands in the vim shell like this:
:let var = &ft
:echo var
I am getting the actual filetype assigned to the var variable.
The if statement also evaluates to true if I just use let var = "python" instead of let var = &ft
It looks to me that I don't understand the rules of assignment of parameter values to variables.
But I just have no clue what is wrong here.
I very much appreciate your help.