Open file in other window from Dired (Emacs) [duplicate] - emacs

I want to have two Emacs windows on the screen: one for Dired and one for code. But when I click on a file in the Dired buffer the file opens in the the same window, in place of the Dired buffer. Can I change this behaviour?

Why are you clicking on things with a mouse? I thought you're using Emacs?
Move point to the line you're interested in and press o to open it in another window or C-o to open the file but stay on Dired buffer.
If you must do it with the mouse, use middle-click to do the same thing.

S-Return works for me in spacemacs if anyone is interested.
dired-find-file-other-window is an interactive compiled Lisp function in
`dired.el'.
It is bound to <S-return>, g O, <normal-state> <S-return>, <normal-state> g O,
<menu-bar> <immediate> <find-file-other-window>.
(dired-find-file-other-window)
For more information check the manuals.
In Dired, visit this file or directory in another window.
[back]

Related

maintaining emacs buffer history

How do I configure Emacs to keep track of the files visited and then allow me to navigate the chain back and forth? I'm not talking about mini-buffer or the cursor positions within the buffer, but rather the files themselves. I hope I got the terminology right of buffer vs file vs window.
ie if I visit
foo.c -> dired home -> readme.txt -> buffer-list
then by pressing some "back key" 3 times, file foo.c should open in the same (current) buffer I was in. Another way to think of it, is how navigation history works in Firefox - I want to browse files within the buffer like the webpages within a Firefox tab.
Use command previous-buffer which is bound by default to C-x <C-left> and C-x <left> (or nakedly, as I prefer to write them, C-x C-left and C-x left).
Similarly, to move in the other direction, there is command next-buffer, bound by default to C-x C-right and C-x right.
If you use library misc-cmds.el then you can remap the keys bound to these vanilla commands to repeatable versions previous-buffer-repeat and next-buffer-repeat.
(global-set-key [remap previous-buffer] 'previous-buffer-repeat)
(global-set-key [remap next-buffer] 'next-buffer-repeat)
Then you can just hold down right or left after hitting C-x, to quickly cycle through the buffers.

How to switch back to a (file) buffer no longer visible, in Emacs

I opened a file in Emacs using Ctrl+x and Ctrl+f. The file replaces the buffer in which an old file was residing. Now I want to go back to the old file without giving the actual path to open it. Is there any command for this?
File opening does not replace buffers. It opens new buffers, so the old buffer is already there. Try the command M-x list-buffers (C-x C-b) to see the open buffers.
Also see this: http://www.gnu.org/software/emacs/manual/html_node/emacs/Select-Buffer.html
And this: http://www.emacswiki.org/emacs/SwitchingBuffers
I use session.el and minibuf-isearch.el. If you use them, you can search the history of file you opened with C-x C-f by C-x C-f C-r what-file-you-want RET RET even if you closed and restart Emacs. It's incredibly useful.

Using tabs in GNU Emacs 23

I have been looking into packages that would enable me to have tabs in my emacs editor. Would like to open multiple files in a single emacs window. Any help/link would be appreciated
Emacs has this functionality built in. They are called buffers C-x C-f opens a new file of a name you provide. C-x b lets you change between buffers. C-x C-b lists all open buffers. C-x k closes the current buffer.
If you want multiple buffers in one window then C-x 2 splits the windows horizontally. C-x 3 will split it vertically. C-x 1 will close all the windows that are not the current one. C-x o cycles between open panes. &c.
GNU the organization that manages the code base for GNU Emacs has a wonderful tutorial
Note: the the above segment C- means while holding the <CTRL> key
post script: the ido library makes working with emacs in generally much easier.
You can already open multiple files in buffers. However, if you want a visual guide, then this is what you might want: http://emacswiki.org/emacs/TabBarMode
Caveat emptor: You might have to configure it a bit.
or you can use elscreen
and use Gnu/Linux too, so i remap the Winkey to manage my tabs.
emacs doesn't contain "tabs" like an internet browser its best to understand the concept of buffers like the others have said but if you want to have a tab bar at the top anyway just to give a quick reminder of what buffers are open I suggest looking at the TabBarMode in the emacs wiki.
When using buffers i like to use m-x ibuffer since you can filter out which buffers your interested in. say you only want to see the buffers which are associated with files in a /home/flood/coding/epicgame/ directory, i simple go to ibuffer, type / f then type epicgame and a filter will be applied, then to remove the filter simply press / twice and remember that C-h m is your friend.
This technique has helped me alot, you can even OR filters together and merge them into groups. I love emacs XD

Emacs buffer shown after closing a buffer

How can I modify the way emacs picks which buffer to show after closing a buffer?
When I have multiple columns showing the same buffer, and then open another file in one of the buffers and then close the newly opened buffer, it doesn't switch back to the previous buffer, but to another buffer.
I'll try to explain with an example:
Start with a new emacs at *scratch*
C-x 2 (split into two columns)
C-x C-f 1 (find file 1)
C-x o (switch to other frame)
C-x b 1 (find file 1)
C-x C-f 2 (find file 2)
C-x k (kill buffer)
Now it switches to scratch but I would like it to show 1 in both windows again, is it possible to make emacs behave this way?
This may not be a direct answer to your question, but it might help.
Emacs manages its buffer list, including deciding which buffer gets displayed when you kill one (via kill-buffer). I haven't looked into how it's done, but the documentation is "out there". Lots of people have created custom buffer-stack management magic to change the way emacs does things, maybe some of them are based on bayesian analysis, or whatever. You can imagine the possibilities.
I've never looked into changing the way emacs manages its buffers. Instead I just bind other-window and switch-to-buffer to easy keystrokes (C-x o, C-x b) and I get really good at using them.
you could create a simple function for what you want: it should destroys all other windows, then split the window so that the current buffer is displayed in both. Luckily, emacs has functions that do exactly those things.
(defun cheeso-show-buffer-two-windows ()
"Close all other windows; then split, and show the current
buffer in both windows."
(interactive)
(delete-other-windows)
(split-window-vertically))
Bind that to a keystroke, and badda-bing, you're there. This is a vertical split - the windows are displayed in a vertical stack. If you want it horizontally split (the windows are side-by-side), then replace ... well, you know.
This also doesn't quite help directly, but Winner mode might help you get where you want to get.
Are you using tabbar-mode? I had the same problem and for me tabbar was the cause. Tabbar adds the function tabbar-buffer-kill-buffer-hook to kill-buffer-hook. You can remove it with (remove-hook 'kill-buffer-hook 'tabbar-buffer-kill-buffer-hook).
If you don't use tabbar try M-x describe-variable kill-buffer-hook. One of the functions in this list should be responsible for messing with your buffers.

What are the "Programmer shortcuts" in emacs?

I would like to know what are all the programmer-useful shortcuts that exists in emacs.
I come from a netbeans background and I am trying to make myself comfortable with emacs -text only environment. So I am looking at shortcuts for "refactoring" the code, "auto-completion", "go to definition" etc.
How can all these be achieved in emacs ? What are other programmer-useful shortcuts ?
I'll be using emacs basically for LAMP, javascript, C, C++.
ps - you can safely assume that I know how to open a file, save a file, navigate and whatever is in the tutorial in emacs.
For auto-completion, use etags with M-xtags-search or M-xetags-select-find-tag. I use macros often to do repetitive tasks. C-x(<string of useful tasks>C-x). Also, M-xalign-regexp to beautify the code and make it more readable.
You should find most of the most used features by Emacs users in this question's answers here at Stackoverflow.
Check this site
Some the important keybindings that are not there in the tutorial are:
Previous matching bracket: C-M-b (if it doesn't work, try ESC followed by C-b)
Next matching bracket: C-M-f (or ESC C-f)
Go to start of block: C-M-u
Go to end of block: C-M-d
Start of function: C-M-a
End of function: C-M-e
Outline mode: C-u 1 C-x $ (C-x $ to revert)
Newspaper mode: C-x 3 M-x follow-mode (especially useful with today's wide-screen monitors!)
Vertical Copy
Sometimes you will need to copy a vertical patch of data, e.g. one column in a table. First press C- where you want to start copying. Then go to the end of the column and press C-x r k. To paste the column press C-x r y. (If you don't want to delete original column, just press C-_ there once to restore it and then press C-x r y at target.)
To start, here is one :
Meta - / -> does code completion
M-x diff-buffer-with-file
M-x revert-buffer
When working with versioning (I use git), M-x diff-buffer-with-file is really useful. When you have a file open in a buffer in emacs, then you do a git checkout or some other action that touches that file, emacs will complain at you when you try to edit the buffer. M-x diff-buffer-with-file is helpful to see if you will break anything by keeping what's in the buffer. If something has changed and you want to grab the file from disc and put it in the buffer, do M-x revert-buffer.