Change the behaviour of cooked mode - terminal

On a terminal, the cooked (canonical) mode allows the user to input in text, and the text is sent to the program when the user hits enter. While in cooked mode, the arrow keys don't work, and they just appear as ^[[A and similar, but backspace does.
So is it possible to allow arrow keys in the terminal? Ideally, I would be able to even specify my own default 'cooker' to use.
And if it is not possible, then why are all terminals like this?
If it helps, I use suckless terminal, but I would prefer a solution that works on all terminals.

As a workaround, you can run your commands with rlwrap, which provides readline's line editing, including arrow key movement.

Related

How can I reset my terminal in a GNU screen session after accidentally printing binary garbage?

Sometimes I accidentally print binary garbage on the screen, for example I have printed a binary hash value or nonce instead of the hex hash value.
Sometimes the terminal is messed up in various ways after this, because the binary data contained escape sequences which reconfigure the terminal, rendering it almost useless.
When in a normal shell (locally or via ssh) it is usually sufficient to blindly type reset and press enter. (Often the typing is not visible due to the messed up terminal configuration.)
But when in a shell which is inside a GNU screen session this is sometimes not sufficient and the shell is still unresponsive.
How can I revive my terminal without destroying it and re-creating it?
The GNU screen terminals maintain part of the terminal state, too. To reset that in GNU screen do:
Press Ctrl-A.
Enter :reset and press enter.
Done. You may also need to enter reset in the terminal itself as well as usual.

How Do I Make Backspace Send ^H In Vim?

I have a problem that is my backspace works in the terminal but not in Vim. It sent '^?' instead of '^H' and I have been trying to figure it out. I have checked my .bashrc and there is stty erase '^?' to remove the '^?' but somehow it is not working.
I have this in my .vimrc:
set backspace=indent,eol,start
set backspace=2
fixdel
This is how I would normally fix it according to my knowledge but it doesn't work in this case. I'm using xterm on Arch Linux server if that helps, I know there is a bug for xterm but I don't think that's the case. It works in Unix command but not Vim, so just the Vim that isn't working.
Any help is greatly appreciated.
Edit:
Um to clarify, I just want my backspace to delete things. My backspace doesn't delete things right now and it is giving me ^? instead of deleting. The deleting is the same as any other system that is ^H but I want to make backspace to send ^H which is delete not ^?. So instead of having to type ^H to delete, I want to do it with backspace, on MobaXterm there is a function that makes backspace to send ^H. But how do I do that on SSH?
Thanks
There's two ways to go. To the left, you see the control-H character you crave. The path that way seems clear, just a little
echo xterm.vt100.backarrowKey: true >> ~/.Xresources; xrdb ~/.Xresources
followed by either restarting all of your xterms, or pressing control and your primary mouse button on each window to bring up the menu that lets you change it per window; the menu item itself is the second one in the third section, it's right under the 8-bit controls option. That way seems to be viable. Except, beware, there's a trap door under the control-H itself, as then backspace stops working properly everywhere else except bash itself. Of course, you have part of the way out of that maze already, with your stty fu. But I kind of recall running into all sorts of other issues with that path. One of them being that the Linux console also uses ^? instead of ^H, and that's not so easy to change.
Or, the other way is to get vim to be able to do what you're trying for, using ^?. Which I think is just
:map ^V^? x
Note that I mean control-V backspace, not caret V caret question. You would also want to add this to your ~/.vimrc if that does what you need. That having been said, you didn't say exactly where in vim isn't working quite right, so it's possible you're needing a different tweak instead.

Using Alt Key in FakeVim mode of Qt Creator?

It's really handy when you work with VIM text editor to use Alt key to execute normal mode commands in insert mode, for example when you are in insert mode you can press Alt + j to go one line down. But in FakeVim mode of Qt creator this couldn't be done. Any suggestion is welcome.
Pressing Esc each time you want to go to normal mode really sucks.
(not a fix to your problem, just discussing it in a properly formatted text)
I never hit <ESC> as well, and this is a deal breaker for me. Note that it's not a vim feature, though : this behavior occurs because using Alt with an other key in terminals generates an escape sequence. So there's nothing wrong with FakeVim regarding Alt implementation, the problem is related to the IDE being a QT window. You can't use Alt sequence in GTK's Gvim as well, for the same reason, last time I checked.
A possible easy fix on the QCreator part : provide an option to not pass Alt combinations, like the one existing for Ctrl. That is, if QT allows that. We could then at the very least define vim bindings using Alt key to simulate the terminal behavior.
In the list of others exotic combinations from terminals that quickly lead to form habits in vim, I also use C-j in place of <return>, and C-h instead of <backspace>. Those would really be nice to have too :)

ConqueTerm bash in Vim, key input delayed

I've just found out that I can use ConqueTerm to bring up a terminal window in Vim. But I have an annoying issue regarding this.
Lets say I go into insert mode to type commands, and then want to exit insert mode, it will not work unless I press Esc key and a different key. It seems to be a set timeout or delay of some sort. Symbols and characters show up in the bottom right corner of the terminal window.
I had the same problem when editing files in vim, but added "set timeoutlen=1000 ttimeoutlen=0" to my .vimrc which sorted this out for me. But I've been looking around and I cannot seem to find anything similar for ConqueTerm. My guess is that something is to be put/edited in "~/.vim/autoload/conque_term.vim"?!
Any help would be most apprechiated!
Thanks

Lightweight event wrapper for the terminal

I believe this is the realm of the ncurses library. I'm trying to avoid having to get down and dirty with it though.
I'm looking for a program that I can configure to run a command while performing terminal mouse reporting translation to keypresses.
This is for use with pagers like less.
For example the MouseTerm SIMBL plugin for Terminal.app does exactly this.
But iTerm2 does not. And I want it.
I think the answer may be as simple as directly remapping the codes.
It looks like there are escape codes to switch the terminal into and out of mouse-listening mode, and mouse click escape codes actually seem to include the character coordinates. I can look at them with Ctrl+V inside of Vim because I have told vim to turn on the mouse.
It looks like this:
Note ^[ denotes escape (you can type escape by typing ctrl+[)
left click: ^[[M !!
right click: ^[[M"!!
middle click: ^[[M!!!
scroll up: ^[[M`!!
scroll down: ^[[Ma!!
So that does match up with the mouse wheel button codes being 64 more than the mouse button ones according to documentation (I like this page).
Now that I'm armed with the knowledge of what codes I need to map to what I just need to find out how to get a layer that lets me filter the input.
This has apparently led me to an epiphany. I simply need a simple non-line-buffering program that listens for mouse escape codes and replaces them with key codes. Surely Perl Term::ReadKey will let me set raw mode and do this nearly trivial task.
This stuff is difficult. I've been making do by configuring Tmux to handle things.

Resources