Change behavior of Alt key in Sublime Text 2 - macos

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.

Related

Sublime 4/Vintage: repeat key on key down only in edit mode

On my mac, I need to be able to access special characters such as accents for editing purposes and for now I access this by holding a key down and then get the suggestions shortcut.
However, I would like to use the Vim mode in Sublime as well so moving around with h, j, k, l is quite tedious if I can't hold the key down to move faster.
Is there any way to only repeat a key when pressing it down in edit mode, or to have this behaviour only for h, j, k, l?
Thanks
Probably unsurprisingly, the press-and-hold-for-special-characters behavior is a macOS feature. It doesn't seem possible to change the behavior on the fly. You can adjust it per app like this:
defaults write com.sublimetext.4 ApplePressAndHoldEnabled -bool false
So the question becomes: how can you enter special characters in insert mode? In vanilla vim, you could use inoremap to replace, say, Option+l with "ł". However, NeoVintageous (which I hope you're using, not the deprecated Vintage mode) does not support remaps in insert mode. It claims to support digraphs, which would be another way of achieving this. However, the keyboard command to insert a digraph is Ctrl+k, which conflicts with one of the default Sublime Text key bindings on macOS. (The one to kill from the cursor to EOL, which is copied from Emacs and available in standard macOS text fields.) It's presumably possible to work around this, but I felt like Ctrl+k+l+/ was kind of wordy anyway.
Fortunately, there IS a fast, simple solution: a Sublime key remap. Open your user key bindings (Sublime Text > Preferences > Key Bindings) and add this one:
{ "keys": ["option+l"], "command": "insert", "args": {"characters": "ł"} }
Now Option+l will add the l-slash character to your document. If you need the special character this is replacing (the not sign "¬"), you can of course choose another binding.
I presume this is the one you want, since it's the only special character available for me when I press-and-hold any of the hjkl keys. But this approach will work equally well for any other characters you might want to insert.

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
}

Typing Unicode Symbols in VS Code

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.

Is there a keyboard shortcut for creating a snippet in Sublime Text?

Going to Tools > New Snippet everytime I need to create a new Sublime Snippet is starting to become cumbersome. Is there a way to create a shortcut in which I can jump to the new snippet page by pressing Command + i?
Preferences -> Key Bindings - User, then add the below line:
{ "keys": ["ctrl+g"], "command": "new_snippet" }
You can replace the ctrl+g combination with anything of course.
BUT be aware: it might happen that the keyboard layout doesn't send the exact keys that the command is bound to.
To investigate this open the console at View -> Show Console or with CTRL+, and type sublime.log_input(True). Now click in the document and give your key combination a try - if the appropriate output doesn't appear in the console, you better specify another combination.
Finally, if sublime.log_input(True) bothers your coding or debugging process, you can easily disable it by clicking again in the console and using the UP arrow to get the command you typed the last type, change True to False, then hit Enter.
open the command palette, find a item named "Preferences: Key Bindings - User", open it and add this:
{ "keys": ["ctrl+y"], "command": "show_overlay", "args": {"overlay": "command_palette", "text": "Snippet: "}}
You can change the "ctrl+y" for anything you like to be the shortcut.

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.

Resources