Sublime Text 2 - Drop Cursor From Multiple Line Selection - sublimetext2

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.

Related

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

Pin search bar to Sublime Text 2

Is it possible to pin the search bar/search&replace bar (Ctrl+F or Ctrl+H) to the window. Because now, if I press Esc, my search bar disappears.
For example when having search bar + multi-line cursors active and when I want to deactivate multi-line cursors using my keyboard (I know a mouse click deactivates multi-line cursors too), I click on Esc. But Esc deactivates both (search bar + multi-line cursors)
I hope you understand what I mean.
Edit:
There is one thing that I'm asking myself a lot of times. I can make the search bar active by doing Ctrl + F, but after I search I want to go back to edit my file (I want to go out of my search bar and go to the place where I found what I searched) This is again possible with mouse click but i want to do it with my keyboard. (something like tab out of the search field). Anyone who knows there is a key binding for this?
--> I found I can use Alt+Enter for this but it selects all occurences. to disable the selections I just move with my arrow keys...
If you're using ST2 you can just edit/remove default key binding (as I remember) for this:
{ "keys": ["escape"], "command": "hide_panel", "args": {"cancel": true},
"context":
[
{ "key": "panel_visible", "operator": "equal", "operand": true }
]
},
ST3 doesn't allow you to edit default bindings so I was able only to reorder Esc button behavior when panel is visible: first press deactivates multi-line cursors, and the second press hides a search panel. If no multi-line cursors active then Esc only hides a search panel.
Try to add these lines to the User's key bindings file:
{ "keys": ["escape"], "command": "single_selection", "context":
[
{ "key": "num_selections", "operator": "not_equal", "operand": 1 }
]
},
Hope this will help.
EDIT: Fixed lines to add

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.

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