How to map Caps Lock to Esc for Vim in macOS? - macos

I use vim to develop on my mac and I updated to Mountain Lion yesterday. I was using http://pqrs.org/macosx/keyremap4macbook/ this to remap the escape key's function to caps lock to switch between edit and insert modes. I can't really functionally develop in vim without this and it doesn't seem to work in Moutain Lion. I really need a solution soon!
Thanks a lot guys.

Found this:
https://github.com/tekezo/PCKeyboardHack/issues/8#issuecomment-7359829
It worked perfectly for me.
I had grown so accustomed to using caps-lock as esc, that it was killing my productivity until I found this.

You can achieve the same using the accessibility features of macOS. A usage example:
Map Caps Lock to Esc;
Map double Shift to Caps Lock.
To achieve (1) go to Settings > Keyboard > Special keys. In the appeared dialog set the desired mappings.
To achieve (2) go to Settings > Accessibility > Keyboard > Hardware > Activate lock keys.
So now if you have taps on you'll even have a logo on your screen notifying you about that.
NB. These are system-wide settings, not only for vim, but I believe it doesn't make a lot of sense to have a special mapping only for one editor, it will only make things more confusing.
NB. The Settings names could differ slightly for you, since I had to translate them from Dutch. Use some fuzzy logic to get to the right place.

Related

Caps Lock does not seem to work as modifier key (Insert) with NVDA running inside a virtual machine (macOS VMware Fusion)

