I am using Sublime Text 3 on Windows with German keyboard. The backslash \ is assigned to alt gr + ß but this key binding is not properly working. (The cursor goes up by several lines.)
Since alt gr is equivalent to ctrl+alt on Windows, I added the following line in sublime-keymap.
{ "keys": ["ctrl+alt+ß"], "command": "insert", "args": {"characters": "\\"} }
But this is not working, neither.
Is it possible to assign \ to alt gr+ß?
Note:
"keys": ["ctrl+alt+0"] (instead of "keys": ["ctrl+alt+ß"]) works. But I want use "alt gr+ß" for backslash.
"keys": ["ctrl+alt+\u00DF"] is not working.
The following settings works perfect!
In Preferences -> Key Bindings
{ "keys": ["ctrl+alt+["], "command": "insert", "args": {"characters": "\\"} }
Related
How to add string pieces to existing strings in Sublime Text 3?
Example: I have a text with strings like (23aa67) or (ret457) and I would like to transform them into \as{(23aa67)} or \as{(ret457)}.
Is it possible?
This solution will work if you have at least build number 4107 - you can tell by selecting Help → About Sublime Text.
Open your key bindings by selecting Preferences → Key Bindings. The pane on the right is your user key bindings file, and may simply look like this:
[
]
Position your cursor between the brackets and paste in the following:
{
"keys": ["ctrl+alt+super+a"],
"command": "chain",
"args":
{
"commands":
[
{
"command": "expand_selection",
"args": {"to": "smart"}
},
{
"command": "insert_snippet",
"args": {"contents": "\\as{${0:$SELECTION}}"},
}
]
},
"context":
[
{
"key": "selector",
"operator": "equal",
"operand": "text.tex",
"match_all": true
}
]
}
Here's how it works: The key combo CtrlAltSuperA (where Super is the Windows key) initiates two commands - expand_selection and insert_snippet.
You place your cursor between the two parentheses of your original text, and expand_selection expands the selection to include all of the text plus the opening and closing parens.
The second command wraps the selection - ${0:$SELECTION} - with \as{ at the beginning and } at the end. The "context" at the end only allows the command to run in TeX/LaTeX files. This can be removed if you'd like access to it everywhere.
If you want to change the key binding from CtrlAltSuperA to something else, just be sure that you're not overriding another keybinding. The FindKeyConflicts plugin is great for figuring that out.
Make sure you save the key bindings file when you're done. This shortcut will even work with multiple selections, so you can put multiple cursors in multiple places throughout your text, hit the key combo once, and they'll all be wrapped.
Using regular expression, you can do:
Ctrl+H
Find: (\(.+?\))
Replace: \\as{$1}
Replace all
Explanation:
( # start group 1
\( # opening parens, have to be escaped as it has special meaning in regex
.+? # 1 or more any character, not greedy
\) # closing parens
) # end group 1
Replacement:
\\ # backslash, have to be escaped
as{ # literally
$1 # content of group 1
} # literally
Screenshot (before):
Screenshot (after):
I have customized the vim-extension in vscode, and for most modes, it executes commands correctly. However If I try to write actuall characters (which are thus no longer commands), it won't. Why is that?
Example:
"vim.insertModeKeyBindingsNonRecursive": [
{
"before": [
"<leader>",
"o"
],
"after": [
"<Esc>",
"i",
"Abcd"
]
},
]
This should only write Abcd, because before that sequence is i, switching into insert mode. (So the <Esc> -> i, is redundant, it is here just as example). The vscode vim extension executes the <Esc> and also the i (becuase I know after that command I am back in insert mode), but will not print the Abcd. Why? Is the extension configured just to execute commands and not to actually print something? How to enable that?
It looks like you just need to split each character of the "Abcd" on to a separate line:
"vim.insertModeKeyBindingsNonRecursive": [
{
"before": [
"<leader>",
"o"
],
"after": [
"<Esc>",
"i",
"A",
"b",
"c",
"d"
]
},
]
As mentioned in the documentation of the project, you are supposed to pass a single key character (single character for normal key and multiple characters for special keys such as arrow keys or escape keys).
Updating after value will solve the issue:
"after": [
"<Esc>",
"i",
"A", "b", "c", "d"
]
You can take a look at the internals of the plugin to understand why it is not working with multiple characters passes in here, specifically NormalizeKey function, which would wrap any string with multiple characters with <>.
Sublime provides ability to:
select/edit all occurrences of a variable (Quick Find All; alt+F3 on Windows)
select each occurrence one-by-one and then edit the summed total (Quick Add Next; ctrl+d on Windows)
What I want:
select/edit all occurrences within a function's scope
note: I've read this related link (Sublime Text: Select all instances of a variable and edit variable name) and didn't see an answer to how editing might be restricted to function scope.
You can create a fairly simple plugin to do this, making use of Quick Find All, and then just removing any selections that are not inside the current function.
From the Tools menu -> Developer -> New Plugin...
Replace the contents of the new tab with the following:
import sublime
import sublime_plugin
class SelectWordInFunctionCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
prev_sel = [sel for sel in view.sel()]
function_region = next((region for region in view.find_by_selector('meta.function') if region.contains(view.sel()[0])), None)
if function_region:
#word = view.expand_by_class(view.sel()[0].begin(), sublime.CLASS_WORD_START + sublime.CLASS_WORD_END)
view.window().run_command('find_all_under')
sel = [sel for sel in view.sel() if function_region.contains(sel)]
view.sel().clear()
view.sel().add_all(sel if any(sel) else prev_sel)
else:
view.window().status_message('Not inside a function')
instead of using the find_all_under command, use select_word_in_function - you can create a keybinding to do this only when inside a function definition:
{ "keys": ["alt+f3"], "command": "select_word_in_function", "context":
[
{ "key": "selector", "operator": "equal", "operand": "meta.function", "match_all": true },
]
},
Disclaimer: this definitely works with PHP in ST build 3142 and other syntaxes that scope the whole function, but a different approach to detect where the function starts and ends may need to be used for other syntaxes that can't/don't behave this way.
Say I am editing this json
{
"a": {"language": "python"},
"b": {},
"c": {"language": "java"},
"d": {"encoding": "utf-16"}
}
My cursor is at b of "b": {}. I want to delete till the end of current {} block. So it'll look like,
{
"a": {"language": "python"},
"
}
Looks little odd. But explains what I want.
How can I do that in Vim?
You can use d]}.
From :help ]}:
*]}*
]} go to [count] next unmatched '}'.
|exclusive| motion.
The help also says that this is one of the motion's use case:
The above four commands can be used to go to the start or end of the current
code block. It is like doing "%" on the '(', ')', '{' or '}' at the other
end of the code block, but you can do this from anywhere in the code block.
for your example, d]] works too. It is easier to press.
However, ]} is better, since it works no matter which column the { or } sits on.
It's really easy to insert a closing brace after typing the opening one:
inoremap { {<CR>}<Esc>ko
This way
if (true) {
converts to
if (true) {
|
}
But I'd like to save time and to type 1 character less:
if (true)<CR>
So I'd like to create the following rule: if return is pressed and the line starts with if/for/while, execute {<CR>}<Esc>ko
Is this doable?
Thanks
Building on your previous mapping, this should do what you want:
inoremap )<CR> ) {<CR>}<Esc>ko
However, you should try a snippet expansion plugin like SnipMate or Ultisnips. Both plugins allow you to define snippets with placeholders and miroring (lots of them are included by default) that are expanded when a <Tab> is pressed after a trigger.
For example, you have a snippet associated with the trigger if that expands into:
if ([condition]) {
}
condition is selected, ready for you to type, and, once you are done, you can hit <Tab> again to jump the cursor between the curly braces, ready to type:
if (myVar == 5) {
|
}
This is incredibly handy.