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

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" },

Related

How to add auto-complete Sublime Text 3

I would like to add custom auto-complete key bindings much like built-in:
Example: html+tab auto-completes the Doctype Block.
I tried adding html custom key binding: type c + o + l + tab to generate <div class="col-">
Preferences > Key Bindings > Default (OSX).sublime-keymap -- User
{"keys": ["c+o+l+tab"], "command": "insert_snippet", "args": {"contents": "<div class=\"col-$0\">"}},
However, two issues:
the new key binding overrides all other auto completes
the initial col or characters remains in front of the
generated tag. col<div class="col-">
What is the correct way to add this type of key binding?
The correct way to do something like this is to use either snippets or completions. Although there are some differences, generally speaking they both work the same way in the end, and which one you choose depends on how many such items you want to create and how complex you want them to be.
Using a snippet, you would select Tools > Developer > New Snippet... from the menu and fill out the snippet template, then save it as a sublime-snippet file in the location that Sublime defaults to (which is your User package).
For example, that might look like the following based on the example in your question:
<snippet>
<content><![CDATA[
<div class="col-$0">
]]></content>
<description>Insert DIV with column class</description>
<tabTrigger>col</tabTrigger>
<scope>text.html</scope>
</snippet>
Snippets are XML formatted, and everything between ![CDATA[ and ]] is inserted into the buffer (don't remove the CDATA even if you think you don't need it; Sublime will ignore the snippet if you do).
The tabTrigger specifies the text that you want to be the trigger for the snippet, the scope says what sort of files the snippet should trigger in, and the description will be displayed next to the snippet in the auto-completions panel.
In a snippet, the tabTrigger, scope and description are all optional. If you don't specify a tabTrigger you can only expand the snippet from the Command Palette or via the insert_snippet command (for example in a key binding). Without a scope the snippet applies everywhere, and without description it has no description in the panel.
If you have many such items that you want to add snippets for, you can also use completions instead. These are stored in JSON files with an extension of sublime-completions and should be saved in your User package (use Preferences > Browse Packages... if you don't know where that is.
An example of such a file would be:
{
"scope": "text.html",
"completions": [
{ "trigger": "col\tInsert DIV with column class", "contents": "<div class=\"col-$0\">" },
]
}
In this format, the trigger is always the text to trigger and the description (still optional) is separated from the trigger by a \t character in the trigger key.
In completions you only specify the scope once at the top instead of every time, but there are some functional differences between completions and snippets.
There can only be one snippet per sublime-snippet file, but a sublime-completions file can contain many completions in a single file; the completions key is an array so you can place more than one completion in the same file.
Completions are JSON, so contents that are multi line or contain JSON specific characters such as a " character are harder to enter; completions are better for shorter sequences while snippets are better for more complex things.
When autocomplete triggers, if there is a completion and a snippet that could be autocompleted, snipptets always "win" and are inserted, whereas completions cycle. That means that for example in this particular example you need to press Tab twice because col is also the name of a tag.
Snippets automatically appear in the command palette (when they apply) but completions do not. In the command palette, Snippets appear as commands like Snippet: Something, where Something is the description if it exists and the name of the file if it does not.
In either case, you can make the snippet/completion apply only in certain types of files by applying a scope; to determine the appropriate scope, position the cursor in a file at the appropriate place and select Tools > Developer > Show Scope Name...; the more of the displayed scope you use the more specific it becomes. Generally just the top level such as text.html is all that's needed unless you're doing something special.

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"}}
]

multi-line selection in sublime text 2

I want to select the text in all the alt tag and type in some identical text. I could be using the wrong key combinations. I've tried several combinations:
alt+left-click hold and drag the mouse,
ctrl+left-click hold and drag the mouse,
ctrl+alt+left-click hold and drag the mouse,
ctrl+alt+shift+left-click hold and drag the mouse,
ctrl+shift+L+left-click drag the mouse,
as well as swapping to "right-click+" with those combinations and here is the result:
That is not what I want.
The following is what I want to select:
In Sublime Text 2 using the MAC, you can hold down the option key and drag to make the selection. So usually in Windows, that means holding down the alt key. Holding down the alt key does not work. I checked out the key bindings in Sublime Text 2:
{ "keys": ["ctrl+alt+up"], "command": "select_lines", "args": {"forward": false} },
{ "keys": ["ctrl+alt+down"], "command": "select_lines", "args": {"forward": true} },
If the up key is the arrow up key, this doesn't work either. I've also tried ctrl+shift+L without success.
Thanks.
Try Middle Click + Drag or Shift + Right Click + Drag
Ok, I just kept trying and I stumbled upon the answer. I was going to delete the question since it was soon after I posted that I got it, but thought I would post for anyone who may have the same issue and have tried everything else others have posted.
Answer:
Left-click to place your cursor in the area you want to make a
multi-line selection, release left-click
After that selection, hold down the ctrl key
Left-click in the area you want to select in the line below (in my case it was the alt tag text)
Keep holding down the ctrl key, left-click each area
individually -- do not drag the mouse while holding ctrl key. Dragging selects everything from the starting point, not the individual area you want

Quick add previous in sublime text 2

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.