Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 445
user1574598 Avatar asked Dec 17 '25 18:12

user1574598


2 Answers

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.

like image 120
Zach Avatar answered Dec 19 '25 06:12

Zach


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

like image 23
Ry- Avatar answered Dec 19 '25 08:12

Ry-



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!