Tmux equivalent of ctrl+k (copy current pos -> eol into buffer) - terminal

I have been using tmux for some time now and really like the internal copy buffer. I frequently find myself wanting to copy a command between panes but haven't really found an easy way of doing this.
What I would like is some equivalent of Ctrl+K that moves the data into the tmux buffer. Is there any way of doing this with one key binding? As it is, I could probably get it to work with two (first do Ctrl+K, then a keybinding that via xclip moves clipboard into tmux buffer), but I really would like to be able to do it quickly with just one hotkey.
EDIT:
I am running bash as shell in tmux, with evilvte as terminal in Kubuntu 12.04.

Related

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.

emacs DELETE/C-h confusion on OS X

Going through the tutorial on emacs, I got stuck on the deleting part, because by default DELETE key sends me to help. I've tried adding a few popular commands to the .emacs file such as (normal-erase-is-backspace-mode 1). So with that in my .emacs file, I hit C-h and get the screen that says This buffer is for notes you don't want to save..., then hit t and it just enters the letter into this "buffer". DELETE does what it's supposed to do now, though. When running emacs -q instead, I end up at the same "buffer" screen, except when I hit t it actually takes me to the tutorial, but the problem is of course that DELETE does not delete. Any solutions to this? I'm on a MacBook with OS X 10.9.4, using the Terminal.
The answer is in the Emacs manual, node DEL Does Not Delete. Just customize option normal-erase-is-backspace. Or use M-x normal-erase-is-backspace-mode to toggle the value.
Hmm, but I see now that you have added that you tried this. I do not understand what you mean by "notepad", so I do not understand that part.
Try this also, at a command prompt (assuming you are on GNU/Linux or similar):
stty erase ^H
And see various writeups on the web about stty erase. (IOW, google stty erase.)
When you say DELETE, I'm guessing (hoping) that you mean the key labeled Backspace and not the key labeled Delete. What does C-h k tell you when you use it and then hit each of these keys?
the key labeled Backspace
C-h, that is, press and hold Control then hit h
the key labeled Delete
(And just which keys are you using to get the behavior that does not work?)

Emacs open another shell in current window

