Control key auto pressed when using vim over SSH through cygwin - windows

I'm using cygwin and sometimes, when I am typing in vim on a file over ssh and I switch to a different window and minimize cygwin and then come back to cygwin sometime later, I get a problem.
The problem is that for some reason, my keyboard doesn't work normally anymore, and it appears that for some reason, it thinks that my Control key on my keyboard is always being pressed. I know this because when I press just the 'V' key on my keyboard, vim says it's in Visual Block mode, and when I just press the 'R' key, it tries to Redo any changes.
The bad thing is that this also means that I can't actually exit from vim because I can press the : key, but then pressing wq doesn't actually enter in the normal wq symbols because it's interpreting it as ctrl w, ctrl q.
The only way I can fix it is by closing the entire window and restarting cygwin, but this means I lose any unsaved work, which is annoying.
Note: This doesn't happen when I use vim locally in cygwin (not over SSH)
What is causing this problem?

Related

Using vim along with screen

When I'm using vim alone, it's fine. I can suspend it by pressing Ctrl+z, work with bash, then return by typing fg.
When I'm trying to use vim along with gnu-screen, it's buggy.
First, pressing Ctrl+z does not show me all previous commands in console, it shows remains of vim screen instead(see pic).
Second, and worse, hotkeys, starting with Ctrl does not work in Vim. For example, Ctrl+PgUp to see previous tab.
Am I doing something wrong?

Clearing the terminal in vs code without using ctrl C

I want to know how do I clear up my terminal in Vs code without using Ctrl C
and restarting my how program?
There is an unbound command:
workbench.action.terminal.clear
that will do what you want without terminating any running tasks/processes. You can set it to a keybinding of your choice if you search for it in the Keyboard Shortcuts. It appears to work when you have editor focus and not terminal focus.

How can I use `M-x` in `emacs -nw` in zshell

It is my first time to use emacs -nw. But I have problem at the first when I type M-x. In the minibuffer, it shows "Mark set" instead of M-x
I don't know why it happens. How can I deal with it?
PS: My os is Macosx and I connect remote by using ssh and then I type emacs -nw but I cannot use M-x
Update:08/30/2015
When I see the options under M-x customize-group ns, it seems that Alt is actually used as Meta? Why it didn’t works.
14Hide Ns Alternate Modifier: [Value Menu] meta |
15 [ State ]: STANDARD. |
16 This variable describes the behavior of the alternate or option key. More |
37Hide Ns Right Alternate Modifier: [Value Menu] Use the value of ns-alternate-modifier |
38 [ State ]: STANDARD. |
39 This variable describes the behavior of the right alternate or option key. More |
When using Emacs in the terminal (switch -nw), you might not have a Meta key, depending on your platform etc. In particular, the Alt keyboard key might not function as the Meta key. You might find some information (e.g. here, or by googling) about how to get it working as Meta for your context (platform etc.), but you might not.
You can always use ESC (the Escape key) followed by a key to act the same as the Meta modifier applied to that key. For example, instead of M-x, you can use ESC x.
(You press and release ESC, and then do the same for x. ESC is not a modifier key -- you do not hold it pressed while hitting x.)
Your problem is that OSX is stealing the key. There are a few things which will make your life easier
Install emacs using homebrew. The version which comes with OSX is old
Use iterm2 instead of the default term.app - much better and feature rich
In iterm2, you can set a key override for either the left or right option as +ESC, which will make it all work.
This will all work on a local machine, but you may run into additional problems if your connecting to a remote machine and running emacs there. It is a similar problem, your key settings may no be getting stolen/dropped by the ssh session - all depends on your terminal, your ssh config and the remote system.
Note that with emacs, you often don't need to run remote. Emacs comes with a built-in system called Tramp, which is very powerful. Using tramp, you can open remote directories and edit the files as if they were local files. You run emacs locally and tramp uses ssh to open the remote files, read the contents into the local emacs buffer and then write the changes back tot he remote file. Helps to have ssh keys setup so you don't have to worry about passwords (but you will need an ssh-agent to make this work easily).
In general, when you find emads does not respond to a key press, especailly if you try C-h k and nothing happens when you hit the key bindings you can't get to work, it is almost certain that something in-between you and emacs is stealing the keys - this is often the window manager or OS, but it can also be due to terminal emulators etc. In over 20 years of using emacs, I've never had emacs 'do nothing' when you hit a key combination - if emacs recieves the key input, it will respond with something, even if that something is to tell you there is no key binding for the keys you pressed. If emacs does absolutely nothing, you know the message just isn't get through!
Open Terminal Preferences
Select Profiles
Keyboard
Check the box for "Use Option as Meta Key"

