Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What you want are filetype plugins, rather than the <code>autocmd</code>s. Run <code>help: ftplugin</code> in vim for more info.</p> <p>From the vim help page:</p> <blockquote> <p>A filetype plugin is like a global plugin, except that it sets options and defines mappings for the current buffer only.</p> </blockquote> <p>In order to use filetype plugins, first put the line <code>filetype plugin on</code> in your vimrc. Then create the folder <code>ftplugin</code> in your vim folder (on unix it's <code>~/.vim/</code>, I'm not familiar with windows). Then create a script file for each file type you want to customize. These files must be named a specific way. From the vim help page:</p> <blockquote> <p>The generic names for the filetype plugins are:<br> ftplugin/filetype.vim<br> ftplugin/filetype_name.vim<br> ftplugin/filetype/name.vim</p> </blockquote> <p>So, for example, if I wanted to create a script for a python file, I would have three options: </p> <ol> <li>Create a file named python.vim in ftplugin</li> <li>Create a file named python_whatever.vim in ftplugin</li> <li>Create a file named whatever.vim in ftplugin/python</li> </ol> <p>This script will then be loaded anytime I open a file that vim recognizes as a python file.</p> <p>So, in order to accomplish what you want:</p> <ul> <li>Create a file named filetype.vim in the ftplugin directory for every filetype you want.</li> <li>In each of these files, add the line <code>colorscheme name_of_colorscheme</code></li> <li>Add <code>filetype plugin on</code> to your vimrc.</li> <li>In order to set a default colorscheme, just set it in your vimrc file. If I remember correctly, filetype plugins are loaded after your vimrc.</li> </ul> <p>Edit: The OP indicated that he had a good reason to avoid using the ftplugin directory. After a bit more diggin, I found <a href="http://vim.wikia.com/wiki/Change_the_color_scheme_to_show_where_you_are#Comments" rel="noreferrer">this script.</a> It can be placed in the global vimrc and seems intended to solve the same problem as the OP.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload