sublime text 2 - add visual mode without vintage mode - sublimetext2

My problem is that I would like to be able to use a visual selection without being in vintage mode. Here are my key bindings:
[
{ "keys": ["ctrl+k"], "command": "move", "args": {"by": "lines", "forward": false} }
, { "keys": ["ctrl+j"], "command": "move", "args": {"by": "lines", "forward": true} }
, {"keys":["ctrl+h"], "command": "move", "args": {"by": "characters", "forward": false}}
, {"keys":["ctrl+l"], "command": "move", "args": {"by": "characters", "forward": true}}
, {"keys":["ctrl+e"], "command": "move", "args": {"by": "characters", "forward": true}}
,{ "keys": ["ctrl+e"], "command": "move_to", "args": {"to": "eol", "extend": false} }
,{ "keys": ["ctrl+a"], "command": "move_to", "args": {"to": "bol", "extend": false} }
, {"keys": ["ctrl+y"], "command": "copy"}
, {"keys": ["alt+y"], "command": "paste"}
, { "keys": ["ctrl+v"], "command": "enter_visual_mode"}
]
As you can see I have vi-like commands except with ctrl modifier. I want it this way. I would like ctrl+v to enter visual mode. I saw in the Vintage mode default key bindings file, the command was defined like I have it defined. Obviously "enter_visual_mode" is a command defined somewhere else in Vintage mode, but I don't know how to include that into my default editor. If anyone could give some guidance on setting this up it would be appreciated!

You will need to use a plugin to support the behavior you want. I don't know of one that is fully flushed out, but I know this was a start to define different keyboard modes (like visual). Take a look at https://github.com/KonTrax/MultiBind. Untested but add the following to your key binding file should work.
// Toggle "visual" layout
{ "keys": ["ctrl+v"],
"command": "multibind_toggle",
"args" : { "layout": "visual" }
},
// Show current layout in statusbar
{ "keys": ["ctrl+shift+\\"],
"command": "multibind_show",
"args" : { }
},
{ "keys": ["ctrl+k"], "command": "move", "args": {"by": "lines", "forward": false, "extend": true}, "context": [{ "key": "multibind.visual" }]},
{ "keys": ["ctrl+j"], "command": "move", "args": {"by": "lines", "forward": true, "extend": true}, "context": [{ "key": "multibind.visual" }] },
{"keys":["ctrl+h"], "command": "move", "args": {"by": "characters", "forward": false, "extend": true}, "context": [{ "key": "multibind.visual" }]},
{"keys":["ctrl+l"], "command": "move", "args": {"by": "characters", "forward": true, "extend": true}, "context": [{ "key": "multibind.visual" }]},
{"keys":["ctrl+e"], "command": "move", "args": {"by": "characters", "forward": true, "extend": true}, "context": [{ "key": "multibind.visual" }]},
{ "keys": ["ctrl+e"], "command": "move_to", "args": {"to": "eol", "extend": true}, "context": [{ "key": "multibind.visual" }]},
{ "keys": ["ctrl+a"], "command": "move_to", "args": {"to": "bol", "extend": true}, "context": [{ "key": "multibind.visual" }] }
You have ctrl+e defined twice, so I'm not sure which behavior you want.

Related

How to navigate in sublime through keypad keys?

Sublime 'alt+ numeric keys' work to switch between least 10 tabs opened
but same option doesn't work with keypad keys doesn't work.
does anybody have idea how to make it work?
thanks :)
Just add this to your User keybindings file:
{ "keys": ["alt+keypad1"], "command": "select_by_index", "args": { "index": 0 } },
{ "keys": ["alt+keypad2"], "command": "select_by_index", "args": { "index": 1 } },
{ "keys": ["alt+keypad3"], "command": "select_by_index", "args": { "index": 2 } },
{ "keys": ["alt+keypad4"], "command": "select_by_index", "args": { "index": 3 } },
{ "keys": ["alt+keypad5"], "command": "select_by_index", "args": { "index": 4 } },
{ "keys": ["alt+keypad6"], "command": "select_by_index", "args": { "index": 5 } },
{ "keys": ["alt+keypad7"], "command": "select_by_index", "args": { "index": 6 } },
{ "keys": ["alt+keypad8"], "command": "select_by_index", "args": { "index": 7 } },
{ "keys": ["alt+keypad9"], "command": "select_by_index", "args": { "index": 8 } },
{ "keys": ["alt+keypad0"], "command": "select_by_index", "args": { "index": 9 } },
open preferences keybinding and add this lines.
and now alt+keypad 0-9 keys work to swtich tabs
[{ "keys": ["alt+keypad1"], "command": "select_by_index", "args": { "index": 0 } },
{ "keys": ["alt+keypad2"], "command": "select_by_index", "args": { "index": 1 } },
{ "keys": ["alt+keypad3"], "command": "select_by_index", "args": { "index": 2 } },
{ "keys": ["alt+keypad4"], "command": "select_by_index", "args": { "index": 3 } },
{ "keys": ["alt+keypad5"], "command": "select_by_index", "args": { "index": 4 } },
{ "keys": ["alt+keypad6"], "command": "select_by_index", "args": { "index": 5 } },
{ "keys": ["alt+keypad7"], "command": "select_by_index", "args": { "index": 6 } },
{ "keys": ["alt+keypad8"], "command": "select_by_index", "args": { "index": 7 } },
{ "keys": ["alt+keypad9"], "command": "select_by_index", "args": { "index": 8 }}]

