Quick add previous in sublime text 2 - sublimetext2

Is there a quick add previous in sublime text 2 like the quick add next(ctrl+d)?
Relevant lines in keymap
{ "keys": ["ctrl+d"], "command": "find_under_expand" },
{ "keys": ["ctrl+k", "ctrl+d"], "command": "find_under_expand_skip" },
I tried changing that find_under_expand to find_over_expand but it doesn't work.

You can use ShiftF3 to move the selection to the previous occurrence, and once you've reached the start of where you want to make multiple selections you can use CtrlD and CtrlK,CtrlD, but to my knowledge there is no way to make multiple selections in reverse without writing a specialized plugin.

Related

Sublime Text 3 insert tab character manually

When using Sublime Text 3, most of my files are set to be indented using spaces. However I sometimes wish to insert a literal tab. When I was using Vim I'd use Ctrl+v Tab but that doesn't work with Sublime Text 3.
I've been searching and searching and cannot find anything. Please help!
There is a default key binding of Shift+Tab to insert a raw tab character into the document, although in certain contextual cases (such as when expanding a snippet) it takes on other functions instead.
However, Indent Using Spaces is controlled by the following setting:
// Set to true to insert spaces when tab is pressed
"translate_tabs_to_spaces": false,
As seen here it defaults to false, but when you have Indent using spaces turned on, it's set to true. As the comment alludes to, when this setting is set to true any attempt to insert a raw tab character gets converted to some number of spaces instead.
As a result, even the official key binding does not insert a raw tab in this case.
Depending on how often you care to insert a literal tab you can work around this by temporarily turning that setting on and off, but this is far from ideal, even when the setting is toggled from the menu in the status bar.
Since Sublime is so customizable, we can automate it into doing that work for us.
To start with, create a file with the following contents and save it in your User package as literal_tab.sublime-macro (use Preferences > Browse Packages... to find your User package if you're not sure where it is):
[
{ "command": "toggle_setting", "args": { "setting": "translate_tabs_to_spaces" } },
{ "command": "insert", "args": { "characters": "\t" } },
{ "command": "toggle_setting", "args": { "setting": "translate_tabs_to_spaces" } }
]
Then, add the following two key bindings to your user bindings (Preferences > Key Bindings in the menu; if there are multiple options, choose User and not Default):
{
"keys": ["ctrl+k","tab"],
"command": "insert",
"args": {
"characters": "\t"
},
"context":
[
{ "key": "setting.translate_tabs_to_spaces", "operator": "equal", "operand": false }
]
},
{
"keys": ["ctrl+k","tab"],
"command": "run_macro_file",
"args": {
"file": "Packages/User/literal_tab.sublime-macro"
},
"context":
[
{ "key": "setting.translate_tabs_to_spaces", "operator": "equal", "operand": true }
]
}
Both bindings include a context that causes it to trigger or not based on the value of the translate_tabs_to_spaces setting, so at any given time only one of them is actually in effect and the other one is automatically disabled.
The first binding is for the case when the setting is turned off, in which case it just needs to insert a tab character and it's done. The second case instead runs our custom macro from above, which turns the setting off, inserts the tab, and then turns the setting on again.
In theory you really only need the second one if you always leave the indent setting turned on, but due to the Principle of Least Surprise it's a good idea to set it up to work regardless of the setting.
Naturally you can use any key stroke that you want (I'm also used to this one from vim), and the name of the macro file doesn't matter as long as it has the correct extension and it matches what the binding tries to execute.
Note: Although you mentioned Sublime Text 3 in your question, you tagged Sublime Text 2 as well, so for completeness I'll also note that the information and solution presented here applies to both versions equally.

Sublime Text 2 - Drop Cursor From Multiple Line Selection

I've been using ST2 for a while now and am curious if there is a way to select multiple lines and drop the top or bottom selection.
For instance, if we selected four of them and then, drop the top cursor, I'd only have three selections. This would be very helpful when I'm doing multi-line edits with slightly different data.
You can open the ST console ctrl+` and write del view.sel()[0] to delete the first and del view.sel()[-1] to delete the last selection. You can obviously adapt the number to delete an other selection.
An alternative is to install MultiEditUtils with "selection fields", which is written to slightly modify single selections while working with multiple selections. Add the keybindings:
// default use of selection_fields
{ "keys": ["alt+d"], "command": "selection_fields" },
// add the current selections as a fields
{ "keys": ["alt+a"], "command": "selection_fields", "args": {"mode": "add"} },
// jump and remove current selection in selection_fields
{ "keys": ["ctrl+alt+d"], "command": "selection_fields",
"args": {"mode": "smart", "only_other": true} },
// cancel selection_fields and remove current selection
{ "keys": ["ctrl+alt+shift+d"], "command": "selection_fields",
"args": {"mode": "toggle", "only_other": true} },
Afterwards you can press alt+d to change the selections to "fields". Now move with tab or shift+tab to the selection you want to remove. Press ctrl+alt+d to remove the selection and jump to the next field. Press ctrl+alt+shift+d to remove the selection and convert all other fields to selections. Press escape to convert all fields to selections.
This is possible using subtractive drag select. On Windows and Linux, hold down Alt (on OS X, hold down ⌘Alt) while holding down mouse button 1 (typically the left mouse button, for right-handed users) and dragging across the cursor, either from left to right or right to left - the drag needs to start in the editing area, though, not the gutter to the left of the text where the line numbers are. Subtractive select also works when selecting words, lines, or columns - just hold down Alt or ⌘Alt while double- or triple-clicking, or selecting columns.
For a full list of available mouse combinations, go to your Packages folder, the one opened when selecting Preferences → Browse Packages…, go to the Default folder, and open Default (YourOSHere).sublime-mousemap (YourOSHere being one of Windows, Linux, or OSX) with JSON syntax highlighting. If you're using Sublime Text 3 (which I very strongly recommend upgrading to), you'll need to install PackageResourceViewer, as the files in Default are now in a .sublime-package archive. Once installed, select PackageResourceViewer: Open Resource, scroll down to Default, then select the .sublime-mousemap file that corresponds to your operating system.

How to word wrap in sublime text's console?

I mean sublime text 2.I wanna achieve something like line 4. Just make console show the same.
Any help will be appreciated.
Turn (View -> Word Wrap) ON and restart the application. If its already on then turn it off and do the same.
Set up the Key Binding for word wrap toggling.
Go to Preferences -> Key Bindings, add the togging command to whatever key combination you want:
[
//...
{ "keys": ["alt+z"], "command": "toggle_setting", "args": {"setting": "word_wrap"}}
]

Vintage mode: moving farthest left or right within a wrapped line

I am in the process of switching to Vintage mode, and I would like to turn off my arrow keys. However, what's stopping me is not knowing how to move farthest left or right within a wrapped line. For example, within a markdown file paragraph.
I achieve this with command + arrow left or arrow right, depending on where I need the cursor. What's the equivalent of this in vintage mode?
Just to be explicitly clear, I am not trying to get to the beginning or end of the entire line, I am trying to move the cursor to the beginning or end of the wrapped it is currently sitting in.
Edit
Adding an image to illustrate what I am trying to do. The arrows indicate where I would want the cursor to jump to with the proper left or right keyboard shortcut.
Go to you Key Binding - User
Add following key bindings
,{ "keys": ["super+0"], "command": "move_to", "args": {"to": "eol", "extend": false} }
,{ "keys": ["super+1"], "command": "move_to", "args": {"to": "bol", "extend": false} }
Save and you can use command+0 / command+1 to go to end/start of the line.
While in command mode, 0 for beginning of line and $ for end of line.

How do you cycle through multiple cursors in Sublime Text like you would with placeholders?

Is there a way to tab through multiple cursors like you can with placeholders?
Having those cursors placed you would:
type "index"
tab
type "products"
tab
…
You could create bookmarks with the multiple cursors (ctrl+f2 or cmd+f2 by default I think). Then, you could return to a single cursor (escape). After you enter the content on a particular line, you could then move to the next bookmark (f2 by default). Of course, those are with the default keybindings. You can always rebind them to something more comfortable than f2.
There is a plugin for that and more. https://packagecontrol.io/packages/MultiEditUtils
You can add this line to your User Keybindings for custom hotkey:
{ "keys": ["alt+d"], "command": "selection_fields" },