Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set line numbers by default in vim?

Tags:

vim

macos

I know you can add line numbers in vim by using,

:set number

How do I set this to default behavior?

like image 638
Hutch Avatar asked Dec 19 '15 01:12

Hutch


People also ask

How do I set relative numbers in Vim?

" turn relative line numbers on :set relativenumber :set rnu " turn relative line numbers off :set norelativenumber :set nornu " toggle relative line numbers :set relativenumber! :set rnu! Like most commands in Vim, the j and k (or ↑ and ↓ ) keys can be prefixed with a number.

How do I select the number of lines in Vim?

If you want to select the entire line in a file, press V. Now when you press k or j to go up and down, vim will select the entire line above and below your cursor. Finally, you can select text in columns by pressing ctrl+v and moving up or down the block.


2 Answers

add this line to ~/.vimrc (if not exist, create a new file)

:set nu

and save the file

like image 120
peteyuan Avatar answered Oct 18 '22 21:10

peteyuan


the settings in $HOME/.vimrc file would be loaded automatically.

Except for set number to show linenumber, I have this to toggle normal line number and relative line number: (by pressing <leader>nu)

"---------------------------------------------------------
"toggle relativeline number
"---------------------------------------------------------
function! ToggleRelativeNumber()
    let &relativenumber = &relativenumber?0:1
    "let &number = &relativenumber? 0:1
endfunction
nnoremap <silent> <Leader>nu :call ToggleRelativeNumber()<cr>

https://github.com/sk1418/myConf/blob/master/common/.vimrc#L704

like image 28
Kent Avatar answered Oct 18 '22 19:10

Kent