KEEP K.I.S.S.

tk's blog

[翻译] Keep your vimrc file clean

tk posted @ Mar 18, 2013 07:57:26 PM in Vim with tags vim setting , 2032 阅读

 

英文原文: Keep your vimrc file clean.
作者: Datagrok
翻译: tisyang


本站和其他一些网站所写的关于 Vim 的技巧都会让你在 .vimrc 文件中添加某些代码。(在 Windows 平台,对应的是 _vimrc 文件。)参阅 :help vimrc-intro

当你添加多次之后,.vimrc 文件会变得相当大并且复杂,尤其是你添加的那些分别针对特定语言的配置。更糟糕的是,一些设置有可能互不兼容。

幸运的是,Vim 有一个良好的内建机制去组织管理针对特定语言的配置,将它们分置在不同的文件和目录。完整资料请参考 help vimfiles, :help ftplugin-overrule, :help after-directory

快捷方法就是将全部针对特定语言的配置从你的 .vimrc 文件中移到一个名为 .vim/ftplugin/language.vim 的文件中。(在 Windows 上对应的是 $HOME/vimfiles/ftplugin/language.vim

比如本来的 .vimrc 文件是这样:

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

移动之后变成这样,针对 python 的配置移动到了一个单独的文件中:

" File ~/.vimrc
" ($HOME/_vimrc on Windows)
" Global settings for all files (but may be overridden in ftplugin).
set tabstop=2
set shiftwidth=2
set noexpandtab

" File ~/.vim/ftplugin/python.vim
" ($HOME/vimfiles/ftplugin/python.vim on Windows)
" Python specific settings.
setlocal tabstop=4
setlocal shiftwidth=4
setlocal expandtab
setlocal autoindent
setlocal smarttab
setlocal formatoptions=croql

如果你想完全禁用某个随 Vim 发行的文件类型的插件时,首先建立你自己的文件类型配置文件(也许是空的),然后添加一行代码:

let b:did_ftplugin = 1

如果你觉得 Vim 自带的某个文件类型的插件大多数功能都不错,只是想改写某些特定的配置项时,你可以将你的配置放到 .vim/after/ftplugin/language.vim (在 Windows 上对应的是 $HOME/vimfiles/after/ftplugin/language.vim )详见 :help after-directory

如果你想让 Vim 识别一个新的扩展名文件,不要在你的 .vimrc 文件中使用 augroup 。将你的配置放到正确的位置。详见 :help ftdetect

关于 ~/.vim 目录(Windows 上的 $HOME/vimfiles )你可以做的更多。目录 ~/.vim/compiler 是一个存放应用到每个编译器基础之上的配置的好地方(比如说,我也许需要使用 javac, jikes, ant 或者 make 去编译然后解析编译器针对对一个 java 源文件的输出。) 【原文: ~/.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.) 】 我也喜欢将一些 color schemes 存放在 ~/.vim/colors, 用 Vim 帮助文件的格式记笔记存放在 ~/.vim/doc 。定期运行 :helptags ~/.vim/doc 命令可以让我在这些笔记里使用 :h 跳转到指定标签。 详见 :help helptags :help vimfiles

这个技巧建议将针对特定语言的配置移到一个适当的 ftplugin file 中。如果想让它生效,你需要启用文件类型检测功能。输入命令 :filetype 来检测文件类型检测是否已经启用。在某些 Linux 发行版中,文件类型检测被禁用,这时你需要添加如下的命令到你的 vimrc 文件中:

filetype plugin on
" Alternative: use the following to also enable language-dependent indenting.
filetype plugin indent on

  • 无匹配
maid services abu dh 说:
Sep 19, 2019 10:13:07 PM

Washing service operation owners are usually entrepreneurs which work beneath the names regarding franchise organizations. They may concentrate on cleaning properties or business buildings. In any case, they hoover, pick upwards trash, clear restrooms or perhaps bathrooms and also shampoo carpets.

maid agency dubai 说:
Jul 01, 2020 04:17:36 PM

It's obvious that several cleaning products in the marketplace are Molly Cleaning service friendly, although some will abandon your 'clean' career laden together with dirt and also streaks. Buy specialist grade washing products inside bulk from your supplier. Then you're able to dilute these with h2o, which can save you money and also time, and enable you to perform a specialist job. Just be sure that if you employ these goods, you use gloves and also always stick to the safety information on the brands.

