Live data from Hacker News

Handy text manipulation tricks in Sublime Text 2

whiletruecode.com

91–99 of 99 posts

Re: Handy text manipulation tricks in Sublime Text 2

#91

Not a complete list, but some Emacs equivalents: M-^ delete-indentation (or join-line) C-x C-t transpose-lines kill-line M-0 C-k kill to beginning of line djcb-duplicate-line (not built-in) M-q fill-paragraph C-c c comment-uncomment M-c capitalize-word... org-move-line-up C-u M-| sort

M-^ is one of my favorite commands in emacs. I use both sublime and emacs on a daily basis (Sublime has better support for the languages I use at work), and it's a constant source of frustration that C-j in Sublime text joins the line below with the current line, whereas M-^ joins the line above.

I guess that's what I get for not using one editor for everything :p

Re: Handy text manipulation tricks in Sublime Text 2

#92

Earlier quoted context omitted.

Does it allow you to have multiple projects open at the same time yet? That was what prevented me from using it earlier.

Yes: http://www.jetbrains.com/idea/webhelp/opening-multiple-proje...

Sorry, I should have been more clear. I meant multiple projects in the same workspace, like what netbeans or eclipse has (or even Sublime).

I really like being able to navigate in all my open projects at the same time. Not having it is a no-go for me.

Re: Handy text manipulation tricks in Sublime Text 2

#93
post #90
post #89

Earlier quoted context omitted.

Actually, this is a perfect example of using Multiple Cursors to get the job done more easily. I'd select all three "def"s simultaneously, then move by word three/four times using ctrl+right, or plain old "w" if using ST's vim mode. When I'm on the second param, I'll delete forward to the next ",". I could also just ctrl+right my way until the next word, which would be the same. Just to recap the keys I'd press: /def…

How do you make multiple cursors that are at the exact locations you need? That's something that a macro is useful for. His macro is less useful because for some reason he did his search outside of the macro. Maybe the search is not for "def", but for "def prefix", so ctrl+d is not applicable to form the multiple cursors. It could be nice if you could record your movements to form the "next" cursor and immediately se…

"How do you make multiple cursors that are at the exact locations you need?"

There are a few simple tricks.

In this case, I hit "ctrl-d", which does the following:

1. If nothing is selected, it will select the word the cursor is on.

2. If something is selected, it will select the next match of this word, using another cursor.

In other words, I'll put my cursor on "def", hit ctrl-d, and "def" will be selected. Hit ctrl-d again, and the next "def" will be selected. Etc. Technically, in Sublime Text, every search makes a multiple cursor. I could hit alt-f3 (IIRC) to select all matches of "def", and they'd all be multi-selected.

But like I said, in this case it's really easy.

There are more advanced tricks - what if the word "def" appears inside the text? Well, you can select not only the def, but also the whitespace before the def, and it will selected the next "def" which is at that exact indentation. And like I mentioned in another comment, I even wrote a plugin to make multi-selections more easily, by splitting on a certain character. So that a list like this: (int a, int b, char c) can easily be split into 3 selections, around the comma.

Re: Handy text manipulation tricks in Sublime Text 2

#94
post #93
post #90

Earlier quoted context omitted.

How do you make multiple cursors that are at the exact locations you need? That's something that a macro is useful for. His macro is less useful because for some reason he did his search outside of the macro. Maybe the search is not for "def", but for "def prefix", so ctrl+d is not applicable to form the multiple cursors. It could be nice if you could record your movements to form the "next" cursor and immediately se…

"How do you make multiple cursors that are at the exact locations you need?" There are a few simple tricks. In this case, I hit "ctrl-d", which does the following: 1. If nothing is selected, it will select the word the cursor is on. 2. If something is selected, it will select the next match of this word, using another cursor. In other words, I'll put my cursor on "def", hit ctrl-d, and "def" will be selected. Hit ctr…

Sounds great, hopefully someone ported this to emacs :-)

Re: Handy text manipulation tricks in Sublime Text 2

#95

Earlier quoted context omitted.

He's providing these as commands to show that Vim can handle the same features as Sublime Text, but he's doing it in a non-Vim way, as far as I'm concerned. I'm all ears. What would be the Vim way?

As I said, learning the basic commands and using them. There's no need to remember a key combo for 'swap lines' because it's just 2 basic commands used in succession. I never even think of it as 'swap lines' because what I want to do is remove a line, then place it somewhere else. And that's what the commands are in Vim to make it happen.

