1

I would like to set custom keyboard shortcuts for the Open File and Open Directory commands listed in the File menu. The only problem is that I don't know the corresponding Lisp commands. I've tried open-file but it doesn't work. I've tried Googling for the answer, but it too failed.

  • Take a look at this page OR just read the manual for key binding – Chakravarthy Raghunandan Oct 4 '16 at 4:53
  • Yeah that tells me how to write keybindings in Lisp. That's not what I want, I know how to do that. What I want is to know which command opens files and directories. See I want to write a line in my ~/.emacs file that binds the open file command to Ctrl + O. I know in Lisp this would be (global-set-key (kbd "C-o") 'command) where command is what this question is asking for. It's the command that opens files! It is what I can't seem to find via Google. – BH2017 Oct 4 '16 at 4:58
  • 1
    You can type C-h k and then click on a menu item with the mouse to find out the name of a command assigned to a given menu item. Consider editing your question to better describe what it is that you are trying to accomplish. – lawlist Oct 4 '16 at 5:02
  • @lawlist Thanks. That helps. Would whoever downvoted me tell me why they downvoted me? I did my research looking for the command myself with Google, but that failed. – BH2017 Oct 4 '16 at 5:04
4

Emacs is designed to be self-documenting. A comment has already shown you how to use C-h k to get help for a keyboard shortcut (or a menu shortcut in this case). There are other quite a lot of other help commands available. You can get a list of them by typing C-h ?. It's a pretty long list, but I'll describe two that you'll especially want to remember (in addition to C-h k).

C-h f gives you help for a function, if you know that function's name. Obviously not directly helpful in your case, since you didn't yet know the name.

C-h a searches for commands by name, but you don't have to know the exact name. For example, you could have typed in "file" at the resulting prompt and it would give you a list of all commands with the word "file" in the name. Unfortunately for you that's a pretty long list. Clicking on anything in this list (or putting the cursor on it and hitting enter) takes you to the same help that C-h f gives you.

C-h i opens up the Info viewer. This is a great choice when you get lost, because Emacs comes with a bunch of different manuals which you can read here. You start out at an index listing all the available manuals. Go down to the Emacs manual and click or hit enter to view it. There's a huge amount of stuff in here, but it's pretty well organized. In your case I would scan down the table of contents until I saw an entry labeled "Files" under the heading "Major Structures of Emacs". That link takes us to chapter 18. The second paragraph explains that opening a file is usually called "visiting" the file, though it doesn't get into the historical reasons for that. There's another table of contents for the chapter there, and the second entry is labeled "Visiting", so that's the obvious next step. That gives us a nice list of different commands for visiting files (yes, there's more than one) as well as a bunch of prose that describes things in some detail. There's nothing much there about directories, but that's documented a little further along in section 18.8.

C-h m shows help information about all the various modes which are active in the current buffer. Usually that's a major mode which is determined by the file type, plus some number of minor modes that add features that are available for many types of files. Not of any direct use for you, since it won't show you the find-file command you were looking for, but you'll consult this information fairly frequently. You might take a look while you're reading the manuals to see the handy keyboard shortcuts for navigating up and down the tree structure of the manuals.

C-h b shows you a listing of every single keybinding currently configured in the current buffer. This is never going to be a small list, but it's handy because it's generated from the actual keymaps that are currently in place. This means that nothing is ever left out; while other sources are hand-written and might ommit details for clarity, this always includes everything.

  • Yup, +1. This is the answer: ask Emacs. – Drew Oct 4 '16 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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