vim is a powerful editor that can be used to create and edit text. However, sometimes you may need to turn on line numbers in order to better see the lines in your document. Here is how to do this:
- Open vim and type “line-number-mode” into the command line. This will enable line numbers in vim.
- To turn on line numbers for all files, type “setlocal lineno=1” at the top of your vimrc file. This will take effect for all files in your directory.
- To turn on line numbers for a specific file, type “setlocal lineno=x” where x is the file’s number (for example, “line-number-mode +x myfile”). This will turn on line numbers for that file only.
Vim is an extremely powerful editor, but only if you know how to use it. When you first start out, it’s like getting dumped into Minecraft survival mode — you’re gonna have to punch some trees.
In this case we can easily enable line numbers by simply typing the : character and using the following:
Well that was easy. You’ll start seeing line numbers right away.
The only problem is that the next time you open vim the line numbers will be gone and you’ll have to google how to do this again and then type the command every time. Luckily there’s a way to make settings stick.
Just open up your vimrc file with vim ~/.vimrc and add the command in there. Save and exit and the next time the line numbers will be there again.