Vim, the most loved and hated, controversial text editor ever. As a fellow normie, second best editor in my book, behind VSCode of course. Along with 5 other basic commands that I’ve only known in 5 years of using Vim, here’s tip on how to set and unset the number lines.
Prerequisites
- Vim
Solution
turn on / off number lines
Step 1. Open Vim.
Step 2. Show line numbers by running the following commands in order:
- Press the
ESC
button (Normal mode). - Type:
:set number
or:set nu
.
Step 3. To turn them off, run: :set nonumber
, or :set nu!
.
enable / disable relative number lines
Enable relative number lines: :set relativenumber
, or :set rnu
.
Disable relative number lines: :set norelativenumber
, or :set nornu
.
set line number width by N columns
:set numberwidth=5
Default value: 8. Min value: 1. Max value: 10.
set / unset line number permanently
Set line number permanently: echo "set number" >> ~/.vimrc
.
To unset line number permanently just update the line to set nonumber
. If you have them both, nonumber
setting will prevail.
open file at a specific line
vim +47 main.tf
list current Vim settings
:set all
Conclusion
Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.