Why is so complicated to remap Esc to CAPS LOCK in Vim?

I saw the vim wiki tips and it says that in order to remap Esc to CAPS LOCK you have to edit the following windows code:
REGEDIT4
[HKEY_CURRENT_USER\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,01,00,3a,00,00,00,00,00
Is it possible to remap Esc to CAPS LOCK by only adding or modifying lines in the _vimrc?
I recommend that you use AutoHotkey for this.
You can do a per-application hotkey change:
SetTitleMatchMode,2
#IfWinActive,VIM
CAPSLOCK::ESC
return
#IfWinActive
CAPSLOCK::CTRL
return
This script, for example sets caps to escape in vim, and control everywhere else.
There's no vim key identifier for the capslock key, so you have to do it with a scan code.
It would be like trying to map the ctrl key or the shift key to something - those keys don't do anything by themselves, they are key modifiers, so they can't be trapped the same way.
The mapping has to be done at the OS level instead of vim, so the complication comes from the OS. For example, on my Ubuntu machine I have the following in ~/.Xmodmap:
! Esc on caps lock
remove Lock = Caps_Lock
keysym Caps_Lock = Escape
However, I don't think the REGEDIT script is so bad. It's kind of ugly, but it's only two lines!
Also you can try this: SharpKeys.
I swaped CapLock and Esc with it.
You could also use Ctrl-C to escape (Available at least in vim). Which is what I normally use. I commonly swap control and capslock, though, and have done so through registry settings in windows and keyboard conf in ubuntu.
Edit: as #mMontu kindly notes, Ctrl-C is more brutal than Esc: As stated in this appropriate question,
vim isn't going to bother checking if you just wrote part of an
abbreviation, and it isn't going to run the fancy auto commands your
plugins have set up for every time you leave insert mode
I hadn't noticed because my vimming is not so advanced yet.
Another alternative that worked well for me was to use the instructions found in
this website
Essentially: Install Microsoft's Keyboard Layout Creator, then edit its source code to allow remapping of CAPS LOCK and create your own custom layout.
Remap CAPSLOCK to ESC and CTRL on Windows
A very nice tool that I've already described in this answer gives you the possibility to remap CAPSLOCK to both
to ESC (when pressed alone) and
to CTRL (when pressed with other keys)
Just use this little piece of open source software by ililim.
You do not need Admin privileges for this and ESC and CTRL are still working as expected.
I use it to enjoy convenient CTRL + anything presses without hurting my pinky and to toggle modes in Vim that I use via ssh in MobaXterm. For installation just follow this description.

Page down and page up in Emacs on Windows using the Windows key

I am trying to learn Emacs and trying to find best keyboard layout for me. One thing is really annoying me. I have added following lines to .emacs
(global-set-key "\C-y" 'scroll-up)
(global-set-key "\M-y" 'scroll-down)
When I hold Control and press y a few times, it will page down on every press of y.
However, when I hold the Windows key (mapped as Meta) and press y a few times it will only page up on the first press of y and all subsequent presses of y I get the ‘y’ character inserted in the buffer.
Can the page up behave like page down? I want to hold Meta and keep pressing y to scroll multiple pages up.
I am using GNU Emacs 23.0.60.1 (i386-mingw-nt5.1.2600) of 2008-05-12 on LENNART-69DE564 (patched). It is Emacs with EmacsW32 patch. Is this problem with this Emacs? Problem with Meta key?
I tried original GNU Emacs (not patched) and it works OK with Alt. But my problem is not that I want to scroll without releasing any key. I release key y and press it multiple times but don't want to have to release Meta key. Same problem is described here:
http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/f30f4b75a8b75b10
Problem is not in that I have changed key mapping. It looks like it is a bug in EmacsW32 version. Here is another description of the problem:
Unreleased Meta/Win modifier
Use C-v and M-v.
Don't change C-y, M-y default bindings.
Could this be a side affect of using the Windows key as Meta? I'm thinking this because in a non-Emacs situation if you press and hold the Windows key and another key for a short cut (Win+E for Explorer, Win+R for Run dialog, etc.) the desired action only triggers once, not multiple times if you keep holding it down.
I'd try reassigning Meta to Alt and see if the problem persists. If it doesn't, then I'm not sure what other option you have, since likely it's the OS only sending the Windows key press once to the app in focus.
You should use the patched EmacsW32 version, if you want the Windows key as Meta.
From the site about the patches:
"Changes that makes it possible to use the window keyboard keys as META in Emacs. Without this patch key sequences like E will always do what they by default does in windows, ie in this case open up Windows Explorer. (This patched is not used by default, you have to turn it on.)"

Resources