Using keyboard to navigate the OS X terminal scrollback buffer - bash

I hate using the mouse. When working in the OS X terminal, sometimes I want to navigate to a line in the bash shell a few rows up, copy a word or two. For this I always end up using the mouse. Any solution for this? Perhaps the terminal supports a key combination that puts it in to navigation/select/copy mode, where I can use the usual C-F, C-B, C-N and C-P keys.

If you feel comfortable with Vi key combinations, you can use this command to switch to vi-mode and use key strokes:
$ set -o vi
Or use C-xC-e to open current line in your $EDITOR.

Related

ZSH shell and CLion/PyCharm integration, movement around terminal

I'm trying to use zsh in the CLion terminal window (changed my shell to /bin/zsh)
But when I try to move around using Ctrl + Left, Ctrl + Right, Ctrl + E... I get the literal characters D, C and Ctrl + E opens the "Recent files" UI
Is there any way around this? I'd like to use the movement keystrokes as I can with bash.
Tempoz,
Check out the offical Zsh Line Editor doc and the Z-Shell Line Editor guide for tons of detail.
To start, you can see your current mappings by typing bindkey at your prompt. There are two start modes: emacs [default], and vi. If you want to use vi mode, add this to your ~/.zshrc
bindkey -v
and source it (or restart your shell, or restart your IDE). Check out how the bindkey output has changed.
If you decide you want to change or augment your key mappings, use bind in your ~/.zshrc to reassign, or add to your key map.
# Example key binding change
# bindkey key-sequence editor-command
bindkey '^Z' vi-kill-line
You will also probably want to fix your $PATH - all the JetBrains products do it incorrectly. See this answer: https://stackoverflow.com/a/51006003/1089228

how do you enable command line editing with vim keys using mac terminal?

I'm reading this book and I really do not understand what this author is talking about. It appears that you can program your mac to go forward one character by either hitting l or ^F. I do not understand the difference between emac key stroke and vim keystroke. He also says run this command and 'place it in your $HOME/.bash_profile but I cannot figure out how to place the command in the bas_profile.
The Author is talking about make you terminal console behaves like vi, this means typing set -o vi in your terminal, the console will work similar vi. So you will be able to navigate using the motion keys of vi, use INSERT mode, x to delete, etc.
You can set that permanently if you include this command in your ~/.bash_profile file.
If you are not sure what it does, I don't recommend so.

What is the representation of the mac command key in the terminal?

Like control key is represented by a '^' in the terminal, what is the equivalent for the command key (mac)?
I am trying to remap my bash shortcuts using stty
For eg
stty eof ^D
But instead of control, I want to use the command key.
EDIT:
Okay so the issue I was trying to solve was that I wanted to interchange command and control keys because I work on osx and linux and the different key combinations cause me a lot of pain.
So I interchanged the modifier keys using osx preferences. But now all the bash shortcuts like Ctrl+C etc had become equivalent of using the key sequences 'cmd+c' - which is not acceptable.
Thankfully iTerm2, supports remapping of modifier keys as well, so for iterm2 I reversed them again which means iTerm2 recognizes command as command and control as control.
So problem solved for now.
The command-key shortcuts do not generate actual input for your terminal, so they are not represented in any way. Terminal allows you to bind certain key combinations to produce actual input (in Preferences > Settings > Keybaord), but you don't get the choice of a Command modifier for them.
Type this in your bash shell :
stty ctlecho
then hit Command
That will display what you need.
To go back to normal
stty -ctlecho
If it doesn't work, try a combo.
Example with Ctrl+C
$ stty ctlecho
$ ^C
$ stty -ctlecho
$

Emacs Through Putty

So I opened emacs through putty by executing the command "emacs -nw FILENAME", where emacs opens up with the desired file. I split the screen in emacs in order to open different file by executing the command "C-x 2" in emacs to split the window horizontally so that I can view two windows at a time.
My question is, now that I can view both files next to each other through the split screen, how do I edit the other file? (I can't use the mouse to click on the other file (other split window) to edit it because I can only use key commands when using emacs through putty)
You might want to try the Emacs tutorial which will explain those things. Also, I believe it is possible to get mouse clicks to work under putty: try M-x xterm-mouse-mode.
Use C-x o, other-window.
See http://www.gnu.org/software/emacs/manual/html_node/emacs/Other-Window.html.
Another tip to use the other window as a terminal is to run:
M-x term

Ctrl+p causing bash to temporarily hang when in vi insert mode over ssh

I recently switched to using vi mode (set :o vi) in my bash terminal. In the past, I've always used ctrl+p to look through previous commands, but for some reason after switching to vi mode bash hangs for about 20 seconds or so when I press ctrl+p in insert mode.
Note, this only happens over ssh. Locally it just inserts ^P.
Does anyone know why this is happening, or how I can hack it to remove the ctrl+p shortcut from OS X Terminal (I'm happy with using ESC, k, k,...)?
Thanks
In insert mode, ^P is bound to menu-complete-backward, so it’s running through all of bash-completion, which takes a while. If you want to cycle through the command history, you need to leave insert mode and use k and j. You could also bind ^P to previous-history.
In the OS X version of bash (which uses BSD libedit instead of GNU readline), ^P in insert mode doesn’t do anything.

Resources