How to enter ^A in screen command [duplicate] - linux

This question already has answers here:
Screen command disable the control key ctrl-a to use it in vim?
(2 answers)
Closed 5 years ago.
I wish to enter Ctrl-A to the terminal which will move the cursor to the very beginning of my current command line.
However, if I were using screen within the terminal, I was not aware of any way of entering Ctrl-A directly to the terminal instead of the default behavior.
Does anyone know how I could enter Ctrl-A directly to the terminal?

Gnu screen documents how to use its command key Ctrl-A, check the exception in "5.1 Default Key Bindings" section of the documentation:
https://www.gnu.org/software/screen/manual/screen.html#Default-Key-Bindings
5.1 Default Key Bindings
As mentioned previously, each keyboard command consists of a C-a followed by one other character. For your convenience, all commands that are bound to lower-case letters are also bound to their control character counterparts (with the exception of C-a a; see below).
C-a a
(meta)
Send the command character (C-a) to window.
So, press Ctrl-A then A to send Ctrl-A signal into program running inside the gnu screen.

Related

How to use tabs with vim in the Linux "screen" program?

When I use the Linux screen program, pressing the tab key will move between multiple screen windows. But when I want to press Tab to add blank space in a file using vim, it is useless, and will move to another screen. How can I use Tab with vim in screen?
EDIT: (taken from comments)
I have this keybinding in my .screenrc file:
escape ^Ii
And if I remove that, the Tab key works again.
The problem is your escape ^Ii entry in the .screenrc file.
In many/most terminal emulators, ^I (CtrlI) is the same key code as the Tab key (ASCII 0x11, aka "TAB" or "Horizontal Tab").
So the only solution is to choose a different escape key for use in screen.

Scrolling to see shell output while vim is open? [duplicate]

This question already has answers here:
How to temporarily exit Vim and go back
(10 answers)
Closed 8 years ago.
I have previously used the Putty terminal in Windows. It does not have mouse scrolling activated within a vim screen, but DOES allow me to scroll "above" the vim window to see previous shell commands/output.
Now I am using gnome terminal. It's behavior is the opposite. It allows mouse scrolling within the vim window, but does not allow me to scroll "above" to see previous shell output. Is there any way to allow me to scroll "up" to see shell output while I have vim open?
You can use <ctrl-z> to suspend vim and return to the shell, where you can scroll up and down all you like.
fg will resume vim, i.e. bring it to the (f)ore(g)round
While not "exactly" like what you describe you can type
:!
that will suspend your vim session and let you scroll back up through your prior output. You can also use :! to execute commands as follows...
:!ls
will run ls in your current directory.
You can use the :shell command to run the terminal from vim. Then you can scroll up and do all the stuff you want. Use <C-d> to return to vim.
you can use the :sh command to switch to the terminal, and type exit on terminal
to switch back to vim. you can always see all your shell output on the terminal.

Determining Priority of Programs' Handling Keyboard Input

When I run vim in a terminal screen buffer under the gnu screen terminal multiplexer, the effect of Cntrl-A is initiation a screen binding. But when I run vim in a terminal screen buffer without gnu screen, the effect of Cntrl-A is vim incrementing the number under the cursor. What is giving screen priority over vim in this case? Can I override or customize this priority scheme?
Ctrl-A is GNU Screen's default escape character, also called the command character; it precedes every screen command. You can change it to something else using a command-line switch (-e xy) when you run screen or within screen using ctrl-a : escape xy. In both cases x is the new escape character, for example ^B, and y is the key to send that escape character to the program in the window. Or you can put the "escape" command in your .screenrc initialization file. The default is -e ^Aa meaning you can send a ctrl-A to vi by typing ctrl-a followed by "a".
This is explained in the GNU Screen manual in the sections on Invoking Screen and Command Character.

Keep vim always in command line mode with a ":"

Is there a way to make vim stuck in command mode with a : already typed in?
In that way, for instance:
I would type /fooEnter and the cursor would go to the beginning of the next line containing foo.
Next, I would be still on command line mode with a : already typed in for the next command.
Yes, start it in Ex mode, by invoking it either as ex or as vi -e.
You can also enter Ex mode from the normal visual mode by typing Q (must be upper case).
You can return from Ex mode to normal visual mode by using the vi command.
EDIT : This doesn't actually do what the OP is looking for. He wants to keep the visual display while keeping the cursor on the bottom command line. That may not be possible.
No, but you can map ; to : to put yourself "closer" to command mode.
I'll link to the Vim wiki instead of reposting identical information here.
http://vim.wikia.com/wiki/Map_semicolon_to_colon
You can build your own REPL, like this:
:while 1 | execute input(':') | redraw | endwhile
This is just a conceptual demo; you probably want to add a condition to quit this special mode. Also, commands like :append would need special handling to work properly.
As a last try, I could just initialize vim with -servername=FOO and then code a little script that would read from stdin and send remote-send to FOO whenever it detects(by parsing) a whole command was typed on stdin.
Then I would just use Vim and this other script side by side on different xterms/gnu screens.
EDIT
OK, I will use this one. This way I can even make :a command to enter vim's Insert mode and switch back to command mode when entering a line with a single .. This way I would also have syntax highlight on the fly when inserting text (you know, vim has a very pretty visual display of the text, I'm just too used with ed's interface). When I have so time I'll write this script and link it here.

Vim "show my last command" command?

Is there a command which shows what was the last command in normal mode?
Suppose I accidently hit random key and got some unexpected result.
Sure I can undo it, but could I reveal what key was pressed and how it was interpreted?
Hit the colon (:) and then use the up arrow to start going back through previous commands. You can use the up/down arrows too to move around the list.
q: will show you command history in Vim.
q/ will show you history of searches.
And must importantly, :q will quit the mode.
The text from the last command is stored in the . register. You can see all registers by :display. Unfortunately it doesn't say what the started the normal command.
To see commands from : (command mode) you can use :hist or q: which is limited to the last 20 (by default).
Another ability is to save the undo buffer :wundo undo.bin -- but the undo buffer is binary.
But none of these actually answer your question. I'm curious if it can be done.
Entering colon : then ctrl+p shows your previous command, i.e., moving backward through your vim command history. ctrl+n moves forward.
This is very convenient if you're used to using the command line and prefer not to change your keyboard hand positioning to use arrow keys.
It is difficult to know it. You can play with the variables:
v:operator
v:count (and v:prevcount)
v:register
But you cannot fully get the last normal mode command issued.
However if you want to systematically record everything you type while in Vim, you can launch vim -W ~/.vim-last-scriptout (a Windows version: vim -W "%HOMEPATH%\Vim\.last-scriptout) You can alias it in your shell on a UNIX machine. Every single key, or control-key, will be recorded into that file. Note that if you happen to use gvim or vim -g (the GUI) you might encounter this bug.
If you want to replay this file you can use :source! (with the exclamation mark) or the -s option from the command line.
On Windows I have set gvimportable.exe -W gvim_directory\last_scriptout as my default editor in my Commander program (FreeCommander). This way I can always remember what I have typed to do something and repeat a sequence of commands on another file. Of course I have another shortcut for opening Vim and playing the scriptout.
Note that the file might be written only when Vim exits, so you have to lose your session to know what you've done.

Resources