wall painting servic 说:
Jul 01, 2020 04:17:53 PM

Very good painter pertaining to office features more tools than smaller sized paint firms. If a home requiring artwork work is often a three-story making or features walls and also a high indoor ceiling, the task might have to have the application of an elevator or no less than one staircase. Spray coating would be the fastest approach to achieve a new uniform stratum on outdoor walls. For that reason, make sure your selected paint company contains the right equipment and tools to complete the task properly.

elimperiotravel 说:
Mar 23, 2021 12:11:47 AM

Journey agents usually get all of the specials very first hand how the travel business releases prior to they reach everyone. Generally all of us get at wholesale prices rates upon major worldwide travel that is never released towards the public, just travel brokers. Saving clients $300+ dollars on the vacation deals within 14 days notice are actually all inside a travel brokers daily workday.

Monthly maid service 说:
Jun 14, 2021 09:44:29 PM

Intended for twice every thirty days, we is able to do a whole house, deep cleaning available for you. Hire your Professional Deeply cleaning products and services in Dubai in addition to Sharjah and allow you to be living houses more fresh and elegant. Get Low cost Deep clean-up services by Cit Help a dependable Cleaning corporation in Dubai

slot gacor 说:
Jan 19, 2023 05:53:39 AM

I’m excited to uncover this page. I need to to thank you for ones time for this particularly fantastic read!! I definitely really liked every part of it and i also have you saved to fav to look at new information in your site. slot gacor

Buy Magic Mushrooms 说:
Jan 29, 2023 06:50:12 PM

As a seller of legal steroids, you can buy Crazy Bulk products, explore stacks and finally get the body you’ve always wanted Buy Magic Mushrooms

promo gifts singapor 说:
Jan 30, 2023 06:51:05 AM

I have express a few of the articles on your website now, and I really like your style of blogging. I added it to my favorite’s blog site list and will be checking back soon… 엔포커 머니상

human growth hormone 说:
Mar 10, 2023 06:17:44 AM

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well.. human growth hormone for sale usa

SEO 说:
May 17, 2023 08:35:32 PM

On this subject internet page, you'll see my best information, be sure to look over this level of detail. 토토사이트

SEO 说:
Jun 10, 2023 10:25:41 PM I am very happy to discover your post as it will become on top in my collection of favorite blogs to visit. 주소모음
sophia 说:
Jun 19, 2023 01:44:31 AM

I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us. <a href="https://making2022.com/인천/">인천출장마사지</a>

sophia 说:
Jun 26, 2023 04:24:00 PM

I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post. agencia seo

SEO 说:
Jul 13, 2023 03:22:58 PM

We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends. 천안출장마사지

sophia 说:
Aug 20, 2023 09:33:34 PM

Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. BLACKHORN 209 POWDER

sophia 说:
Aug 29, 2023 02:18:12 PM

I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work... เว็บแทงบอลดีที่สุดUFABET

sophia 说:
Aug 31, 2023 09:14:57 PM

I am happy to find this post very useful for me, as it contains lot of information. I always prefer to read the quality content and this thing I found in you post. Thanks for sharing. AVALIADOR PREMIADO PAGA MESMO

Johny 说:
Sep 01, 2023 11:56:10 AM

I’ve been searching for some decent stuff on the subject and haven't had any luck up until this point, You just got a new biggest fan!.. last minute naar sal rei

sophia 说:
Sep 02, 2023 07:20:50 PM

I am happy to find this post very useful for me, as it contains lot of information. I always prefer to read the quality content and this thing I found in you post. Thanks for sharing. 먹튀검증

sophia 说:
Sep 03, 2023 01:57:58 AM

I am happy to find this post very useful for me, as it contains lot of information. I always prefer to read the quality content and this thing I found in you post. Thanks for sharing. ikaria lean belly juice

sophia 说:
Sep 03, 2023 05:41:19 PM

I am happy to find this post very useful for me, as it contains lot of information. I always prefer to read the quality content and this thing I found in you post. Thanks for sharing. Animale Male Enhancement

