LoginSignup
2
4

More than 5 years have passed since last update.

vimでインサートモードを抜ける時のあれ(Hammerspoon版)

Last updated at Posted at 2017-01-31

vimでインサートモードを抜ける時のあれ(Hammerspoon版その2)
hs.eventtap を使用したものに書き換え。


Sierra にアップグレードして困らないための準備

前準備

Hammerspoon のインストール

$ brew cask install hammerspoon

Lutzifer/keyboardSwitcher のインストール

本家の brew install はコケるので、とりあえず以下でインストール。

$ brew install oppara/homebrew/keyboardswitcher

入力ソースの設定

以下の設定
input_source.png

init.lua

init.lua
local function keyCode(key, modifiers)
   modifiers = modifiers or {}
   return function()
      hs.eventtap.event.newKeyEvent(modifiers, string.lower(key), true):post()
      hs.timer.usleep(1000)
      hs.eventtap.event.newKeyEvent(modifiers, string.lower(key), false):post()
   end
end

local function switchToUs()
    local cmd = '/usr/local/bin/keyboardSwitcher select U.S.'
    os.execute(cmd)
    hs.console.printStyledtext(cmd)
end

local ctrlBracket = hs.hotkey.bind({'ctrl'}, '[', keyCode('escape'), switchToUs)


local function handleGlobalEvent(name, event, app)
    if event == hs.application.watcher.activated then
        local bundleId = string.lower(app.frontmostApplication():bundleID())
        if bundleId == 'com.apple.terminal' then
            ctrlBracket:enable()
        else
            ctrlBracket:disable()
        end
    end
end
watcher = hs.application.watcher.new(handleGlobalEvent)
watcher:start()

備考

read は出来る

$ defaults read com.apple.HIToolbox AppleSelectedInputSources
$ defaults read com.apple.HIToolbox AppleSelectedInputSources | xargs | cut -d';' -f3 | cut -d'=' -f2

write が:confounded:

$ defaults write com.apple.HIToolbox AppleSelectedInputSources -array '{ InputSourceKind = "Keyboard Layout"; "KeyboardLayout ID" = 0; "KeyboardLayout Name" = "U.S."; }'

多分、こっちが王道。escapeのループ問題も解決できそう。。
IntelliJとかJVMのIDE使いでもKarabinerなしでバックスラッシュを片手入力したい

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4