I'm running NVDA inside a virtual machine on my macOS using VMware Fusion. I do that since many years, and it's generally a very smooth experience, except that I need to map a keyboard key to Insert. I use Karabiner-Elements to do just that: it maps my right option key to Insert. This runs just fine, but it is quite a complex installation/configuration, and when asking clients to do the same, they are quickly overwhelmed. (Sadly, while VMware Fusion offers a feature to map certain keyboard combos to different ones, it does not allow to just change a single key's [ie. right option to insert] mapping.)
So I tried to go the route of activating the NVDA option to use caps lock as modifier key, too. But this just does not seem to work - or do I do something wrong?
Would I need to keep holding caps lock while hitting (for instance) N (to show the NVDA menus)
Or would pressing and releasing caps lock trigger some special "I am on Insert now" mode, so I could just hit another key like N? And then press and release caps lock again to deactivate the "special mode" again?
Neither option works for me. What I can say though is that the "real" caps lock functionality does not get activated anymore with the option checked, unless I hit it twice in a row quickly. So it at least seems to have some effect...
Am I doing something wrong? Any help is highly appreciated.

How to make iTerm2 appear on the current screen?

Under Preferences -> 'Keys' It is possible to tick Show/hide iTerm2 with a system-wide hotkey.
However iTerm always appears on the main display (monitor) instead of where the cursor currently resides.
e.g. if I have three monitors, and am working on the third screen, the hotkey makes iTerm appear on first monitor, instead of where I am currently working.
Any advice how to solve this please?
UPDATE:
The bug strikes back again in v.3.1.6. If any workarounds are known, please share.
I'm on Sierra using iTerm 3.1 and I have the option under window to put the screen where the cursor is (bottom right drop down options). I'm using it with a hotkey.
The answer by Grant works.
The only thing you need to do is to install the beta version since there was a bug in the stable version.
This bug was fixed in 3.1.beta.1 https://iterm2.com/downloads.html
Here's the link to the latest beta version https://iterm2.com/downloads/beta/iTerm2-3_1_beta_4.zip
This may be a couple more keystrokes than you were hoping for, but if you install window management software like Size Up, you can get this working with just a few keystrokes.
Maintain your ⌥Space hotkey preference on Iterm2. Go to Size Up -> Preferences and change 'Send Window Prev Monitor' to an easy keystroke. I used ⌥1.
Now, you can do ⌥Space to get the terminal open and ⌥1 one or two times to get it to your monitor of choice. It takes a couple of key combos, but not too many!
I had this problem with macos monterey and iterm 3.4.15. I'm using the hotkey to show the terminal with slide-out window. After some search on the internet I found that disabling the option on system preferences to reopen closed documents solved the issue and the hotkey is now opening terminal on the screen with cursor as it should.
mac -> System preferences -> General -> (deselect this) Close windows when quitting an app
Neither of the above worked for me, but this helped, even though the question was quite different in that thread.

OSX: Programmatically remap Caps Lock's functionality (as set via System Preferences)?

My question is referring to the System Preferences setting that enables you to remap Caps Lock to e.g. Ctrl key.
^ Is it possible to affect this setting programmatically?
Primarily I'd be interested achieving this via defaults or some shell trick; secondarily via AppleScript (yuck).
I know I can probably achieve this by using 3rd party tools, such as KeyRemap4MacBook, but that's a last resort. But I'd rather prefer a non-3rd party solution, if possible.
My use case:
Using Keyboard Maestro and its nice macro triggers, I'm looking to automatically remap Caps Lock -> Ctrl in apps like MacVim, and toggle it back to normal Caps Lock when leaving the affected apps.
You can toggle this using AppleScript. It'll be a simple automation technique, that will basically do the same toggle in System Preferences for you automatically.
You can add the created AppleScript toggle to the MacVim Scripts Toolbar icon. That way, while inside the app you can toggle it, and put it off while leaving.
Is this what you're looking for ? If you still need this I'll design the AppleScript for you and post it in here in a bit.

Scrolling inside Vim in Mac's Terminal

I've been googling around trying to figure out if it's possible to use my mouse wheel to scroll while inside Vim in Mac's Terminal, with no luck. It seems as if only X11 or iTerm support this.
Before I give up, I thought I'd try the geniuses here to see if anyone knows a way to do this. So, does anyone know if I can set that up?
Or should I seriously consider using a different terminal application?
And if you're using iTerm, add this to your vimrc
:set mouse=a
http://bitheap.org/mouseterm/
Use MouseTerm (and do make sure to install SIMBL first!) and scrolling will work like a charm, even remote, using Mac Terminal.
You need to fully quit the Terminal application (Command+Q) and then launch it again after installing MouseTerm.
This is an old question, but a top hit on google, so I feel compelled to provide an updated answer.
Running OSX El Capitan 10.11, vim mouse and trackpad scrolling just worked(TM) for me in Terminal.app by default. However occasionally the mouse/trackpad input stopped manipulating the vim buffer, and started scrolling the terminal buffer. The answer was Command+R or Menu View --> Allow Mouse Reporting. Turning that on allowed the mouse/trackpad scroll operations to move the cursor in vim.
Termanal Menu > View > Allow Mouse Reporting
Terminal Menu > Preferences >
Keyboard > Scroll alternate screen
If the mouse functionalities still do not work properly take a look at my answer in this post How to let vim behave on Mac OS X as on Ubuntu?, just add to your .vimrc
set ttymouse=xterm2
You can read this article, but I'm pretty sure since the default terminal in Mac OS X has a built-in scrollbar, the mousewheel commands automatically go to it. You could definitely use gVim as suggested in the previous answer. I find that I don't generally want to use the mouse in Vim though as it takes my hands off the keyboard.
I just use 50j to go down and 50k to go up. Not exactly scrolling, but it works pretty well.
Make sure the terminal is xterm & not ansi in Terminal Menu > Preferences > Profiles > Advanced. I accidentally broke scrolling by changing the term type in a naive effort to get coloring to work over ssh.
Use gVim, which gives you a text editing environment in a window you can scroll. Terminal is not involved when using gVim.
I'm using xterm in X11 (XQuartz 2.3.4) and vim works very fine with mouse and also suport 256 colors.
Here is the ~/.Xresources I use to make my xterm nicer in X11:
XTerm*faceName: Lucida Sans Typewriter Regular
XTerm*faceSize: 9
XTerm*utf8: 1
xterm*saveLines: 1000
xterm*jumpScroll: true
!xterm*awaitInput: true
!xterm*multiScroll: true
XTerm*scrollBar: false
xterm*scrollbar*thickness: 16
xterm*rightScrollBar: true
XTerm*foreground: white
XTerm*background: grey10
!XTerm*background: black
XTerm*cursorColor: yellow
xterm*visualBell: false
xterm*loginShell: true
Little tips, to remove the bell sound in X11's xterm type this command:
xset b 0
I would recommend using iTerm - it has so many advantages over Terminal eg Mouse support, 256 colors, sensible copy and paste (auto-copy, word/url selection with double click, middle click paste)...
When using iTerm create a .vimrc file (if not already there) in your home folder and add the line:
:set mouse=a
Scrolling down in vim to view a file works after this.

Customised programs for Dvorak

I have not configured much keybindings due to my change from QWERTY to Dvorak, 4 months ago. I am using a programmer version of the layout. I find many terminal-based programs, such as Elinks and Vim, easier to use. The experience raises a question:
Which programs are customised for Dvorak?
[Some Elaborating] The term "customised program" means that you can easily use a Dvorak with the program. At least for me, Dvorak has opened my eyes to the shortcuts that I found odd earlier. How about you? Please, do not hesitate mention the programs.
[My Findings]
Opera browser
Opera's keys, such "CTRL+A", "CTRL+E", "CTRL+D" and "CTRL+H", are on the home row in Dvorak. Then, have a look at Qwerty: not on the home row. Is Opera customised for Dvorak or vice versa? Or is it just because of Unix? Earlier, I used Firefox 95% of my time. Now, the ratio is 40% for Firefox.
Terminal apps
The answers have mentioned terminal apps, such as GNU Screen. I am interested to know more about them.
I've been using Dvorak for 10+ years now, and actually have found that most of the QWERTY keybindings are actually just fine on a Dvorak layout.
But, since you're looking for things to customize, I have made extensive bindings changes in gnu emacs for my favorite bindings. It's fully customizable, and a great editor. My .emacs file has over 15 years of changes in it -- I'm sure others here have been using it for much longer than that!
Another great program to customize for keybindings is gnu screen, which I'm beginning to use extensively on the machines that I administer remotely.
My two cents: use AutoHotkey / IronAHK to remap hotkeys globally or for specific keybinds that cause you grief. Since switching to Dvorak a few years ago, I've've only had one such problem, but it's a big one: the hotkeys for cut, copy, and paste are placed awkwardly on Dvorak compared to pressing ctrl+x/c/v.
The keys are obviously meant to be adjacent and close to the control button, so globally remapping these keys is a great solution for me.
^q::^x
^j::^c
^k::^v
That way, you can use whatever programs you like, and bend them to your will.
I learned Vim on Qwerty, but I prefer Dvorak for typing English, so I use qwerty2dvorak (http://www.vmunix.com/vim/howto/dvorak.html) which lets me use Qwerty to tell Vim what to do (ie, hjkl) and Dvorak to type text.
I just set my keyboard on Dvorak, and go. I use the dvorak layout for all my command keys, and you get used to it very quickly. Apple (and others) do have layouts set up where the layout is Dvorak for normal typing, but querty when the command key is used.
Whatever you do, just pick something simple and stick with it. If you're having to use different keyboard shortcuts for different apps, you're likely to wear yourself down remembering all that.

Resources