Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a project that uses Ruby & Javascript and I am really comfortable with a particular colorscheme.

However I have another project in PHP + HTML, and I would like to use another colorscheme. What should I do?

I have my vim configuration in ~/.vimrc

Thanks

share|improve this question
    
Read Keep your vimrc file clean. Essentially, you just put the command colorscheme myrubytheme on the file ~/.vim/ftplugin/ruby.vim, the command colorscheme myphptheme on the file ~/.vim/ftplugin/php.vim, etc. (You must create the directories if they don't exist.) –  edwin Jan 31 at 23:10

1 Answer 1

You can make use of the ftplugin feature. First create the relevant directory:

mkdir -p ~/.vim/ftplugin

And second, add the line

filetype plugin on

to your .vimrc.


Now you can add language specific options to a file called <language-name>.vim located in the directory ~/.vim/ftplugin:

cat <<EOF > ~/.vim/ftplugin/ruby.vim
colorscheme myRubyTheme
set expandtab
set shiftwidth=2
set softtabstop=2
EOF

(This creates the file ~/.vim/ftplugin/ruby.vim and adds to it the contents presented.)

To determine the name of the language (as Vim understands it), open a file with the necessary file type (say MyLibrary.js) and type :set ft. For a JavaScript file Vim should return filetype=javascript, so the ftplugin for JavaScript should be named javascript.vim.

For a more thorough exposition read Keep your vimrc file clean on Vim's wiki page.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.