Vim Tips Wiki
Register
Advertisement
Tip 336 Printable Monobook Previous Next

created October 3, 2002 · complexity basic · author Odyss · version 5.7


An easy way to to get to a line (whose number we know) faster is to combine some existing methods:

:123<CR>
 or
123G
 or
123gg

The solution is to map the <Enter> key in Normal Mode, to the G command:

:nnoremap <CR> G

We can type the line number and then press Enter to get there. Without the mapping, 123<Enter> will jump 123 lines down from the current position rather than to an absolute number. With the mapping, you can jump very quickly especially if you use the numeric keypad. On some systems, to get the numeric keypad's Enter key working, you may need to add the following mapping to make it do the same as the normal Enter key (or <CR> as in the mapping above):

:nmap <kEnter> <Enter>

To launch Vim and start at a certain line, you can pass the line number as follows:

vim file.txt +123

Comments[]

Advertisement