Typing Unicode Symbols in VS Code - macos

I'm having trouble typing the Ω symbol (U+03A9) in the Visual Studio Code editor.
On my Mac, I can usually type this with option + z but it doesn't seem to work in Code.
Many other combinations seem to work just fine (for example, ≈ option+x inputs correctly).
I'm wondering if VS Code is intercepting option + z for some other keyboard shortcut. I searched for a list of keyboard shortcuts but didn't find anything relevant.

⌥Z is bound to toggle word wrap.
You can toggle word wrap for the VS Code session with ⌥Z. Restarting VS Code will pick up the persisted editor.wrappingColumn value.
https://code.visualstudio.com/docs/editor/codebasics#_common-questions
In the Default Keyboard Shortcuts it shows up as:
{
"key": "alt+z",
"command": "editor.action.toggleWordWrap",
"when": "editorTextFocus"
}
To remove a specific key binding, simply add a - to the command and the rule will be a removal rule.
https://code.visualstudio.com/docs/customization/keybindings#_removing-a-specific-key-binding-rule
Your keybindings.json file should include the following:
{
"key": "alt+z",
"command": "-editor.action.toggleWordWrap",
"when": "editorTextFocus"
}
I have confirmed that this is working on VSCode for Mac.

Related

How does one stop VS code from going into normal mode in Vim when doing normal copy `Cmd + c`?

whenever I select code and then do Cmd + c (copy) it then goes by itself to normal mode in vim. So:
How do I stop VS code from doing that?
Why is it doing that?
My default keybinding for copy paste has (go to command pellet type keybinding go to default keybindings):
{ "key": "cmd+c", "command": "execCopy" },
probably this: { "key": "cmd+c", "command": "extension.vim_cmd+c",
"when": "editorTextFocus && vim.active && vim.overrideCopy && vim.use<D-c> && !inDebugRepl" }, except it doesn't let me edit the file!?!?!
I feel the answers are longer than need.
Follow these steps:
Command palette Cmd+shift+P
Type Open Keyboard Shortcuts (not the Json one)
Nice looking file in vscode comes up like pinocchio said (see attached image)
Search cmd+c
Go the the row that has in it's column extension.vim_cmd+c
Click it and then hit backspace (or right click select remove).
Done.
For sake of context see Snippet:
without seeing your exact extension configuration and system info, it's hard to say with certainty, but you may have an extension conflicting with or overriding the default behavior.
open the command palette and type keybindings and choose the command to edit keybindings. you can search for cmd+c to see if anything else is using it, and in what context. alternatively, you can do this directly from your keybindings.json file.
also, for the sake of diagnostic, you can always launch vs code with no extensions enabled just to see if it is indeed an extension problem. if so, you can selectively enable extensions, and when you find the right one, you can look within its internal settings
As Tedskovsky suggested, go to the json file that has the keybinding. Find the last one that maps cmd+c to something. Then remove it. Though, that file can only be opened in read mode so you will need open:
Preferences: Open Keyboard Shortcuts `Cmd+K Cmd+S`
NOT THE JSON ONE (at least not in vscode):
So the first one (not the second one).
That opens a nice looking window that allows you to edit the keyboard settings. Probably the last one in that list I assume. I went to the uneditable one and found the last one and removed it (and yes as Tedskovsky suggested, it was added by the vim extension).
The name of it was:
{ "key": "cmd+c", "command": "extension.vim_cmd+c", "when": "editorTextFocus && vim.active && vim.overrideCopy && vim.use<D-c> && !inDebugRepl" },
search is somewhere in your default editable file to remove it (click and select remove).
Don't select the json file for the keyboard bindings if you want to change it.
Go to settings.json and add this:
"vim.handleKeys":{
"<C-c>": false
}

How to prevent the typing of special characters like "~" modifying the next keyboard input?

