简体   繁体   中英

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 . 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

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..."

Note: If you are on windows the .vimrc is called _vimrc

Your .vimrc file should be created inside your home directory ( ~ ). This is a script that is run everytime you start vim and should contain customizations to the editor such as the set number command. It allows you to customize and "program" 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.

Create a .vimrc (text) file with vim (or with any other text editor) in your home directory

$ 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.

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. 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.

As you use vim more and more, you will discover good optimizations to put in your .vimrc and the file will start to grow. You can google example vimrcs to see very cool settings that will help you code faster or better.

While in vim, use :h vimrc to see more information about it.

See here for a website about how to make a good vimrc.

.vimrc is Vim's Runtime Configuration. 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.

For set number , you would write in the .vimrc

set number

See also :help vimrc if you haven't already.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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