how to go to a specific line number in emacs

One of the common forms of navigation with in a text editor is the ability to go to specific line in the buffer by using the line number. In emacs, you can browse or navigate the buffer in several different ways and the "go to line number" feature is just one of them.

The function in emacs that performs this is the goto-line. So in typical emacs fashion, you can do that by invoking it from the prompt

M-x goto-line

This is an interactive command so that means it will prompt you for a line number once you execute the command.

If you prefer to use to keyboard shortcut instead of the command then the default binding for the command is M-g M-g.

You can also prefix the shortcut with a numeral as in the following example to prevent it from prompting.

C-u 545 M-g M-g

Prior to moving to the new point, the command will set the mark without activating it, which means it makes it easier if you want activate the region or move back to the previous point.

If you use vi or vim as your text editor, then the command to go to a specific line in vim is just as easy.