58

I'm learning Emacs after over two years of using Notepad++ as my default editor. I'm still hung up on a few things, but I find myself kind of enjoying working with it.

My question is simple: in Notepad++, when I wanted to go to a specific line of my file, I used CTRL+G. Emacs, for some perplexing reason, requires me to do M-x goto-line [enter] $linenumber [enter].

I can't believe there isn't a shortcut for that. I must be googling wrong, surely?

5 Answers 5

74

M-g g or M-g M-g are the default bindings for goto-line.

And, the easiest way to find this is either M-x where-is RET goto-line RET which will list the bindings for the command goto-line, or you can type C-h b which lists all the bindings for the current buffer (and then you can peruse the bindings to see if goto-line is there, or to discover other useful commands & bindings.

1
  • 21
    Never feel stupid, while learning emacs. There are miles/years to go on this journey.
    – aartist
    Feb 6, 2013 at 0:51
8

Trey Jackson's answer is correct, but another useful thing to know in emacs is how to discover this sort of thing on your own. In your case, you know the name of the command -- goto-line. If you type 'C-h w' (Control+h and then w), Emacs will as you "Where is command: ". Type goto-line and hit enter, and it will tell you what keystrokes (if any) are bound to that command.

There are a bunch more similar features. 'C-h k' does the inverse -- asks you for a keystroke and then tells you the command it runs; 'C-h b' shows all current keybindings; 'C-h a' will search for a string, so you might type 'C-h a goto' to search for commands with "goto" in the name; 'C-h v' describes variables; 'C-h f' describes functions; etc.

2
  • and if you activate suggest-key-bindings, you will see a message like "You can run the command `goto-line' with M-g" automatically. To do that (setq suggest-key-bindings 't)
    – mmaruska
    Nov 26, 2014 at 16:44
  • You can also type C-h ? to see a list of the help commands, this will list all of the above. Jan 18, 2015 at 4:32
0

If you're an emacs newbie, this webpage gives a detailed explanation on how to find specific line numbers.

For me (on a mac), it was M-x goto-line (where I get the "M" meta key by pressing and immediately releasing the escape button).

0

try M-<, then C-u n C-n, goes to (n+1)th line.

0

I recommend https://github.com/davep/goto-line-faster.el

Which reduces M-gM-g <number> to simply M-g <number> without messing with any other uses of M-g as a prefix binding.

Being a command that I use fairly frequently, I've found this small optimisation highly agreeable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.