使用vim.rc配置vim
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 (Linux, OS 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 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,mappings, functions, commands 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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 手把手教你在本地部署DeepSeek R1,搭建web-ui ,建议收藏!
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· 程序员常用高效实用工具推荐,办公效率提升利器!
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 【译】WinForms:分析一下(我用 Visual Basic 写的)