When I type in "^" it is highlighted and waits for the next keyboard input such that if available, the next input is accented with it. For example typing in "^" and then "a" would result in "â" instead of "^a". How do I prevent this from happening?
I was able to solve this by creating a custom layout with the help of this post
https://superuser.com/questions/665494/how-to-make-a-custom-keyboard-layout-in-os-x.
First downloaded Ukelele.
Chose my desired layout to be edited as the current layout.
In Ukelele, went to File -> New From Current Input Source
The current layout is then shown on an on-screen keyboard. All the keys that will automatically accent the next keyboard input are highlighted with a different color from the rest of the keyboard. Right Click on the highlighted key and clicked on Make Output and pressed OK.
This makes the output of the key to the character and does not accent any following inputs. Did the same for all other highlighted keys ("Dead Keys" I think they are called).
Then saved the keyboard layout as a Bundle file anywhere (Remember to also change the name of the keyboard layout within the bundle. Otherwise it will have the same name as the layout you started with and may cause confusion when trying to select it)
Moved the saved bundle to ~/Libraray/Keyboard Layouts/
Selected the new layout from the Input Sources in System Preferences
Became a happy programmer :)
If by chance you are using the US International PC layout, remove that and use US, British, or ABC instead.
In the Spanish LATAM layout I ran into the same problem with the symbols ~, ^ and `. I added comfortable key bindings for them as "regular keys" (contrary to dead keys) with Karabiner. I think the approach I followed could work with other layouts as well, although I haven't tried.
Using Karabiner-Elements
Before getting into Karabiner, select "Show Keyboard Viewer" in the menu of the Input icon in the menu bar. You should see a virtual keyboard displayed. If the Input icon is not shown, enable:
System Preferences > Keyboard > Input Sources > Show Input menu in menu bar
Leveraging the virtual keyboard, find if there is a specific key combination to make the special symbol be printed as-is (without waiting for another key press). For instance, in Spanish LATAM, pressing Option+Shift+{ directly prints ^.
The amount of keystrokes can be reduced using Karabiner. The following is an example of a complex modification to reduce Option+Shift+{ into Option+{ for typing ^ in the Spanish LATAM layout. To find the value for key_code, use Karabiner's EventViewer.
{
"title": "Regularize dead keys - Spanish LATAM",
"rules": [
{
"description": "left_option+{ PRINTS caret(^)",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "quote",
"modifiers": {
"mandatory": ["left_option"]
}
},
"to": {
"key_code": "quote",
"modifiers": ["left_option", "left_shift"]
}
}
]
}
]
}
In my case, my laptop keyboard was working fine, but somehow I bumped some keys and then my external keyboard was typing symbols instead of characters and numbers as expected.
I was going to investigate further, then I remembered the ancient wisdom that provides the simplest solution.
unplug it & plug it back in.

Can't close Visual Studio Code Window with my shortcut, yet it works for tabs

In apps I use, I like to use the command ctrl+cmd+left to close tabs and to close windows when there are no open tabs.
I tried to do the same for Visual Studio Code by searching for the commands with cmd+w and replacing them in my keybindings.json file with ctrl+cmd+left.
Those are the first two elements in my keybindings.json below.
// Place your key bindings in this file to overwrite the defaults
[
{ "key": "ctrl+cmd+left", "command": "workbench.action.closeWindow",
"when": "!editorIsOpen" },
{ "key": "ctrl+cmd+left", "command": "workbench.action.closeActiveEditor" },
{ "key": "ctrl+cmd+right", "command": "workbench.action.files.newUntitledFile" }
]
I can close tabs with ctrl+cmd+left. I think that means the 2nd command is working. The 3rd one above for opening tabs with ctrl+cmd+right works too.
However I cannot close the window with ctrl+cmd+left, which I'm pretty sure means that the first command isn't working. Yet, I can still close the window with cmd+w.
Why can't I close a window with no tabs open with ctrl+cmd+left? Why does it still work for cmd+w?
EDIT: I was able to get things to work as I wanted by changing the order of the first two shortcuts. I haven't figured out why that works yet and would appreciate it if someone could answer that. I suspect there's some sort of cascading esque feature that causes the 2nd command to overwrite the first command and the when condition prevented that from happening with the order reversed.
Keybinding rules in Visual Studio Code are evaluated from the bottom to the top. So it starts with your custom rules in your keybindings.json file and goes through the default rules. The first keybinding rule that matches your key and meets its when condition is applied. See the VSCode docs
As a result, when I tried to close a window it would always match the keybinding to close an active window. Switching the order of the first two commands above resolves the problem because now when I try to close a window it matches the when condition of the editor is not open. Additionally, when I'm trying to close a tab it doesn't match the condition of the editor is not open so it looks up to the next rule (which has no when condition limiting the scope of the rule) and closes the active editor.
So Visual Studio Code actually "cascades" from bottom to top.

Submlime Text 2 - Windows key behavior on Mac?

I'm using a Mac for development, but 15 years of Windows experience before that means certain keystrokes are hard-wired (like Home for beginning of line, etc).
Is there a simple way to get Sublime Text 2 on my Mac to behave more like a Windows editor? I am used to Visual Studio.net on Windows.
I see two possible methods to solve your problem. The first is to find an OS X keybinding that does what you want. Then in the ST console enter sublime.log_commands(True). Then execute the command. This will give you the command so you can create a custom key binding. The second is to search for a key binding where you know the proper behavior exists in the Windows key map file (in your case home). In either case, the goal is to get a command and any necessary arguments.
You can now create a custom key binding. Go to Preferences -> Key Bindings - User. Insert the key binding you desire here. For your particular case, you would want something like the following.
[
{ "keys": ["home"], "command": "move_to", "args": {"to": "bol", "extend": false} }
]
Of course remove the square braces if you already have an entry. Additionally, you can change the keys to something else if you need to, but since you said you wanted to rebind home, I assume that is what you want.
I had a hard time getting used to Mac after I switched from Windows. Took me quite a while but you know, you have to get used to a few frequently used shortcuts.
Here are a few shortcuts.
Command +
left arrow - beginning of the line,
right arrow - end of the line,
up arrow - beginning of the document,
down arrow - end of the document.
Alt or Option +
left arrow - beginning of the word,
right arrow - end of the word.
Hope this helps.

Change behavior of Alt key in Sublime Text 2

I want to be able to use the alt key in Sublime Text 2 like I can use it on the command line in iTerm. For example, when I hit alt+f, the cursor moves forward a word, or when I hit alt+b, the cursor moves backward a word.
Instead, what happens is UTF+8 characters corresponding to the keys get inserted (ex: ƒ or ∫). In iTerm on the Mac, I can change the left alt behavior to act like +esc and it seems to do the trick.
This could either be a Mac OS X problem in general (I have the same problem in the web browser) or something specific with Sublime Text 2 so I would appreciate any Mac or Sublime Text 2 expertise. Thanks!
After using Sublemacs Pro for a few days, I realized it does too much for my liking, although it may be fine for more seasoned emacs users.
I come from TextMate and what I really want is the best of all worlds: mostly Sublime shortcuts, a few missing shortcuts from Textmate's ruby library of shortcuts, and a few shortcuts that Textmate stole from emacs.
So, I figured out how to solve the alt+f and alt+b problems:
{ "keys": ["alt+b"], "command": "move", "args": {"by": "subwords", "forward": false} },
{ "keys": ["alt+f"], "command": "move", "args": {"by": "subword_ends", "forward": true} }
If I find some more really useful ones, I'll post them here. Also, if I find a resource that lists all the possible "by" field values, I'll post that, as well.
There is a Sublime Text 2 plugin called Sublemacs Pro that provides emacs-like keybindings and operations, including those that you mentioned pining for. You can find installation instructions and the complete keybinding reference on the Github page.

Resources