One small thing that has been bugging me with emacs
When opening a shell within a buffer i do:
M-x shell
So far so good
But if I want to open another shell, I switch to another buffer and:
C-u M-x shell
but this always opens in another window - not the one I am currently in
this is annoying does anyone know how to fix it?
EDIT
I should have added that i have multiple buffers open in multiple split windows, e.g. my frame is split into 3 sections - what i want is the new shell to open in the same section that currently has focus, i.e. the one i am typing in and not an alternate one
I think what happens when I do C-u M-x shell is that the new shell buffer opens in the next window, i.e. the one you would shift to if you hit C-x o. I want it to open in the same window
Emacs runs interactive shells in dedicated buffers. It cannot run a shell in, say, TeX buffer.
M-x shell creates a new shell if there isn't one already, and C-u M-x shell asks you for the name of a new buffer. You can also rename the shell buffer to facilitate multiple shells, see the link above.
EDIT: the new shell buffer is displayed using pop-to-buffer-same-window (in Emacs24).
Your best venue is to add *Shell* to display-buffer-alist - but it is not necessary there.
In Emacs23 the display of the *Shell* buffer is controlled by special-display-function (since *Shell* has a match in special-display-buffer-names or special-display-regexps). Set special-display-function to display-buffer-same-window (or something similar) and you should be golden.
However, the ultimate solution is to upgrade Emacs to v24; since you are on a linux system, it should be straightforward.
You can use following codes to force the "*shell*" buffers display in the same window.
(add-to-list 'display-buffer-alist
'("^\\*shell\\*" . (display-buffer-same-window . nil)))

How to use vim in the terminal?

How does one setup and start using vim in the terminal on OS X?
I want to start writing my C code using vim in the terminal rather than a separate text editor. How does one get started on this?
The basics like: opening, creating, saving files via terminal using vim and writing code using vim. Also, does one compile directly using vim in the terminal?
Get started quickly
You simply type vim into the terminal to open it and start a new file.
You can pass a filename as an option and it will open that file, e.g. vim main.c. You can open multiple files by passing multiple file arguments.
Vim has different modes, unlike most editors you have probably used. You begin in NORMAL mode, which is where you will spend most of your time once you become familiar with vim.
To return to NORMAL mode after changing to a different mode, press Esc. It's a good idea to map your Caps Lock key to Esc, as it's closer and nobody really uses the Caps Lock key.
The first mode to try is INSERT mode, which is entered with a for append after cursor, or i for insert before cursor.
To enter VISUAL mode, where you can select text, use v. There are many other variants of this mode, which you will discover as you learn more about vim.
To save your file, ensure you're in NORMAL mode and then enter the command :w. When you press :, you will see your command appear in the bottom status bar. To save and exit, use :x. To quit without saving, use :q. If you had made a change you wanted to discard, use :q!.
Configure vim to your liking
You can edit your ~/.vimrc file to configure vim to your liking. It's best to look at a few first (here's mine) and then decide which options suits your style.
This is how mine looks:
To get the file explorer on the left, use NERDTree. For the status bar, use vim-airline. Finally, the color scheme is solarized.
Further learning
You can use man vim for some help inside the terminal. Alternatively, run vimtutor which is a good hands-on starting point.
It's a good idea to print out a Vim Cheatsheet and keep it in front of you while you're learning vim.
Run vim from the terminal. For the basics, you're advised to run the command vimtutor.
# On your terminal command line:
$ vim
If you have a specific file to edit, pass it as an argument.
$ vim yourfile.cpp
Likewise, launch the tutorial
$ vimtutor
You can definetely build your code from Vim, that's what the :make command does.
However, you need to go through the basics first : type vimtutor in your terminal and follow the instructions to the end.
After you have completed it a few times, open an existing (non-important) text file and try out all the things you learned from vimtutor: entering/leaving insert mode, undoing changes, quitting/saving, yanking/putting, moving and so on.
For a while you won't be productive at all with Vim and will probably be tempted to go back to your previous IDE/editor. Do that, but keep up with Vim a little bit every day. You'll probably be stopped by very weird and unexpected things but it will happen less and less.
In a few months you'll find yourself hitting o, v and i all the time in every textfield everywhere.
Have fun!
if you want to open all your .cpp files with one command, and have the window split in as many tiles as opened files, you can use:
vim -o $(find name ".cpp")
if you want to include a template in the place you are, you can use:
:r ~/myHeaderTemplate
will import the file "myHeaderTemplate in the place the cursor was before starting the command.
you can conversely select visually some code and save it to a file
select visually,
add w ~/myPartialfile.txt
when you select visualy, after type ":" in order to enter a command, you'll see "'<,'>" appear after the ":"
'<,'>w ~/myfile $
^ if you add "~/myfile" to the command, the selected part of the file will be saved to myfile.
if you're editing a file an want to copy it :
:saveas newFileWithNewName
If you want to learn by reading yourself:
Open MacOS terminal app.
Write this and press enter -> vimtutor
For quit write this and click -> :q

Bash in vi-mode: browsing shell history with cursor up/down, cursor position not at the end?

I'm very fond of vim and really would like to enhance my bash experience with vi-mode. However one thing I'm so accustomed to the emacs behavior in that, when browsing the shell history with cursor up/down, the cursor is positioned at the end of the line.
In vi-mode it's the other way around; the cursor is always positioned at the beginning of the line. It's really burned in the brain to expect the cursor at the end, having used bash in emacs mode for ... way too long.
Any chance to get the cursor position by default at the end of the line in bash vi-mode when browsing through the shell history?
You need to remap the up and down cursors:
bind -m vi-command '"\201": previous-history'
bind -m vi-command '"\202": next-history'
bind -m vi-command '"\203": end-of-line'
bind -m vi-command '"\e[A": "\201\203"'
bind -m vi-command '"\e[B": "\202\203"'
This will map previous-history, next-history and end-of-line to non-existant keys, then map up and down to a sequence of those characters. You can do the same for j/k if you want, but I'd recommend leaving them alone. That way you can do both.
This only remaps the keys when you are in command mode. On my machine, the cursor is already at the end of the line in insert mode. If this is not true for you, you can do the same using vi-insert instead of vi-command as the keymap.
I don't know of a way of doing this short of re-coding the history code inside of bash (or readline, really).
However, is it really so hard to enter Shift-A once you've found your line to start appending at the end?
If you're going to ditch emacs mode then, at some point, you're going to have to do it totally and accept the vi way of doing things. Join us, you know you want to :-)

Resources