
Now, when you will open Vim, you will always have relative line numbers enabled.
#Macspice set editor to vim how to#
You are wondering how to make this change permanent, instead of typing ':set relativenumber' every time you open Vim. You tried relative line numbers, and you liked it. If the relative line numbers are already toggled, setting this option will disable relative line numbers. The same nifty trick applies for relativenumber: If the relative line numbers are turned off, you can turn them on using ':set relativenumber!' or with ':set rnu!' command for short. This will entirely disable the left column that shows the line numbers.

You will see relative line numbers to the above and below the line that your cursor is on.įor any reason, if you do not end up liking it, you can turn off relative line numbering using the ':set norelativenumber' command or with 'set nornu' command for short. Now type 'set relativenumber', or you can type 'set rnu' (for short) and hit the Enter key. There should be a colon character printed to the bottom-left corner of Vim. Showing relative line numbers in Vim from an active Vim session You do not have to do the mental math of subtracting the current line number from the line number, and you can go to a specific line in Vim easily. This is particularly useful because moving the cursor up and down x number of lines gets easier. When you have relative line numbers enabled, it means that the line you are currently on is line number 0 and the lines above and below the cursor are consecutively numbered 1, 2, 3. If you no longer wish to have them, simply delete the line 'set number' from your user's '.vimrc' file. Next time you open Vim, you will always see absolute line numbers in Vim.

It starts with 1 and ends with the number of the last line.Īnd, there are two ways to enable that. Show absolute line numbers in VimĪbsolute line numbers are what you find in almost all IDEs. To display line numbers in Vim, go into the command mode by pressing Esc key and use: :set number!Įasy, right? Let's see it in details and with examples.Īctually, you can show three kinds of line numbers in Vim:Ĭurious? Let's take a more in-depth look.

You might think, “I would switch to Vim immediately if Vim could show me line numbers”. You never know, and you can easily get locked out of root.Vim is a remarkable editor that most Linux/UNIX sysadmins have come to love and use every day.

To still have it working, you have to call it like: sudo EDITOR=vim visudoįinally, as hinted here, you can also add a line to your /etc/sudoers file near the top that reads: Defaults editor=/usr/bin/vimĪ word of warning: when modifying your sudoers configuration, keep a terminal open with a root shell in it (with sudo -i). So the change will not percolate to visudo. The sudo command will sanitize (read: delete) most environment variables before rising privileges - and it's a good thing it does. Log out, log in, check that the variable is set: % env | grep EDIĪnd now all the programs that call an editor (and are well written) will default to vim for your user.Īs noticed by (thanks!) in the comment, this will not work for visudo: since you are supposed to call it using sudo, when you do sudo visudo profile (or wherever you keep your startup environment if using a shell different from bash). If you want just to make your user use by default a different editor, add export EDITOR=vim
