How can I move a window to another session in tmux? - session

In tmux, how can I move a window from a session to another session?
ex. move window:4 in session [0] to session [4] .

From my testing on tmux 2.6, you'll need two things for the command to move an entire window over:
The name of the session you want to move the window from (for future reference, $session_name)
The index of the window you want to move (in the session it's currently in, of course -- we'll call this $window_index). This is actually optional -- if you omit this, then it defaults to the window in focus in the session you're pulling the window from.
From this point, you can just change to the session you want to move the window into, <tmux-escape>: into a command prompt, and type a command of this form:
move-window -s $session_name[:$window_index]
...where, as noted before, the $window_index is optional (as indicated by the square brackets, which aren't actually part of the syntax
). To use some concrete examples:
# Moves from currently-focused window from session named `$session_name`
move-window -s $session_name
# Moves from window with index `$window_index` from
# session named `$session_name` into the current session
move-window -s $session_name:$window_index
Et voilĂ ! Your window got moved. :)
EDIT: Added some more info on an alternative that omits $window-index.

There's now a built-in shortcut <tmux-escape>. to bring up the move-window command, so it's as easy as <tmux-escape>. <session_name>:<window_index> or to move a window within the same session, omit the session name: <tmux-escape>. <window_index>

Related

In FoxPro, data session window lost

Normally, I can use the command "SET" to view the Data Session window. The window doesn't show up anymore, even if I use the menus under Windows -> Data Session. I think I lost the window off the edge of the screen. How can I get it back?
Do this in the command window
SET && make the window active
MOVE WINDOW "View" TO 1,1 && move it to location 1,1

Bash Alias for Pressing Up in the Command Line

