If I am in split-screen viewing 2 different buffers on Emacs and the cursor is on the top buffer, what's a quick way to move the cursor to the bottom buffer?
Bonus question: if I know a command, is there an easy way to identify what key-combo it's bound to, if any?
To switch to other buffer use: C-x o.
Describe key: C-h k.
Here is a better solution when you open more than two windows(buffers) in one frame:
(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
(global-set-key (kbd "C-x <left>") 'windmove-left)
(global-set-key (kbd "C-x <right>") 'windmove-right)
Now, you can use C-x UP/DOWN/LEFT/RIGHT to go to the above/nether/left/right buffer when you have three or more in one frame, they are more precise than 'other-window and you don't need to install any package.
You even CAN make it to cycle the buffers in the direction(vertically/horizontally) with one of the above shortkeys with configuration in .emacs/init.el file, but I don't recommend it(besides I don't remember it anymore, you can google it if you want).
Of course, you can use other shortkeys other than the ones I use in my .emacs.
You may also be interested in WindMove, which enables "directional" window navigation with <S-up>, <S-right> etc.
With respect to the bonus question, if you know the command (other-window), and you invoke it with M-x other-window, Emacs will show a brief message in the minibuffer stating: "You can run the command `other-window' with C-x n".
There is also M-x where-is which prompts for a command and gives you the current bindings that result in that command (if any).
There is a tutorial that's shipped with Emacs. It actually has the answer to your question (see the section MULTIPLE WINDOWS about 80% into the tutorial). The tutorial can be accessed via C-h t, or M-x help-with-tutorial. There's also a link to the tutorial on the initial splash screen of Emacs. Right below the link to the tutorial is a link to the on-line Emacs Guided Tour. The tutorial walks you through basic editing/movement commands, the guided tour is more of an introduction to what Emacs has to offer.
If you want to navigate among only buffers that are currently displayed, then you really want to navigate among the windows they are displayed in. This gives you a way to do that, using window/frame names that are the same as the buffers:
See Better window navigation in Emacs?
Related
I've been working with VIM for decades, and I've become quite proficient in it. I was however sort-of... seduced by Emacs's org-mode, and in order to try it, I installed Emacs and Evil.
Evil satisfies most of my VIM-related muscle memory, so I proceeded with my testing of org-mode - and met my first issue: when I spawn Emacs in its own window (i.e. emacs plan.org) then the TAB key works, opening and closing my plan's sections just fine. However, TAB does nothing when I use Emacs in text mode (i.e inside my XTerms, via "emacs -nw plan.org"). And that's the state that I am mostly interested in, since I usually work from inside screen/tmux over SSH connections.
If it's a conflict with Evil-mode, I don't understand why - I am unaware of any TAB functionality in VIM's normal mode (which is what we're in when opening/closing org-mode sections).
Any Emacs-guru out there with a suggestion on why this happens?
Try
(setq evil-want-C-i-jump nil)
in your ~/.emacs before
(require 'evil)
Evil has, in evil-maps.el
(when evil-want-C-i-jump
(define-key evil-motion-state-map (kbd "C-i") 'evil-jump-forward))
That should give you org-mode Tab functionality back
I have almost no experience with terminals. However, I know that TAB is equivalent to C-i. Maybe that one would go through the terminal? If that works, you could add some key bindings for every TAB operation?
Try maybe C-h k TAB as well to see if TAB if sent on the wire.
(define-key evil-normal-state-map (kbd "M-i") 'evil-jump-forward)
(define-key evil-normal-state-map (kbd "M-o") 'evil-jump-backward)
I bind the function to other keys, so it's also work.
I want to be able to use a keyboard shortcut to edit my .emacs file instead of typing Ctrl-XCtrl-F.emacsEnter every time (here's an analogous question regarding Vim). There's probably an obvious way of doing this, but I can't find the Emacs Lisp command to open a file. I'd think it would be something beginning with "open" or "file" but typing M-x and those terms doesn't seem to bring up anything relevant. I tried
(global-set-key (kbd "<f6>") (find-file "~/.emacs"))
but that doesn't work.
According to the documentation
(global-set-key KEY COMMAND)
Give KEY a global binding as COMMAND. COMMAND is the command
definition to use; usually it is a symbol naming an
interactively-callable function.
So you have to use an interactively-callable function:
(global-set-key (kbd "<f6>") (lambda() (interactive)(find-file "~/.emacs")))
Personally I prefer to use emacs registers to store files which I use often.
I would store '~/.emacs' in a register:
(set-register ?e (cons 'file "~/.emacs"))
and open it with C-x r j e
Bookmarking is an excellent solution for this purpose that is packaged with emacs.
That way if it's ok for you to see the list of files that you want to open, you can easily browse them. There is also BookmarkPlus which offers variety of options.
M-x list-bookmarks
I switched from Vim to Emacs, and I am so crazy for Emacs now.
But there is a very, very useful trick in Vim and I can't use conveniently in Emacs, that's find next/previous word at point. Those are very handy with */# in Vim.
The simplest way is to move to the beginning of the word at point and then C-s and C-w, use C-s/C-r to find next/previous word.
Then I found another trick from Mastering Emacs, but still some minor bug.
Today I find a plugin - vimpulse which simulate vim in Emacs. And I can use */# there just like Vim!!
But seems the vimpulse will automatically enables Viper.
So, are there any other methods to implement this requirement? Or, Can I automatically disable Viper if I use vimpulse?
First, the answer
Well, as is often the case, we can do better in Emacs. The package I use for this is highlight-symbols
Specifically, I bind a series of its commands with variations of the F3 key:
;;;;;;;;;;;;;;;;;;;;;;
;; highlight-symbol ;;
;;;;;;;;;;;;;;;;;;;;;;
(require 'highlight-symbol)
(global-set-key [f3] 'highlight-symbol-next)
(global-set-key [(shift f3)] 'highlight-symbol-prev)
(global-set-key [(control f3)] 'highlight-symbol-at-point)
(global-set-key [(control meta f3)] 'highlight-symbol-query-replace)
Next/previous symbol is nice. But I find it most helpful when reading an
algorithm to highlight a few key variables.
On symbols vs words
The distinction between words and symbols is very nice for
programming. I'm not sure if other editors offer this distinction.
An alternative
Another related tool I find very useful for programming is iedit.
Here is how I load it:
(autoload 'iedit-mode "iedit")
(global-set-key [(control \;)] 'iedit-mode)
(define-key isearch-mode-map [(control \;)] 'iedit-mode)
To do what you want, go to a symbol and press C-;, now
tab and shift tab will move amongst matching symbols.
C-' (single-quote) will show you an adhoc occur view of the
buffer.
For a bonus refactoring tool, mark a region (maybe a class) where you want to
rename the symbol (variable), and press C-; again and only matches
within that region will be edited.
Try Evil: https://gitorious.org/evil/pages/Home
*/# works nice with it.
Is there a way to zoom in and out (dynamically change the font size, quite smoothly) on emacs?
Try C-x C-+ and C-x C--; that is, Control-x Control-Minus/Control-Plus.
After one combination (C-x C-+ or C-x C--), successives + or - increase or decrease the text scale without typing C-x C- again.
Addition by sawa
I looked up the function that was assigned to the keys mentioned, and found out that they are text-scale-increase and text-scale-decrease. I added the following to my configuration file so that I can do Ctrl+Scroll to zoom in/out. It is useful.
(global-set-key [C-mouse-4] 'text-scale-increase)
(global-set-key [C-mouse-5] 'text-scale-decrease)
The -very nice- answer of user173973 is binding the functions to non-generic mouse events. That is to say that for example on my windows system, the binding command is not valid.
To use it on windows (or probably anywhere) you can use these generic bindings :
(global-set-key [C-mouse-wheel-up-event] 'text-scale-increase)
(global-set-key [C-mouse-wheel-down-event] 'text-scale-decrease)
This config worked for me:
(global-set-key [C-wheel-up] 'text-scale-increase)
(global-set-key [C-wheel-down] 'text-scale-decrease)
In addition to sawa's accepted response, I prefer to use the keyboard exclusively. Here are some additions to my init.el file that meet that preference similarly to the short cuts found on Windows/MacOS desktops:
;; enable shortcuts (both keyboard and mouse) for zoom-in/zoom-out
(global-set-key [C-mouse-4] 'text-scale-increase)
(global-set-key [C-mouse-5] 'text-scale-decrease)
(global-set-key [?\C-\+] 'text-scale-increase)
(global-set-key [?\C-\-] 'text-scale-decrease)
All windows
You'll often want to change your font size because you're showing something to others. Then you likely want all windows to zoom in (including mode-line). For this, default-text-scale is great.
I bind it as such:
(key-seq-define-global "q-" 'default-text-scale-decrease)
(key-seq-define-global "q+" 'default-text-scale-increase)
(global-set-key (kbd "C-M-_") 'default-text-scale-decrease)
(global-set-key (kbd "C-M-+") 'default-text-scale-increase)
Quick single window, and back
For a really quick heavy (16x) zoom-in, you can use: C-u C-u C-x C-+
For going to single-window mode, say for a org presentation: C-x 1
Then you can undo the single-window and return to whatever layout you had before with winner-undo: C-c <left>
Whole desktop
Relatedly, for sharing over a video call, it might be easiest to just change (lower) your desktop resolution. On linux, I pop up arandr for this before starting a sharing session.
In GNU emacs, every time I hit Ctrl-x Ctrl-b to see all of my buffers, the window is split to show the buffer list, or if I have my window already split in 2 (for instance, I will have a shell running in the lower window), the buffer list appears in the other window.
My desired behavior is for the buffer list to appear in my active window so that I can select the buffer I want and continue to working in the same window, rather than having to Ctrl-x Ctrl-o to the other buffer, selecting the buffer (with enter) and editing that buffer in the other window... I've googled for it but it doesn't seem to be a common desire? I wonder if anyone has an elispy (or other) solution?
You might want to rebind C-x C-b to invoke buffer-menu rather than list-buffers:
(global-set-key "\C-x\C-b" 'buffer-menu)
Just customize the variable same-window-regexps. display-buffer will display any buffer whose name matches a regexp there in the currently-selected window.
(You will want to add "[*]Buffer List".)
not exactly a solution, but ido-mode provides a different and powerful way to interact with buffers. C-x b will then show a list of all the open buffers, and the one you select will open in the current window.
Strangely, there isn't an answer here about ibuffer.
I would recommend this as a standard change for the majority of Emacs users:
(global-set-key (kbd "C-x C-b") 'ibuffer)
ibuffer is a very advanced replacement for the default buffer listing, and not only features the exact behaviour requested, but provides a wealth of other functionality.
I listed a few ibuffer filtering and grouping basics in
Emacs: help me understand file/buffer management, but be sure to read the documentation for details.
Try to add
(ido-mode 1)
to your .emacs, and enjoy the result :)
If you like the original buffer list (as opposed to the 'buffer-menu solution proposed by others), you can use this:
(global-set-key (kbd "C-x C-b") 'my-list-buffers)
(defun my-list-buffers (&optional files-only)
"Display a list of names of existing buffers.
The list is displayed in a buffer named `*Buffer List*'.
Note that buffers with names starting with spaces are omitted.
Non-null optional arg FILES-ONLY means mention only file buffers.
For more information, see the function `buffer-menu'."
(interactive "P")
(switch-to-buffer (list-buffers-noselect files-only)))
Which is the same function as before, only in the current window.
I highly recommend bs.el from http://www.geekware.de/software/emacs/ Install it and:
(require 'bs)
(add-hook 'bs-mode-hook 'turn-on-font-lock)
(global-set-key "\C-x\C-b" 'bs-show)
It manages buffers and window configuration in the right way, so everything requires minimum number of keystrokes.
Not sure where I got this but:
;;; Faster buffer switching
(global-set-key [(C tab)] 'buffer-menu)
This makes Ctrl-Tab display all buffers in the current window. You can then navigate to a buffer and hit Enter to visit it.
Another not-what-you-asked-for solution: don't select the desired buffer with the mouse, rather finish typing its name (use tab-completion to reduce keystrokes and increase accuracy), then hit return. The buffer list will disappear, and the new file will be open in the previously active window.