Navigate through camel case

I was working with Eclipse and I want that I can jump between words written in camel-case by pressing STRG. Now I'm working with Sublime and I can't find a shortcut to do so nor a plug-in, which achieves it.
The following example shows my problem
aFunctionName
In Eclipse it jumps from a to the F to the N of aFunctionName, when I press STRG + RIGHTARROW. In Sublime it skips the whole word. Is there a shortcut, a plug-in or can I set an entry into the config?
In Sublime Text, this functionality is bound to alt+right by default. In ST lingo it's referred to as "subwords" rather than having any reference to camelCase.
From the default keybindings:
{ "keys": ["alt+left"], "command": "move", "args": {"by": "subwords", "forward": false} },
{ "keys": ["alt+right"], "command": "move", "args": {"by": "subword_ends", "forward": true} },
{ "keys": ["alt+shift+left"], "command": "move", "args": {"by": "subwords", "forward": false, "extend": true} },
{ "keys": ["alt+shift+right"], "command": "move", "args": {"by": "subword_ends", "forward": true, "extend": true} },

Browse autocomplete results without arrows in Sublime

I'm using Sublime Text 3, and I am trying to not use arrows for anything. However I can't seem to scroll through different results of autocomplete or Ctrl+P without the arrows.
Any suggestions? Thanks!
You probably want something like this in your keymaps file:
// navigation with tab in autocomplete popup
{ "keys": ["tab"], "command": "move", "args": {"by": "lines", "forward": true}, "context": [{ "key": "auto_complete_visible" }] },
{ "keys": ["shift+tab"], "command": "move", "args": {"by": "lines", "forward": false}, "context": [{ "key": "auto_complete_visible" }] },
// navigation with tab in overlay
{ "keys": ["tab"], "command": "move", "args": {"by": "lines", "forward": true}, "context": [{ "key": "overlay_visible", "operator": "equal", "operand": true } ] },
{ "keys": ["shift+tab"], "command": "move", "args": {"by": "lines", "forward": false}, "context": [{ "key": "overlay_visible", "operator": "equal", "operand": true } ] },

Move tab from one column to another in Sublime Text using only keys

Does anyone know this shortcut? I'm looking for it online, but I can't seem to find it
To move it is CTRLSHIFT1 to move to Group 0, CTRLSHIFT2 to Group 1, and so on - that's on Linux, Windows, and OSX.
Text buffers can also be moved to their neighbouring groups:
Linux, Windows:
CTRLk + CTRLSHIFTLEFT
CTRLk + CTRLSHIFTRIGHT
OSX
SUPERk + SUPERSHIFTLEFT
SUPERk + SUPERSHIFTRIGHT
Here's the whole group section of my Default (Linux).sublime-keymap - the Windows keys are all exactly the same, while the OSX keys are the same in the top section but differ in the bottom section, below where I have placed an explanatory comment.
// The keys BELOW are for Linux, Windows, and OSX.
{ "keys": ["ctrl+1"], "command": "focus_group", "args": { "group": 0 } },
{ "keys": ["ctrl+2"], "command": "focus_group", "args": { "group": 1 } },
{ "keys": ["ctrl+3"], "command": "focus_group", "args": { "group": 2 } },
{ "keys": ["ctrl+4"], "command": "focus_group", "args": { "group": 3 } },
{ "keys": ["ctrl+5"], "command": "focus_group", "args": { "group": 4 } },
{ "keys": ["ctrl+6"], "command": "focus_group", "args": { "group": 5 } },
{ "keys": ["ctrl+7"], "command": "focus_group", "args": { "group": 6 } },
{ "keys": ["ctrl+8"], "command": "focus_group", "args": { "group": 7 } },
{ "keys": ["ctrl+9"], "command": "focus_group", "args": { "group": 8 } },
{ "keys": ["ctrl+shift+1"], "command": "move_to_group", "args": { "group": 0 } },
{ "keys": ["ctrl+shift+2"], "command": "move_to_group", "args": { "group": 1 } },
{ "keys": ["ctrl+shift+3"], "command": "move_to_group", "args": { "group": 2 } },
{ "keys": ["ctrl+shift+4"], "command": "move_to_group", "args": { "group": 3 } },
{ "keys": ["ctrl+shift+5"], "command": "move_to_group", "args": { "group": 4 } },
{ "keys": ["ctrl+shift+6"], "command": "move_to_group", "args": { "group": 5 } },
{ "keys": ["ctrl+shift+7"], "command": "move_to_group", "args": { "group": 6 } },
{ "keys": ["ctrl+shift+8"], "command": "move_to_group", "args": { "group": 7 } },
{ "keys": ["ctrl+shift+9"], "command": "move_to_group", "args": { "group": 8 } },
{ "keys": ["ctrl+0"], "command": "focus_side_bar" },
// The keys BELOW are for Linux and Windows only.
//
// The OSX keys all use 'super' instead of 'ctrl'.
//
// e.g. In the top command use: ["super+k", "super+up"]
// e.g. In the bottom command use: ["super+k", "super+shift+right"]
{ "keys": ["ctrl+k", "ctrl+up"], "command": "new_pane" },
{ "keys": ["ctrl+k", "ctrl+shift+up"], "command": "new_pane", "args": {"move": false} },
{ "keys": ["ctrl+k", "ctrl+down"], "command": "close_pane" },
{ "keys": ["ctrl+k", "ctrl+left"], "command": "focus_neighboring_group", "args": {"forward": false} },
{ "keys": ["ctrl+k", "ctrl+right"], "command": "focus_neighboring_group" },
{ "keys": ["ctrl+k", "ctrl+shift+left"], "command": "move_to_neighboring_group", "args": {"forward": false} },
{ "keys": ["ctrl+k", "ctrl+shift+right"], "command": "move_to_neighboring_group" },
Hope this helps.
If you mean rearranging the tabs within the same group, there's a good plugin called MoveTab
My keybindings Sublime Text --> Preferences --> Key Bindings (User) -->
{
"keys": ["super+alt+shift+["],
"command": "move_tab",
"args": { "position": "-1" }
},
{
"keys": ["super+alt+shift+]"],
"command": "move_tab",
"args": { "position": "+1" }
}
Allows CMD+Shift+Option+[ and CMD+Shift+Option+]
If you have Package Control you can install via CMD+Shift+P --> Install Package --> MoveTab
import sublime, sublime_plugin
class DualViewMoveTo(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command('set_layout', { "cols": [0.0, 0.5, 1.0], "rows": [0.0, 1.0], "cells": [[0, 0, 1, 1], [1, 0, 2, 1]] })
self.window.run_command('focus_group', { "group": 0 })
self.window.run_command('move_to_group', { "group": 1 })
There's an excellent plugin offered by Sublime Text itself called Origami, it allows you to create new panes(Columns), delete panes, move and clone views(Tabs) from pane to pane. You can easily shift tabs between a split view using this plugin. Also if you just reorder the tabs in a single pane then Sublime Text offers another good plugin called Move​Tab.

How does one bind commands to combinations of non-control key presses in Sublime?

Let's say, as an example, I want to expand the functionality of the arrow keys. When I press ctrl+z in combination with an arrow key it performs either a redo, undo, soft redo, or soft undo, depending on the direction of the arrow I press. I've prototyped this and it feels very intuitive (well, to be fair, I'm actually using vim-style hjkl navigation instead of arrow keys, but that's an aside):
[
{ "keys": ["ctrl+z+left"], "command": "undo"},
{ "keys": ["ctrl+z+right"], "command": "redo"}
]
The problem arises when I try to press ctrl+left/right, without the z. I should expect this to move the cursor left or right by one word, but instead it performs the undo/redo that I've just recently binded.
Now, I know full well I could do this instead:
[
{ "keys": ["ctrl+z","ctrl+left"], "command": "undo"},
{ "keys": ["ctrl+z","ctrl+right"], "command": "redo"}
]
But it just doesn't feel the same.
How can I bind ctrl+z+left/right without modifying the behavior of ctrl+left/right?
The solution I came to was to create my own plugin. The plugin tracks previous key commands and redirects to other commands based upon their values. Its available on package manager as "ContextualMove"
Here's the plugin in its simplest form:
import sublime, sublime_plugin, datetime
class ContextualMoveCommand(sublime_plugin.WindowCommand):
def run(self, context = None, direction = None, extend = False, timeout = 15):
if not hasattr(self, 'context'): self.context = context
if not hasattr(self, 'timeout'): self.timeout = timeout
if not hasattr(self, 'lasttime'): self.lasttime = datetime.datetime.now()
DIRECTION_COMMANDS = {
None:
{
'up': {'command': 'move', 'args':{'by': 'lines', 'forward': False, 'extend': extend}},
'down': {'command': 'move', 'args':{'by': 'lines', 'forward': True, 'extend': extend}},
'left': {'command': 'move', 'args':{'by': 'characters', 'forward': False, 'extend': extend}},
'right':{'command': 'move', 'args':{'by': 'characters', 'forward': True, 'extend': extend}}
},
'words':
{
'up': {"command": "move", "args": {'by': 'lines', 'forward': False, 'extend': extend} },
'down': {"command": "move", "args": {'by': 'lines', 'forward': True, 'extend': extend} },
'left': {'command': 'move', 'args':{'by': 'subwords', 'forward': False, 'extend': extend}},
'right':{'command': 'move', 'args':{'by': 'subword_ends', 'forward': True, 'extend': extend}}
},
'lines':
{
'up': {"command": "move", "args": {'by': 'pages', 'forward': False, 'extend': extend} },
'down': {"command": "move", "args": {'by': 'pages', 'forward': True, 'extend': extend} },
'left': {'command': 'move_to', "args": {"to": "bol", 'extend': extend}},
'right':{'command': 'move_to', "args": {"to": "eol", 'extend': extend}}
},
'scroll':
{
'up': {"command": "scroll_lines", "args": {"amount": 1.0 } },
'down': {"command": "scroll_lines", "args": {"amount": -1.0 } },
'left': {"command": "scroll_lines", "args": {"amount": 1.0 } },
'right':{"command": "scroll_lines", "args": {"amount": -1.0 } }
},
'history':
{
'up': {'command': 'undo', 'args':{}},
'down': {'command': 'redo', 'args':{}},
'left': {'command': 'soft_undo', 'args':{}},
'right':{'command': 'soft_redo', 'args':{}}
},
'indent':
{
'up': {'command': 'undo', 'args':{}},
'down': {'command': 'redo', 'args':{}},
'left': {'command': 'soft_undo', 'args':{}},
'right':{'command': 'soft_redo', 'args':{}}
},
'tabs':
{
'up': {'command': 'prev_view_in_stack', 'args':{}},
'down': {'command': 'next_view_in_stack', 'args':{}},
'left': {'command': 'prev_view', 'args':{}},
'right':{'command': 'next_view', 'args':{}}
},
'find':
{
'up': {'command': 'find_prev', 'args':{} },
'down': {'command': 'find_next', 'args':{} },
'left': {'command': 'find_prev', 'args':{} },
'right':{'command': 'find_next', 'args':{} }
}
}
CONTEXT_COMMANDS = {
'find': {"command": "show_panel", "args": {"panel": "find", "reverse": False} }
}
if not direction:
if self.context == context:
self.context = None
else:
self.context = context
if self.context in CONTEXT_COMMANDS:
command = CONTEXT_COMMANDS[self.context]
self.window.run_command(command['command'], command['args'])
return
# time = datetime.datetime.now()
# if (time - self.lasttime).seconds > self.timeout:
# self.lasttime = time
# self.context = None
if self.context not in DIRECTION_COMMANDS:
return
context_commands = DIRECTION_COMMANDS[self.context]
if direction not in context_commands:
return
command = context_commands[direction]
self.window.run_command(command['command'], command['args'])
And here's the edits I made to key bindings:
{ "keys": ["ctrl+u"], "command": "contextual_move", "args": {"context": "history"} },
{ "keys": ["ctrl+space"], "command": "contextual_move", "args": {"context": "words"} },
{ "keys": ["ctrl+enter"], "command": "contextual_move", "args": {"context": "lines"} },
{ "keys": ["ctrl+tab"], "command": "contextual_move", "args": {"context": "tabs"} },
{ "keys": ["ctrl+f"], "command": "contextual_move", "args": {"context": "find"} },
{ "keys": ["ctrl+i"], "command": "contextual_move", "args": {"direction": "up"} },
{ "keys": ["ctrl+k"], "command": "contextual_move", "args": {"direction": "down"} },
{ "keys": ["ctrl+j"], "command": "contextual_move", "args": {"direction": "left"} },
{ "keys": ["ctrl+l"], "command": "contextual_move", "args": {"direction": "right"} },
{ "keys": ["ctrl+shift+i"], "command": "contextual_move", "args": {"direction": "up", "extend": true} },
{ "keys": ["ctrl+shift+k"], "command": "contextual_move", "args": {"direction": "down", "extend": true} },
{ "keys": ["ctrl+shift+j"], "command": "contextual_move", "args": {"direction": "left", "extend": true} },
{ "keys": ["ctrl+shift+l"], "command": "contextual_move", "args": {"direction": "right", "extend": true} },