I personally hate having to go down to press the up-arrow-key when I want to repeat a command on the command line.
Is there a way to have map a bash alias to pressing the up-arrow-key? Or something that's also as convenient? I would like to just press 'n' then 'enter' instead of 'up-arrow-key' and then 'enter'
By default, bash uses the emacs keybindings. Ctrl-p and ctrl-n (for previous and next) do the same as up and down arrow.
To view and edit interactively, bash gives you the builtin bind command. help bind shows you usage, and, for example, bind -P shows you all the current bindings. Any remapping you do can be put into your .inputrc file for next time.
Also, bash provides what it calls HISTORY EXPANSION, similar to what was present in older shells. Just type !! and hit enter to execute the previous command. There's an entire section in the documentation with extra features.
Finally, I'll note that if you are repeating commands so often that hitting up-arrow enter is annoying, you might consider writing a script to do whatever you're doing.
You can issue the command set -o vi, or add it to your startup file. Then, you can hit the escape key and use the movement keys from vi to scroll. You can use k to scroll backwards, j to scroll forward, and h and `l' to move left and right.

How can I get quickfix to open results in the previously focused window?

I wrote the following command to search Vim's help files:
command! -n=1 -complete=help SearchHelp \
help | execute "grep! -i <args> $VIMRUNTIME/doc/ -r" | botright copen
Now, for example, when I have forgotten the key to increment the number under the cursor, I can do:
:SearchHelp increment
to search through the help files. (The answer turned out to be <Ctrl-A>.)
The problem is ... I have a few windows open, and I want quickfix to leave them alone. When I hit <Enter> in the quickfix list, I want it to open the result in that help window which I split open at the beginning of the command.
But it doesn't do this. It seems to prefer to always open the result in the bottom-most of all my editing windows, regardless of which window I was focused on, and with complete disinterest for the help window I opened. Obviously this moves away from whatever file I happened to be editing in that window (yes I have :set hidden), requiring an arbitrary number of <Ctrl-O> keys to get back to the file when I have finished browsing the help files.
So how can I get quickfix to open in the previously focused window (ideally that help window that was split open)?
(Incidentally, I sometimes use a patched version of Yegappan Lakshmanan's old grep.vim plugin, and somehow this does open :cope results in the window that had focus before I ran :Grep. I am not sure what's different in the two situations.)
The behavior (among others like :sbuffer) is controlled by the 'switchbuf' option. With a value of useopen, you can make it re-use a window if it already displays that help page. If you need more control than what is offered by that option, you do need to use a custom command / mapping.
So far what I have come up with is to replace that help command with:
99wincmd j | wincmd s
This splits whatever window happens to be at the bottom of the screen, so that when the quickfix clobbers the bottom one, I still have a window that keeps the file visible.
This solution is workable, but not quite as neat as my preferred result, which is to open results in the help window which was split just above the window I was focused on when I ran the command.

How to preserve buffer and window location (without manual save) between iTerm sessions?

How does one set iTerm to keep the buffer history (like Terminal.app's behavior) on OS X between quitting the app?
Also, it seems to reset Window Arrangement between sessions without manually saving it. Can I set this so that it remembers these window positions without having to save them each time I move the window around? This is kind of a hassle when using something like Flexiglass where I change things semi frequently.

Tell Emacs to open new buffer in specific window

If an Emacs frame is split in several windows and a new buffer is opened, is there a possibility to tell Emacs in which window to open the buffer.
Especially, if one window contains a dired buffer and I want to tell Emacs in which of the other opened windows a new file shall be displayed.
If the Emacs frame is for example split like this:
____________________
| | |
| | |
| A | B |
| | |
| | |
--------------------
| | |
| C | D |
| | |
--------------------
Where A,B,C and D are the windows. If A contains a dired buffer, can I tell Emacs to open a new file in a new buffer in window D?
Here's another answer --
You can do what you want using Icicles. In Icicle mode, C-x o, which is normally other-window, is icicle-other-window-or-frame. A prefix arg gives it several alternative behaviors, one of which (for Emacs 24 and later) is to choose a window that will be used by the next buffer-displaying operation (e.g., C-x C-f, C-x b).
That's what happens if you use a double plain prefix arg: C-u C-u C-x o. That invokes command icicle-choose-window-for-buffer-display, which you could of course also bind to any other key.
You choose the target window by name (using completion or cycling etc.).
All that command does is set variable icicle-next-window-for-display-buffer to the window that you choose. Icicles advises commands display-buffer, switch-to-buffer, and switch-to-buffer-other-window so that the next time they are called they use the window that is the value of icicle-next-window-for-display-buffer. (After that invocation they return to their normal behavior.)
This means too that if you have another method of choosing a window, which you prefer (e.g. cycling using one of the other methods mentioned here), then you could modify that method to set icicle-next-window-for-display-buffer to the chosen window, to get the same effect (in Icicle mode). IOW, it does matter how you choose the window; just set the variable value to it and the next buffer-displaying action will use it.
Others will probably give you answers that more directly respond to your question. My answer is to just move the focus to the window you want and then use C-x C-f or whatever to open the file or display the buffer you want in that selected window.
In order to do what you requested directly, you need anyway to use a key sequence that invokes the command you want. And if you want something general that works with different commands (e.g. find-file and switch-to-buffer) then you need to use a prefix key or repurpose the prefix arg. That is typically just as many key strokes as it is to switch to the window and then use the usual command.
Of course, with my suggestion you need a command to quickly switch to the window you want. There are various commands out there that let you cycle among windows or use completion to quickly pick a window by name or number.
So that's what I would suggest: switch to the window and then display whatever you want there, instead of trying to combine (a) designating the target window with (b) invoking the command that displays the buffer. IOW, just do it the old-school way: go to the window and then display there.
Of course, if you don't really want to end up in that newly displayed buffer, and you just want to keep the focus where you started, then with my suggestion you would need to cycle (e.g.) back to your starting window. It's not clear from your description whether this is your use case. If it is, then my solution is probably not that helpful.
But even in that case, it might still be useful to split things up: (a) a command to (only) designate the window to use for the following display-buffer command and (b) the display-buffer command. IOW, do essentially the same thing I suggested, but the first step would only designate the target window instead of switching to it, and the second step would use that designated window. (You would need to define (a) and (b), as a general mechanism.)
In this case too my suggestion differs probably from what others might suggest, in that it does not try to combine window choice with display command. They are coupled sequentially, but not combined in one command.
make the window that you would like to load the buffer in, activated and press:
C-x b
and you will be prompted by:
Switch to buffer (default *Buffer List*):
press enter(ret) without writing anything to choose the default. and then you will find buffer list loaded in that window. then choose the one you like to load and you will find it loaded in the same window.

Resources