Dave 说:
Sep 07, 2023 12:46:34 AM

I am constantly surprised by the amount of information accessible on this subject. What you presented was well researched and well written to get your stand on this over to all your readers. Thanks a lot my dear. bubble games free

Dave 说:
Sep 16, 2023 09:39:28 PM

i love reading this article so beautiful!!great job! rugs on sale

seo akc 说:
Oct 07, 2023 05:56:26 AM

Initial You got a awesome blog .I determination be involved in plus uniform minutes. i view you got truly very functional matters , i determination be always checking your blog blesss. <a href="https://www.cbdflex.com/product/30ct-cbd-gummy-bears-300mg/">Buy CBD Gummy Bears</a>

Dave 说:
Oct 08, 2023 06:15:53 PM

This article was written by a real thinking writer. I agree many of the with the solid points made by the writer. I’ll be back. Jogo do Tigre

Dave 说:
Oct 09, 2023 01:00:28 PM

This is my first time visit to your blog and I am very interested in the articles that you serve. Provide enough knowledge for me. Thank you for sharing useful and don't forget, keep sharing useful info: LIFT DETOX CAPS

sophia 说:
Oct 11, 2023 06:54:41 PM

Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too. There tend to be not many people who can certainly write not so simple posts that artistically. Continue the nice writing Fortune Tiger

Dave 说:
Oct 11, 2023 09:07:20 PM

I think this is one of the most significant information for me. And i’m glad reading your article. But should remark on some general things, The web site style is perfect, the articles is really great : D. Good job, cheers CORTEXI

Johny 说:
Oct 22, 2023 02:19:39 PM

Really a great addition. I have read this marvelous post. Thanks for sharing information about it. I really like that. Thanks so lot for your convene. ufabetทางเข้าเล่น

Dave 说:
Oct 26, 2023 12:19:59 AM

I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. bitcoin recovery software

wallpaper singapore 说:
Nov 02, 2023 03:08:01 AM

This blog is really great. The information here will surely be of some help to me. Thanks!. Sajta de Pollo

Dav 说:
Nov 06, 2023 12:38:28 AM

I just want to let you know that I just check out your site and I find it very interesting and informative.. wallpaper singapore

Dave 说:
Nov 13, 2023 09:01:54 PM The pencils are fantastic, and the packaging is the icing on the cake. pencil packing work from home
Dave 说:
Nov 16, 2023 08:14:59 PM

Thanks for taking the time to discuss that, I feel strongly about this and so really like getting to know more on this kind of field. Do you mind updating your blog post with additional insight? It should be really useful for all of us. temazepam online kopen

tech 说:
Dec 11, 2023 11:35:54 PM

The next time I read a blog, I hope that it doesn't disappoint me as much as this one. I mean, I know it was my choice to read, but I thought you had something interesting to say. All I hear is a bunch of whining about something that you could fix if you weren't too busy looking for attention. UFABETแทงบอลเว็บแม่

Dave 说:
Dec 22, 2023 06:11:32 PM

Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. roket288

Dave 说:
Dec 24, 2023 02:42:29 PM

Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. fake ausweis kaufen

johny 说:
Dec 31, 2023 12:56:49 PM

I found your this post while searching for some related information on blog search...Its a good post..keep posting and update the information. hi88con

Dave 说:
Jan 07, 2024 02:58:45 PM

Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. comprar haxixe online

johny 说:
Feb 03, 2024 02:34:03 PM

Thanks for sharing the post.. parents are worlds best person in each lives of individual..they need or must succeed to sustain needs of the family. lingerie uae

johny 说:
Feb 08, 2024 02:19:35 PM

Nice to be visiting your blog again, it has been months for me. Well this article that i’ve been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share. Cream charger

Dave 说:
Feb 09, 2024 12:56:55 PM

Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post. comprar erva online espanha

johny 说:
Feb 10, 2024 06:49:00 PM

Tôi đánh giá cao nó rất nhiều! Tôi trông chờ thêm một bài viết nữa tuyệt vời như vậy. Chúc tác giả may mắn! Mọi điều tốt đẹp nhất! https://okvip.reviews/khuyen-mai/

Dave 说:
Feb 20, 2024 01:21:56 AM

Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post. pets gear


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter