简体   繁体   English

向VIM OSX终端添加永久号码行

[英]Adding a permanent number line to VIM OSX Terminal

I have come across a command for vim in osx terminal that allows you to view each line in a predetermined .c document, which is :set number . 我在osx终端中遇到了vim的命令,该命令使您可以查看预定的.c文档中的每一行,即:set number I want to set this parameter to be on default each time a document is created or opened. 我想在每次创建或打开文档时将此参数设置为默认值。

After doing a search I came across this: you can append :set number to vi ~/.vimrc 搜索后,我发现:您可以将:set number附加到vi ~/.vimrc

First, what is this file? 首先,这个文件是什么? How do you access it, and how do I append such a command to it? 您如何访问它,以及如何向其附加这样的命令?

I've tried searching the vim docs for .vimrc , but it doesn't make much sense as it talks about there being "4 places for initialisations, etc..." 我试过在vim文档中搜索.vimrc ,但是它没有意义,因为它谈到“有4个初始化位置,等等...”。

Note: If you are on windows the .vimrc is called _vimrc 注意:如果在Windows上, .vimrc称为_vimrc

Your .vimrc file should be created inside your home directory ( ~ ). 您的.vimrc文件应在主目录( ~ )中创建。 This is a script that is run everytime you start vim and should contain customizations to the editor such as the set number command. 这个脚本每次启动vim时都会运行,并且应包含对编辑器的自定义设置,例如set number命令。 It allows you to customize and "program" vim. 它允许您自定义和“编程” vim。 If you want :set number to be called every time you start vim, you should place it inside your vimrc to be run everytime vim starts. 如果您想在每次启动vim时调用:set number ,则应将其放在vimrc中,以便在每次vim启动时都可以运行。

Create a .vimrc (text) file with vim (or with any other text editor) in your home directory 在主目录中使用vim(或任何其他文本编辑器)创建一个.vimrc(文本)文件。

$ cd ~
$ vim .vimrc

Then add this line: 然后添加以下行:

set number

Notice there is no : . 注意没有: That is because this is not a command line command anymore and instead is executed as vimscript code. 这是因为这不再是命令行命令,而是作为vimscript代码执行。

The .vimrc file is useful for remapping keys to other commands, creating your own commands, turning on options like set number (there are many more) enabling plugins etc... For this reason, everyone has a different .vimrc file, which has been crafted as they use vim. .vimrc文件可用于重新映射其他命令的键,创建自己的命令,打开设置编号(还有更多)启用插件等选项。因此,每个人都有一个不同的.vimrc文件,该文件具有在使用vim时被精心制作。 I am often coding in vim, and decide it would be nice to have a command that you let me do something more efficiently, so I open up my .vimrc and add in something that would help me code faster. 我经常在vim中进行编码,并决定使用一个命令让您更有效地执行某件事会很好,因此,我打开.vimrc并添加可以帮助我更快地进行编码的内容。

As you use vim more and more, you will discover good optimizations to put in your .vimrc and the file will start to grow. 随着越来越多地使用vim,您将发现可以放入.vimrc的良好优化,并且文件将开始增长。 You can google example vimrcs to see very cool settings that will help you code faster or better. 您可以在google示例vimrcs中查看非常酷的设置,这些设置将帮助您更快或更佳地进行编码。

While in vim, use :h vimrc to see more information about it. 在vim中,使用:h vimrc查看有关它的更多信息。

See here for a website about how to make a good vimrc. 有关如何制作优质vimrc的网站,请参见此处

.vimrc is Vim's Runtime Configuration. .vimrc是Vim的运行时配置。 It's a Vim script that runs every time Vim starts up, so you can use it to run commands and configure the editor to your liking. 这是一个Vim脚本,每次Vim启动时都会运行,因此您可以使用它来运行命令并根据自己的喜好配置编辑器。

For set number , you would write in the .vimrc 对于set number ,您可以输入.vimrc

set number

See also :help vimrc if you haven't already. 如果还没有的话,请参见:help vimrc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM