Shift + Backspace won't work on Vim for Windows - windows

Before you mark this question as a double, hear me out because I've looked around and I can't find anything that'll fix my issue.
In Vim for Windows (accessed through Powershell running from CMD in a console), backspace works fine. Pressing Shift (or Ctrl) + Backspace prints a weird looking I to the screen and presses Ctrl+C.
Using :set to see what the keycode for the backspace is on my Vim yields this: "Î^Cx". This makes sense considering the behavior described above. The interesting part is that this keycode obviously is for the normal backspace key. My problem however, doesn't appear when pressing backspace normally, which doesn't make sense to me considering that the normal keycode is this weird collection of characters. It only appears when combining backspace with the shift key.
I don't understand why the backspace key doesn't send ^H or ^?. I've heard that those two options are popular. I assume my terminal is messing this up in some way, but I don't understand why it would be sending a different keycode for backspace when the shift key is pressed.
Thanks in advance.

I solved this issue like this:
imap Î^Cy <BS>
In my (Windows) terminals, Î^Cy is shift-backspace and Î^Cz is ctrl-backspace, and I have remapped them both. If Î^Cx is shift-backspace in your terminal, which it seems like it is, try adding this to your vimrc file:
imap Î^Cx <BS>

I don't know why this happened in your configuration, but you should be able to use inoremap to make it do what you want.
Interactively, you can test my idea by typing this
:inoremap <hit control-V><hit shift-backspace> <hit control-v><hit backspace>
What this will do is create a non-recursive map in insert mode for the escape sequence generated by <shift-backspace> to the escape sequence generated by <backspace>.
In my case, the result looked like
:inoremap ^? ^?
because my <shift-backspace> produces the same sequence as <backspace>, but in your case it should produce something more useful for you.
Once you've figured this out, move it to your .vimrc without the colon, and that will hopefully fix your issue in a lasting way.

Are you having the same issue as me I wonder where this happens in Windows Powershell but doesn't happen in gvim or when you run vim under cmd. If so I think the other responders are correct that vim does nothing different with shift+BS than BS but the Powershell command running it is. It's not an answer, I don't know a way around it other than use gvim. But if you're trying to dig further I'd suggest it's Windows Powershell that's the issue (unless I'm wrong of course) rather than vim.

Related

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

How to hijack the Caps Lock key for Cut, Copy, Paste keyboard operations

Here is what I am trying to accomplish:
To Copy, press and release Caps Lock ONCE
To Paste, press and release Caps Lock TWICE, quickly
To Cut, press Ctrl+Caps Lock
The reason I want to do this is often times i find my self looking down to press the correct X/C/V key, since they're all next to each other (atleast on a QWERTY keyboard).
How can I do this on a standard keyboard (using Windows), so that it applies to the entire system and is transparent to all applications, including to Windows Explorer? If not possible with a standard keyboard, can any of the "programmable numeric keypads" do this you think?
In the above, by "transparent" I mean "the application should never know that this keystroke was translated. It only gets the regular Ctrl+X/C/V code, so it behaves without any problems".
Ps. Not sure of all the tags that are appropriate for this question, so feel free to add more tags.
SOLVED. UPDATE:
Thank you to #Jonno_FTW for introducing me to AutoHotKey.
I managed all three requirements by adding the following AHK script in the default AutoHotKey.ahk file in My Documents folder:
Ctrl & CapsLock::
Send ^x
Return
CapsLock::
If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 1000)
Send ^v
Else
Send ^c
Return
That was easy!
NOT COMPLETELY SOLVED. UPDATE:
The above works in Notepad, but NOT in Explorer (copying files for example) or MS Office (even text copying does not work). So, I need to dig around a bit more into AutoHotKey or other solutions. Will post a solution here when I find one.
In the meantime, if someone can make AutoHotKey work for everything I need, please reply!
ALL SOLVED. UPDATE:
All I had to do was to change the capital "C"/X/Z to lowercase "c"/x/z. So Send ^C became Send ^c. It now works in ALL programs inlcuding Windows Explorer! Fixed code above to reflect this change.
I believe the program you are looking for is AutoHotkey.
You need a Global Keyboard Hook.
Very nice! Been looking for something like this for a while.
My script is slightly different, making use of shift or control combinations for cut/copy, then CapsLock on its own is always paste.
Ctrl & CapsLock::
Send ^x
Return
Shift & CapsLock::
Send ^c
Return
CapsLock::
Send ^v
Return
If you wanted to retain the option of retaining the Caps Lock function, I presume you could always remap e.g. Alt-CapsLock for this. I couldn't get it to toggle correctly when I tried it though.

OS X Terminal: Meta key + alt functionality at the same time

Is there a way to use an alt / option key as a meta key but still be able to use it to make some characters which need it?
For example, in my local keyboard layout:
# is alt + 2
\ is alt + shift + 7
| is alt + 7
etc.
So, if I set alt as a meta key, I can't make those characters anymore. On the other hand, using "press esc, release esc, press a key" to make meta key sequences makes my hands hurt.
Any Emacs users with international keyboards who have solved this, please give any tips you might have! :)
Edit:
It appears that I can set alt as a meta key and then add these kind of settings in inputrc: "\e2": "#" This works in the bash shell but it still won't work with Emacs though, so no good.
I use a Swedish keyboard in Mac OS X and use the following setup for Emacs.app:
First I have KeyRemap4MacBook installed and I have it setup to change the left Option key to Command.
I then have the following in my .emacs:
(setq mac-option-modifier 'none)
(setq mac-command-modifier 'meta)
This makes Emacs treat command as Meta and ignore Option. Since the left Alt/Option key is remapped to command, this makes it work lite meta while the right Alt/Option key still works for entering special characters like # [] and {}.
App specific Mac shortcuts like Cmd+C and Cmd+V no longer work, but global shortcuts like Cmd+space for Spotlight and Cmd+Tab for app switching do.
Update:
If you use iTerm2 as a Terminal, that has support for mapping only the left Alt/Option key to meta, which means you can still use the right AltGr/Option key for entering special characters. This also means you can use meta as normal inside Emacs running in the iTerm2 terminal.
I have a Swedish keyboard on my Mac and I'm using Aquamacs. Adding the two lines (attribution goes to Joakim Hårsman)
(setq mac-option-modifier 'none)
(setq mac-command-modifier 'meta)
in .emacs (and restarting Aquamacs) did the trick for me.
with iTerm2 you can map the left option key to ESC/meta and leave the mapping of the right option key to "normal". This way you can use the right option key to type accents etc.
Think about using a full featured Emacs for Mac OS X. I use Carbon Emacs but I believe others (say Aqua Emacs or X11 Emacs) would do the trick.
If you insist on using Emacs in a terminal you can use the C-x 8 prefix as a compose key. Try C-x 8 C-h to get a list of possibilities.
See http://www.emacswiki.org/emacs/EmacsForMacOS
Two work-arounds I use:
I use xterm running under X11.app. X11.app uses the command key as meta.
When running emacs in Terminal.app, I just use the rfc1345 input-method, which allows me to enter all kinds of crazy non-ascii characters without needing an option key.
Check out cmd-key-happy. This little app has worked wonders for me. It allows you to use command as meta, with exceptions that you can configure.
Author's info follows:
This program allows you to swap the command and alt (or option) keys
in any application, but in particular Terminal.app.
http://github.com/aim-stuff/cmd-key-happy
This is an old post but adding an alternatives for Robots to find.
I borrowed a couple of files from Aquamacs(emulate-mac-keyboard-mode.el, aquamacs-tools.el) that fixes the problem (I have a Italian-Pro keyboard) :
(defun aq-binding (any)
nil)
(load "~/.emacs.d/emulate-mac-keyboard-mode.el") ;; 'noerror
this provides:
few minor modes (emulate-mac-italian-keyboard-mode,
emulate-mac-french-keyboard-mode,
mulate-mac-swiss-german-keyboard-mode, etc)
a menu to play with all the options provided by Aquamacs
Tested with Emacs-23.3-universal-10.6.6 and seems to work ok for me.
Thanks Aquamacs for this, what about pushing this upstream if not already done.
It's worth thinking about the assumption behind the question. I mean to say that the real problem is making the characters that currently seem to need the option key. This problem can be solved without achieving simultaneous 'meta key + alt functionality'.
Let me explain: I have a similar problem. On my UK keyboard, shift-3 is mapped to the pound sign, £, which means that I generally need to hit option-3 to get the very useful # - a real problem in Terminal, where I use option as meta. However, I find most of the above solutions to be a little over-the-top. I don't want to change to another version of Emacs (eg. Aquamacs), to switch to a different Terminal application (eg. iTerm or xterm), or to install a key-remapping application (eg. KeyRemap4MacBook) all for the sake of one symbol! Perhaps that would suit some people, but I thought it was worth pointing out that if the problem is just one character, it can be solved with a nine-character text file.
With regard to my personal version of this problem, I find the simplest solution is to create a file called .inputrc in my home directory, consisting of the following single line:
"§": "#"
This re-maps the (to me, quite useless) § that can be found to the left of the 1 on the current Mac keyboard to the (almost indispensable) #. That suits me even better than the default setup, because I can now get # with a single keypress. If there were any other characters I needed to remap, it would just be a matter of adding an extra line for each one.
Anyway, that deals with how to get the missing character in the shell, but if you also want it in Emacs (which you didn't say but is probably the case) then you can add something like this to your .emacs file (where 35 is the ASCII for the character I happen to want, ie. #):
(global-set-key (kbd "§") 'insert-hash)
(defun insert-hash ()
(interactive)
(insert 35))
It might not be such a neat solution if there were dozens of characters that I routinely wanted to access via the option key, but there aren't.
I hope this helps somebody. As a mere weekend hacker, I ordinarily wouldn't dare post an answer to a question on Stack Overflow...
Special keyboard layout with option deadkey
My solution to this problem is a special keyboard layout I have written, U.S. custom. It provides an option deadkey that produces option combos without having to use the physical ⌥ Option modifier key. For instance, the character ⟨ç⟩ is produced as follows on a normal U.S. keyboard layout:
Hit ⌥ Option+c.
The U.S. custom keyboard layout adds a second way of producing ⟨ç⟩:
Hit ⇧ Shift+§ (the option deadkey), then release it, then hit c.
This works even in Terminal.app when Use option as meta key has been checked.
Note that the U.S. custom keyboard layout does two additional things:
It converts plain § into a ⎄ Compose key (so you could also produce ⟨ç⟩ by hitting §, then ,, then c).
It replaces the CapsLock mapping by a (significantly extended) U.S. Extended keyboard layout.
Remap option deadkey to right option modifier key
If you have a physical ANSI keyboard, then you lack the § key. In that case, I recommend assigning the § key to some other key, for instance to the right ⌥ Option modifier key. Install KeyRemap4MacBook, open ~/Library/Application\ Support/KeyRemap4MacBook/private.xml and paste the following code:
<?xml version="1.0"?>
<root>
<item>
<name>Send ISO Section for right Option</name>
<identifier>private.send_iso_section_for_right_option</identifier>
<autogen>--KeyToKey-- KeyCode::OPTION_R, KeyCode::UK_SECTION</autogen>
</item>
<item>
<name>Send Shift+ISO Section for Shift+right Option (keep normal right Option without Shift)</name>
<identifier>private.send_shift_iso_section_for_shift_right_option</identifier>
<autogen>--KeyToKey-- KeyCode::OPTION_R, ModifierFlag::SHIFT_R, KeyCode::UK_SECTION, ModifierFlag::SHIFT_L</autogen>
<autogen>--KeyToKey-- KeyCode::OPTION_R, ModifierFlag::SHIFT_L, KeyCode::UK_SECTION, ModifierFlag::SHIFT_L</autogen>
</item>
</root>
Then, open the KeyRemap4MacBook preference pane, hit ReloadXML and then select “Send ISO Section for right option”. Now, your ⌥ Right Option key is remapped to §, so while the U.S. custom keyboard layout is active, hitting ⇧ Shift+⌥ Right Option will give you the option deadkey state (hitting ⌥ Right Option without additional modifiers will give you a deadkey state equivalent to the option modifier.
If want to keep ⌥ Right Option when ⇧ Shift is not pressed (instead of the ⎄ Compose key), then select “Send Shift+ISO Section for Shift+right Option (keep normal right Option without Shift)” in the KeyRemap4MacBook preference pane (instead of “Send ISO Section for right Option”). Like that, only ⇧ Shift+⌥ Right Option will produce the option deadkey, while plain ⌥ Right Option will continue to work as an option modifier. You can even continue using ⌥ Right Option+⇧ Shift modifier combos (for instance ⌥ Right Option+⇧ Shift+c→⟨Ç⟩) as long as you don’t hit ⇧ Shift first.
The above answers mention ways to enter non-ascii input, but that's not really the problem here. The C-x 8 method lets you enter a bunch of non-ascii, but the problem is that you need the option key on mac just to enter the (ascii) character `|' (vertical bar)!
So how do you then enter stuff like M-| (region to shell command) when running emacs in ssh under Terminal.app? No way for it but to use the escape key, since | is option-7 and Terminal.app for some stupid reason won't let you use Cmc as meta :-(
(If anyone knows of a hack (SIMBL perhaps?) that actually does let Terminal.app use Cmd as meta, I'd be very grateful...)
The following solution works, is UNOBTRUSIVE and you don't need iTerm2 or Aquamacs or whatever.
Step 1
Keep "Use option as meta key" turned ON in the Terminal.app Settings.
Step 2
Edit ~/.inputrc (make it if it doesn't exist already), add the following line:
"\e3": '#'
This will remap ⌥ alt + 3 so that you produce a # character as expected in the terminal, instead of it annoyingly coming back with the prompt (arg: 3).
Step 3
Edit ~/.emacs, add the following line:
(global-set-key (kbd "M-3") "#")
This will remap ⌥ alt + 3 so that you produce a # character as expected inside emacs, instead of it annoyingly doing nothing.
Caveat 1, This is just 1 re-map. So ⌥ alt + ? (other keys) won't be remapped, e.g. you may wish to remap ⌥ alt + n to produce the tilde key ~. Simply follow the same steps outlined above obviously switching 3 with whichever key you need going forward.
Caveat 2, When you ssh into another box, you will face the same difficulties, but all you have to do there is edit the ~/.inputrc and ~/.emacs files on that box.
Caveat 3, I'm British, on a British MacBook. So I can't vouch for foreign MacBooks.
Aquamacs supports that, at least for my (french) keyboard. Once Aquamacs is installed (via drag'n'drop), you can go to Options -> Option, Command, Meta keys and choose an appropriate setting for your keyboard (in my case, ...Meta & French). I am not proficient with Emacs, but all the useful combinations I have tried seem to work ([, {, |, and so forth).
Supported keyboards, according to the menu items as of version 2.1, are :
British
US
Swiss-french
Swiss-german
Finnish
Italian-Pro
Italian
Spanish
French
German
I would guess the Aquamacs team would be grateful for any contribution, though, should your keyboard not appear in the list.
I bit the grass and started hitting the escape key instead. You get use to it...
I would like to mod this question up or something because i also use a Swedish keyboard where i must press alt+7 or alt+shift+7 to make | and \ respectively.
I also use Irssi in Terminal.app and these don't mix well.
I'm a long time vim user though so emacs is not an issue to me.
Isn't there some way to remap CMD to be Meta in Terminal.app?
So far i've been surviving by simply typing /wg N in Irssi because having those characters in my Terminal is much more important than IRC.
A solution would be worth gold to me though! :)
This is years late, but for people coming across this page whilst searching for a solution, as I did, I have decided to build one myself, one that doesn't require abandoning Terminal.app in favour of iTerm 2.
It is a simple status bar app that runs in the background and rewrites all left-Alt + $KEY key events to two key events in rapid succession, Esc, then $KEY; however, it only does this if Terminal.app is the focused application.
You can find it here at https://github.com/habibalamin/Metalt.
I assigned escape to the caps lock key and it works quite good. You can configure it easily in the mac system preferences > keyboard > modifier keys.
https://apple.stackexchange.com/a/282092/236382

Resources