That's how I constructed the above list in the first place, but I get what you mean; you shouldn't be learning these as Street Fighter-like combos.

Re: Handy text manipulation tricks in Sublime Text 2

#96
post #6

For whatever it’s worth, all of these are copied directly from TextMate. :-)

While I did try to be compatible with TextMate key bindings where possible, I believe only a handful of the key bindings mentioned in the article are actually common between the two.

Most of them are identical. The capitalization and line joining shortcuts are slightly different.

Re: Handy text manipulation tricks in Sublime Text 2

#97
post #89
post #86

Earlier quoted context omitted.

Sample def qux(bar, baz, qux) pass def quuux(grim, gram, grom) pass def quuuuuux(hip, hop, zoom) pass Delete second argument (of 3+ arg functions): /def # search qd # record as 'd' 2f,dF,n # find second arg q # done recording @d # again (or n to skip) Example intentionally simplified/convoluted. I'm doing stuff like this on the spot routinely, and there's no way multiple cursors could do this because I apply verbs to…

Actually, this is a perfect example of using Multiple Cursors to get the job done more easily. I'd select all three "def"s simultaneously, then move by word three/four times using ctrl+right, or plain old "w" if using ST's vim mode. When I'm on the second param, I'll delete forward to the next ",". I could also just ctrl+right my way until the next word, which would be the same. Just to recap the keys I'd press: /def…

> When I'm on the second param, I'll delete forward to the next ","

you can't do that, else you'll delete not enough ('gra') or too much ('baz,')

> ctrl+shift+right

It fails the moment one of the second arguments has a space or a dash. e.g default value:

    def qux(bar, baz = {}, qux)
or in some languages (CSS, HTML, LISP)

    
The interesting reason is why it fails: you say you want to delete 'to the next ","' but do word movement with w or ctrl+arrows. Indeed this is solved by Vintage mode, but I unfortunately found it too inconsistent with vim, and lacking a few critical features (e.g vim-surround and indent-object) for me.

Also, multiple cursors rock anyway, but if I want to apply them to a number of elements responding to a criteria and decide on a case by case basis if I want to apply then it does not work. Also it does not work when there's no code locality (i.e affected code is not visible in the same view, or spread around multiple files). The major difference with macros is that they're repeatable, while multiple cursors do the same thing at once, and once.

Also, when one vim user uses f/t too often, one should look into an object describing what he wants to really do (here [0]).

[0] http://www.vim.org/scripts/script.php?script_id=2699

I hope Sublime Text has or introduces at some point the same extendable concept of text objects as in vim.

Don't get me wrong, I'm not saying anything of this is bad per se, just that there's room for improvement.

Re: Handy text manipulation tricks in Sublime Text 2

#98
post #93
post #90

Earlier quoted context omitted.

How do you make multiple cursors that are at the exact locations you need? That's something that a macro is useful for. His macro is less useful because for some reason he did his search outside of the macro. Maybe the search is not for "def", but for "def prefix", so ctrl+d is not applicable to form the multiple cursors. It could be nice if you could record your movements to form the "next" cursor and immediately se…

"How do you make multiple cursors that are at the exact locations you need?" There are a few simple tricks. In this case, I hit "ctrl-d", which does the following: 1. If nothing is selected, it will select the word the cursor is on. 2. If something is selected, it will select the next match of this word, using another cursor. In other words, I'll put my cursor on "def", hit ctrl-d, and "def" will be selected. Hit ctr…

Now that's the kind of thing I wish I would see in a "ST tricks" blog post.

Re: Handy text manipulation tricks in Sublime Text 2

#99
post #35

Any article that talks about tricks in Sublime Text 2 without mentioning Multiple Cursors is... lacking (no offense to the OP). For anyone that doesn't know it, Multiple Cursors is the ONE BRILLIANT FEATURE that Sublime Text has. Don't get me wrong, tt's great in many other ways too, but Multiple Cursors is, IMO, a feature that should become part of every friggin' text editor in existence, it's that important. And it…

I guess you are aware Sublime Text 2 has a Vim mode. As someone who's gone "far in Vim's world", how do you think this compares to regular Vim? I'm starting to learn Vim commands in ST2 but I don't know if "proper" Vim is required to get fully into Vim.

I think it's one of the best vim-emulations I've seen so far. It's not 100% but it has things like text-objects (cit, etc.), named buffers and bookmarks (which most of the other emulations miss).
Post reply on HN