(Assign tip id + convert to TipNew template + minor clean) |
(Move categories to tip template) |
||
Line 7: | Line 7: | ||
|author=Datagrok |
|author=Datagrok |
||
|version=7.0 |
|version=7.0 |
||
⚫ | |||
+ | |category2= |
||
}} |
}} |
||
Many tips that you find on this site and others will tell you to add some code to your .vimrc file. (Or on Windows, your _vimrc file.) {{help|vimrc-intro}} |
Many tips that you find on this site and others will tell you to add some code to your .vimrc file. (Or on Windows, your _vimrc file.) {{help|vimrc-intro}} |
||
Line 55: | Line 57: | ||
---- |
---- |
||
⚫ |
Revision as of 09:48, 25 April 2008
[[Vim_Tips_Wiki:New_tips{{{subpage}}}#Keep your vimrc file clean|created]] July 23, 2007 · complexity basic · author Datagrok · version 7.0
Many tips that you find on this site and others will tell you to add some code to your .vimrc file. (Or on Windows, your _vimrc file.) :help vimrc-intro
Once you do this a few times, it can get pretty big and confusing, especially if the bits of configuration you're adding are each specific to a single language. Worse, some settings might be incompatible with others.
Happily, Vim has a very nice built-in way to organize and manage language-specific options by breaking them out into files and directories. You can learn all about it by reading :help vimfiles, :help ftplugin-overrule, :help after-directory.
The quick way to get started is to move all the language-specific stuff from your .vimrc file into a file named .vim/ftplugin/language.vim.
This turns a .vimrc that looks like this:
autocmd FileType * set tabstop=2|set shiftwidth=2|set noexpandtab autocmd FileType python set tabstop=4|set shiftwidth=4|set expandtab au BufEnter *.py set ai sw=4 ts=4 sta et fo=croql
Into this:
" ~/.vimrc " Global settings for all files, unless I want to override them set tabstop=2 set shiftwidth=2 set noexpandtab " ~/.vim/ftplugin/python.vim " Python-specific settings setlocal tabstop=4 setlocal shiftwidth=4 setlocal expandtab setlocal autoindent setlocal smarttab setlocal formatoptions=croql
If there's a filetype plugin distributed with Vim that you want to completely disable, make your own (perhaps empty) settings file and adding this line:
let b:did_ftplugin = 1
If you like most of what Vim's filetype plugin is doing, but you want to override something specific, you can place your settings in .vim/after/ftplugin/language.vim. More info can be found in :help after-directory
If there's a new file extension that you want Vim to recognize, don't muck about with augroup in your .vimrc, put the settings in the right place. Read up in :help ftdetect.
There's a lot more you can do with your .vim directory. ~/.vim/compiler is a good place to keep configuration that gets applied on a per-compiler basis (for example, I might need to use any of javac, jikes, ant, or make to compile and parse the compiler output for a java source file.) I also like to keep a couple color schemes in ~/.vim/colors, and I keep notes in vimhelp format in ~/.vim/doc. Periodically running :helptags ~/.vim/doc lets me jump to a tag in those notes using :h. :help helptags :help vimfiles