使用vim.rc配置vim

本文介绍了.vimrc文件的用途和位置。在Unix系统中,该文件通常位于用户主目录下;在Windows上,它位于HOME目录,名称为_vimrc。.vimrc主要用于存储个人选项设置、映射、函数和自定义命令,以个性化配置Vim。举例说明,如何通过.vimrc禁止使用制表符并设定自动缩进。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Your vimrc file is an incredibly powerful, incredibly useful thing. Anything you can do in command-line mode you can do in your vimrc file. This makes it possible to make settings (e.g. :set textwidth=80) in the command-line mode and then make them permanent in your vimrc file by just doing the exact same thing but in a file instead of in the running Vim session.

Where it is

Depending on what operating system you’re running on the vimrc file will be in a slightly different place. However, no matter where it actually is you can reference it from within Vim using the$MYVIMRC variable.

On Unix (LinuxOS X, whatever…)

On these operating systems, the vimrc file defaults to being in your home directory at ~/.vimrc. If it’s not there then just create it by editing it and saving it.

On Microsoft Windows

On all of the MS Windows variants you’ll also find this in your HOME Directory but most people don’t know where that is ;). I’m not going to try and tell you where it is, specifically and leave that up toWikipedia’s Home Directory Page. In general however it is one directory up from the directory that contains your “Documents” (e.g. “My Documents” in Windows XP). The major difference is that it’snamed slightly differently than it is in Unix: it’s named _vimrc.

What’s it for?

Everything. Ok, that’s not strictly true but at this stage in the game it’s more than sufficient to look at it that way. In practice you’ll find that plugins and many other types of file type specificconfiguration will make use of Vim’s extensive capabilities in its runtime structure, outside of thevimrc file but that sort of thing comes… later.

Generally you should think of your vimrc file as holding your own personal option settings,mappingsfunctionscommands and whatever else you need to customize Vim for your personal use.


Short example:

Make Vi-Vim never use tabs (converting spaces to tabs, bad!), makes the tab key == 4 spaces, and automatically indent code after curly brace blocks 

set smartindent
set tabstop=4
set shiftwidth=4
set expandtab

The help files take a bit of time to get used to but the more you read the better vim gets:

:help smartindent

Even better, you can embed these settings in your source for portability:

:help auto-setting

To see your current settings:

:set all
use the smartindent format

:set smartindent



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值