Vim wasn't picking up my ftplugin configs and it was driving me nuts.A few days later, I answer my own question. Thanks for the advice on "filetype plugin on". Even before I started to use Vim (many years ago). The best way to configure is setting 'expandtab' to '1' and setting 'tabstop' to something you like. When using 'expandtab', it should always look the same in "dumb" viewers anyway, since you're inserting spaces instead of tabs. As a matter of style, you can do what you like, but if tabs and spaces are mixed in a single Python file, that 8-space alignment is what Python will use when it interprets your script. Python syntax explicitly interprets a tab as being 8-space aligned. The official style guide (PEP8) currently defines one indentation level as 4 spaces with the caveat "For really old code that you don't want to mess up, you can continue to use 8-space tabs." - Pydave ( talk) 23:19, Ma(UTC) With Python, this isn't just a matter of style, it's a matter of syntax. Python is a perfect example of how no tabstop setting is universal. I haven't used windows in a long time but my guess is that when you `type` a file in a cmd window, any tabs will show up as 8 characters wide. Ever since computers had a tab key it expanded to a width of 8 with one historical exception the classic macintosh. The tabstop=8 comes from the width of a hardware tab, e.g. This applies when not using 'expandtab', since when you use it you are inserting spaces anyway, as Fritzophrenic said. I don't know Java, but in Python, where indenting is important, the standards of the language mandate that hard tabs MUST be interpreted as equivalent to as many spaces would be needed to reach the next multiple of 8, not 4. For instance, in Java and Python, tabs are usually 4 spaces. However, the tabstop = 8 rule is nowhere near universal. " Alternative: use the following to also enable language-dependent indenting.Ī minor point: It's "recommended" to keep 'tabstop' at 8 when using 'expandtab', since that will ensure that the text or code looks the same way in dumb viewers and when printing. On some Linux distributions, file type detection is disabled, in which case you should add a command like the following to your vimrc: Enter the command :filetype to determine whether detection is enabled on your system. For that to work, you need to have file type detection enabled. This tip suggests moving language-specific settings to a suitable ftplugin file. This allows me to jump to a tag in these notes using :h. After making changes to these notes, running :helptags ~/.vim/doc updates the tags file. If you want the tags to look pretty set the filetype to help. Surround the tags with '*' and save the notes with the. ~/.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. There is a lot more you can do with your ~/.vim directory ( $HOME/vimfiles on Windows). vimrc, put the settings in the right place. If there is a new file extension that you want Vim to recognize, don't muck about with augroup in your. vim/after/ftplugin/ language.vim ( $HOME/vimfiles/after/ftplugin/ language.vim on Windows). 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. If there is a filetype plugin distributed with Vim that you want to completely disable, make your own (perhaps empty) settings file and adding this line: " ($HOME/vimfiles/ftplugin/python.vim on Windows) " Global settings for all files (but may be overridden in ftplugin). vimrc that looks like this:Īutocmd FileType * set tabstop=2|set shiftwidth=2|set noexpandtabĪutocmd FileType python set tabstop=4|set shiftwidth=4|set expandtabĪu BufEnter *.py set ai sw=4 ts=4 sta et fo=croql vim/ftplugin/ language.vim (or $HOME/vimfiles/ftplugin/ language.vim on Windows). The quick way to get started is to move all the language-specific stuff from your. You can learn all about it by reading :help vimfiles, :help ftplugin-overrule, :help after-directory. Happily, Vim has a very nice built-in way to organize and manage language-specific options by breaking them out into files and directories. Worse, some settings might be incompatible with others. Once you do this a few times, it can get pretty big and confusing, especially if the bits of configuration you are adding are each specific to a single language. (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. Tip 1510 Printable Monobook Previous Next
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |