Verified Commit 7019952d authored by Connor Shea's avatar Connor Shea 🏄

Draft of a post on VS Code Keybindings.

parent 47d8b0b2
Pipeline #38705982 passed with stage
in 1 minute and 26 seconds
---
layout: post
title: Abusing VS Code Keybindings to match macOS in an AWS WorkSpace
subtitle: Navigate through text in a Windows environment as though it was macOS
tags: [vscode, aws-workspaces, windows, macos, keybindings]
published: True
---
After a few years of using Sublime Text, I switched to [Visual Studio Code](https://code.visualstudio.com/) earlier this year. I also recently started using an [AWS WorkSpace](https://aws.amazon.com/workspaces/) (essentially a means of running a Windows desktop "in the cloud" and streaming it to your personal device) for work, but I was having trouble writing code without the text navigation keybinds I was used to. On macOS, you're able to easily navigate around text using the directional keys and modifier keys (e.g. {% kbd option left %} )
Honestly, I probably should've just given up and learned Vim keybindings.
There are plenty of blog posts about plugins and configuration for VS Code, but I couldn't find anything for this specific use-case. I figured I may as well share it.
Here's my `keybindings.json` (well, the relevant parts):
```jsonc
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "ctrl+up",
"command": "cursorTop",
"when": "textInputFocus && isWindows"
},
{
"key": "ctrl+home",
"command": "-cursorTop",
"when": "textInputFocus"
},
{
"key": "ctrl+down",
"command": "cursorBottom",
"when": "textInputFocus && isWindows"
},
{
"key": "ctrl+end",
"command": "-cursorBottom",
"when": "textInputFocus"
},
{
"key": "alt+right",
"command": "cursorWordEndRight",
"when": "textInputFocus && isWindows"
},
{
"key": "alt+left",
"command": "cursorWordStartLeft",
"when": "textInputFocus && isWindows"
},
{
"key": "ctrl+right",
"command": "-cursorWordEndRight",
"when": "textInputFocus"
},
{
"key": "ctrl+left",
"command": "-cursorWordStartLeft",
"when": "textInputFocus"
},
{
"key": "shift+alt+left",
"command": "cursorWordStartLeftSelect",
"when": "textInputFocus && isWindows"
},
{
"key": "ctrl+shift+left",
"command": "-cursorWordStartLeftSelect",
"when": "textInputFocus"
},
{
"key": "shift+alt+right",
"command": "cursorWordEndRightSelect",
"when": "textInputFocus && isWindows"
},
{
"key": "ctrl+shift+right",
"command": "-cursorWordEndRightSelect",
"when": "textInputFocus"
},
{
"key": "ctrl+right",
"command": "-cursorWordEndRight",
"when": "textInputFocus"
},
{
"key": "ctrl+left",
"command": "cursorHome",
"when": "textInputFocus && isWindows"
},
{
"key": "home",
"command": "-cursorHome",
"when": "textInputFocus"
},
{
"key": "ctrl+shift+left",
"command": "cursorHomeSelect",
"when": "textInputFocus && isWindows"
},
{
"key": "shift+home",
"command": "-cursorHomeSelect",
"when": "textInputFocus"
},
{
"key": "end",
"command": "-cursorEnd",
"when": "textInputFocus"
},
{
"key": "shift+end",
"command": "-cursorEndSelect",
"when": "textInputFocus"
},
{
"key": "ctrl+shift+right",
"command": "cursorEndSelect",
"when": "textInputFocus && isWindows"
},
{
"key": "ctrl+right",
"command": "cursorEnd",
"when": "textInputFocus && isWindows"
},
{
"key": "ctrl+shift+end",
"command": "-cursorBottomSelect",
"when": "textInputFocus"
},
{
"key": "ctrl+shift+down",
"command": "cursorBottomSelect",
"when": "textInputFocus && isWindows"
},
{
"key": "ctrl+shift+home",
"command": "-cursorTopSelect",
"when": "textInputFocus"
},
{
"key": "ctrl+shift+up",
"command": "cursorTopSelect",
"when": "textInputFocus && isWindows"
}
]
```
# Turns:
# {% kbd shift cmd V %}
# Into:
# <kbd>⇧ shift</kbd><kbd>⌘ cmd</kbd><kbd>V</kbd>
module Jekyll
class Kbd < Liquid::Tag
def initialize(tag_name, markup, tokens)
@markup = markup
# http://meta.apple.stackexchange.com/q/193/68
@special = {
'cmd' => '&#8984;',
'ctrl' => '&#8963;',
'option' => '&#8997;',
'shift' => '&#8679;',
'caps' => '&#8682;',
'eject' => '&#9167;',
'return' => '&#9166;',
'delete' => '&#9003;',
'esc' => '&#9099;',
'right' => '&rarr;',
'left' => '&larr;',
'up' => '&uarr;',
'down' => '&darr;',
'tab' => '&#8677;',
}
super
end
def render(context)
keys = @markup.gsub(/\s+/m, ' ').strip.split(' ')
keys.map! do |key|
key_name = key
key = @special[key] if @special.has_key?(key)
key = "<kbd><abbr title='#{key_name.capitalize}'>#{key}</abbr></kbd>"
end
keys.join(' + ')
end
end
end
Liquid::Template.register_tag('kbd', Jekyll::Kbd)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment