Windows users, change all 'Alt' to 'Ctrl' in this article and you guys should be alright.
[Edit]Didn't realize the author was around.
Author, 'Alt' is the wrong key for Windows. You should probably change them to 'Ctrl' instead
Further to point F: if you hold down control, you move by word segment - this is camel-case (and underscore) aware. So, if I am at the front of the word "cakeParty", I can move to between 'e' and 'P' by holding control and pressing the right arrow key.
(This is in ST2 for Mac OS X - I'm sure there's an equivalent feature in ST2 for other systems.)
The command and alt modifiers work when I use the arrow key but this ctrl doesn't seem to do anything... OS X lion. For example, I put the caret in front of a camelCased variable and press ctrl+right arrow, nothing happens. Am I doing it wrong?
I curse myself whenever I think about it. For the longest time, I didn't know about this shortcut. I missed it terribly, but I was too thick to understand that I can search through the manuals or internet to find if such a shortcut exists... I used it a hundred times daily (Java, Eclipse), but the need for it is much greater in CoffeeScript+Node.js
Ctrl+Shift+D duplicates the current line by default (or the current selection, if any).
Ctrl+Shift+K deletes the whole line.
Ctrl+K twice deletes to end-of-line.
Ctrl+K Ctrl+backspace deletes to beginning-of-line.
Combine duplicate, move up/down, and the Ctrl+D multi-cursor stuff, and you have a copy-and-paste coder’s dream editor. ;-)
Something else you might not know -- multiple selection via command clicking (also implemented in Excel, for example) was in the original (1985ish) Apple Humn Interface Guidelines.
Now that I think about it, it's such a common feature everywhere except text editing (I'm mainly thinking of selecting/highlighting things like icons and menu items) it's interesting that it has taken so long to be an editor's big selling point.
Installation is through the Sublime Text 2 console. This is
accessed via the ctrl+` shortcut. Once open, paste the following command
into the console:
import urllib2,os; pf='Package
Control.sublime-package'; ipp=sublime.installed_packages_path();
os.makedirs(ipp) if not os.path.exists(ipp) else None;
urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler()));
open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbon
d.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime
Text to finish installation'
Are you kidding me? The product or package maintainer should handle this better.
Um, this is product for developers. I think that they should be able to handle a pretty simple copy/paste. Not sure the reason behind the drama queenery.
It needed to be said, and the style was intentional. Statements like the one you made sound right and are easy for readers to accept as fact. My comment was intended to make people go back and reevaluate yours. I think it was accurate, effective rhetoric. It wasn't intended as a judgment of your worth; just as a judgment of that particular comment's worth.
Hey, we're programmers here. When the entire install command fits in one line of Python, and I can read it, I freaking love seeing the entire thing and running it in the interpreter myself. I have -1 problems with this.
Plus it's easy as pie, and as anyone who's actually used Package Control knows, it would be worth it if you had to pluck a hair from an Argentinian llama and place it in your USB port while reciting the gregorian chant from Monty Python and the Holy Grail to install it. One line of actual Python is simply a convenient shortcut.
Who cares if it is "professional" or not? It works, and you do it once after you install the editor and never do it again. Oh yeah, and it was created for free by someone not associated with the product and is awesome.
I'm right there with you, I agree completely. Not to get pedantic but when I read "who cares if it's professional or not" I kind of cringed. I mean, professionalism is important no matter what. And I think professionalism is the wrong word to describe this. I think what we're talking about here is more a matter of doing things "the right way" which isn't always the same as professional. So I can definitely see the argument for wanting it done the right way but at the same time there's no reason to go on a crusade for everything to be done perfectly. Sometimes just being done reasonably and working is enough. In this case just working certainly is enough. It's reasonable to give this one a pass on "professionalism".
> Are you kidding me? The product or package maintainer should handle this better.
Man, you got that right. They should make it so that it can be installed through Package Control.
Oh, wait...
For a bootstrapping method, this seems completely reasonable. It doesn't involve downloading inscrutable single-platform installers, or opening a shell window, or any other external dependencies. The whole process runs inside the one environment you're guaranteed to have: Sublime Text itself.
Your reaction is understandable but wrong. It's a ugly, horrific block of code that you copy/paste and never think of or see again. The package manager itself makes the installation and management of 3rd party packages incredibly easy. It's super impressive really.
Naturally people ask if the 3rd package manager will become an official feature but that opens up a new can of worms.
Agreed. It doesn't go with the rest of ST2 ease of use. I was shocked that people think this is whining, but then remembered that programmers are used to putting up with the obviously-less-than-ideal:
"Computer people generally design terrible computer interfaces because they are not only willing to cope with something bad, they're pleased to."
- Alan kay, Personal Computing Historic Beginnings
I haven't had a chance to checkout Sublime Text 2, but that sample prompted me to download it after finding out it has a console that will accept python as a way to install packages.
Yep. Basically, Textmate's Goto Anything feature is activated by cmd+t, so ST's author mapped both cmd+t and cmd+p to Goto Anything on OS X to accommodate people switching over. On OS X, Goto Symbol is actually cmd+r.
Another one i've found useful is CMD+D / CMD+K+D. CMD+D finds the next instance of the current selection and creates another cursor there (and selects it as well). CMD+K+D skips the current selection and finds the next one.
Subsequent Cmd + d presses will select the following instance of the word for editing. Makes it easy to do things such as renaming a local variable or changing both the opening and closing element of a HTML tag.
What's really wild is if you do CMD+d several times and then move around with the arrow keys. Multiple cursors follow you around. I'm not sure if this is useful, but it's certainly cool.
To me, supporting multiple cursors is one of ST2’s killer features.
For one thing, it goes a surprisingly long way to making up for not having language-sensitive refactoring tools if you’re renaming things, changing parameter lists, etc.
Also, you can make a selection in advance rather than relying on the default of selecting the current word. That selection can even span line breaks and/or include indentation. If you then select some/all instances of the same text as starting points using Ctrl+D, you can change not only the copies of the text but also (for example) extend the selections to include whatever is immediately before or afterwards (even if that is different in each case) or move to the start or end of each line. It’s a quick way to do a lot of common search-and-replace type operations without getting bogged down in regexes or macros.
A related useful technique is using (on Windows) Ctrl+Alt+up/down, which moves up/down a line creating multiple cursors as you go. If you then do Shift+left/right, you can get a “column selection” effect, for example. (You can also drag with the middle mouse button to select a column.)
I hope ST2 will build on these basic features as time goes on. It could allow incremental forward/backward search without cancelling the multiple cursors, let you cycle around which cursor is shown or will be left when you hit escape to cancel multiple mode, maybe even temporarily split the display to show multiple cursors at once if they are far apart. There’s a huge amount of potential here.
Way useful. You can, for example, select all instances of a variable name, then rename it selectively from the middle of the selection if you want.
Also good to note: Command-F find also has a "Find All" option which can be faster than pressing Command-D multiple times, and also allows more complex non-word and regexp searches. From there you can use multiple cursors or replace the whole selection just by typing.
One minor complaint: I wish cmd+D had a "whole words only" setting. Its confusing when using with the "highlight all matches" feature, which is "whole words only" IIRC.
Also notable is that you can skip the currently selected element (i.e. unselect it) if you press ctrl+k+d. Sublime will then continue to select the next word, but leaves the one you just selected unselected.
ctrl+k+d was added recently and was quite a big improvement
but it's still hard to use because if you do one wrong cmd+d you'll have to either start again or use the mouse.
the way cloud9 ace[1] handles this is better, since it keeps last added selection as active one and from there you can add selections with ctrl+alt arrows or remove with ctrl+alt+shift arrows
If you press ctrl+d one time too many, you can use Soft Undo (ctrl+u / command+u) to step backwards. Soft Undo undoes selection commands as well as modifying commands, as opposed to regular undo, which undoes modifying commands only.
another fast way to select all instances of a word/phrase for editing is to find in file (cmd+f) type out your variable/whatever and then option+enter will find all instances of your search text and highlight each for editing via their own cursor
Is it possible to do multi-line editing like Sublime Text but in Vim? I use both, and this was the feature that got me out of Terminal, but besides this I can't think of anything else offhand for what ST2 can do that Vim can't do.
Yes, Ctrl-v to enter visual-block mode, then move up or down to cover all lines where you want to make changes, then I{string}Esc to append a string at the cursor location on all lines.
I'm not sure exactly what you're looking for without knowing more what you mean by multi-line editing, but you can apply arbitrary commands (including inserts) to any set of lines.
Switches case on lines 4, 15:
:4,15 norm ~
Indents text and changes the first two words of ever line to "duck" from mark a to the end of the file
:'a,$ norm >>2cwduck
Prepends a # to every line of the visual selection
You can also get multiple cursors from the keyboard with ctrl+alt+(uparrow or downarrow) not the most convenient of keybindings but can be rebound if you look for "select_line" in the default keybindings. (Linux and Windows)
Ctrl+Alt+P to get a dialog for opening all your Sublime projects.
Ctrl+R for navigating to functions or classes within the current file.
SublimeClang gives you Visual Studio-style Intellisense, static analysis, and jump to definition/implementation.
When setting up Vim emulation, you'll need to install VintageEx and change some of the default bindings (Ctrl+Shift+P+"key" to see the binding files). You'll also want SublimeBlockCursor.
For example, put the following in the user defined keymap to override the defaults:
[
{ "keys": ["ctrl+f"], "command": "move", "args": {"by": "pages", "forward": true} },
{ "keys": ["ctrl+b"], "command": "move", "args": {"by": "pages", "forward": false} },
{ "keys": ["ctrl+shift+f"], "command": "move", "args": {"by": "pages", "forward": true, "extend": true} },
{ "keys": ["ctrl+shift+b"], "command": "move", "args": {"by": "pages", "forward": false, "extend": true} }
]
You can also search and do multiple selection with a regular expression, which is awesome. I've used this heavily in the past few weeks. The only problem I've had is that all searches appear to run on the main thread, so when working on a sufficiently large file, the whole application blocks like hell. And to make it even worse, they update search results on the fly, meaning that for every new character you enter it blocks. I've taken to writing my expressions fully in a random textfield elsewhere, and pasting them in all at once.
I've kept my favorite shortcuts open in a panel for about a week, so I could learn them by heart: http://pastebin.com/hQtYKzhN
Favorites include: Expand selection (to various levels), close tag, block commenting and splitting lines!
You can also use your middle mouse button to make block selections, or doing things like making a long vertical line of multiple cursors (handy if you have an HTML list of varying line lengths, you can draw a long vertical line of multiple cursors, then use the left and right arrow keys and home and end keys to make changes to all of the lines quickly).
Obviously you didn't actually try what you suggested, if you had you'd have found there are plugins for JSON and XML and probably a few other formats, but was hoping ST2 would have what textmate and eclipse has had for a long time, code formatting, java, XML, xsl, JavaScript, c etc.
I know you're new here, but a little reminder about etiquette, even if you haven't gotten laid in a while, the community here is based on people being helpful rather than trying to be superior. The problem with that attitude is that it backfires and just makes you look insecure.
Sorry? My response was tailored for your comment -- you didn't mention plugins and you weren't (and still aren't) clear on the features you're missing. I.e., from your comment I inferred that you are new to all this, and so I treated you as a newcomer. I guess that hurt you feelings? If so, I didn't mean to :)
Nope, didn't hurt my feelings at all, I was trying to help you learn the ropes.
My comment was really pretty clear, and easy to follow, ST doesn't have a code formatter, you know, like textmate and eclipse do. It's a feature that lets you take poorly aligned code that is difficult to read, and fix up the alignment a la K&R et al. Hope that's clear enough for you :)
If you want to find out if someone is a newcomer, you can click on their profile and see pretty easily.
>It's a feature that lets you take poorly aligned code that is difficult to read, and fix up the alignment a la K&R et al. Hope that's clear enough for you :)
I linked you to plugins that do that. Also, you can find other such plugins through the site I linked for you. I wasn't inferring that you were a newcomer to Hacker News, I was inferring that you were new to this kind of technology in general (sort of freshmen level). And because my profile is two months old, doesn't mean I haven't been on Hacker News much longer. I'm glad I didn't hurt your feelings :)
You don't have to be so defensive, it's fine. No point in getting into a tizzy over this, I'm sure you meant the comment in the good spirit of the community. I am not new to this kind of technology, maybe you should have looked at my profile before making inaccurate statements. But the truth is, siodine, that you didn't think any such thing, you were just being passive aggressive (again).
> If you want to find out if someone is a newcomer, you can click on their profile and see pretty easily.
> the community here is based on people being helpful rather than trying to be superior
Siodine's account is older than yours. You're rageing on him for trying to help you out by suggesting you find plugins before dismissing ST2. You're making an ass of yourself man. Stop acting like an elitist prick.
dr42, I'd say you are the one not responding in the spirit of HN. Just calm down, someone tried to help, and you didn't find it helpful, no need to go all flamewar on them.
But then syntax highlighting is off until you close and reload it, which is annoying. I usually have a terminal open to the project anyway so I just use 'touch' to create the file I want.
I've been using {g}vi{m} for 20 years now, but just bought ST2. I like how this whole discussion revolves around finding keystrokes in ST2 that yield the convenience of doing things I took for granted in vim. Maybe I should just yield to the wisdom of the crowd, go back to VIM, forget about having a file explorer on the left side (NERDtree's wonkiness drove me to ST2), and learn to use Ctrl-P. It's what people keep suggesting to use in ST2.
You guys know that you can go to the Default Keymaps file and get all of these tips in one list right? You can even change them...
EDIT: Just for fun, here is that file on OS X: https://gist.github.com/3117613 Notice the "context" definitions. Also check out how the auto-pairing functionality is defined in terms of the key binding DSL. And how you can define nonstandard layouts for the panes. And so on.
Sublime is great. It reminds me of a less insane version of Foobar2000.
They're not actually cut off, they're in a scrollable text area (use two fingers to scroll within that text area) same as on the desktop. Not very easy to use, but then the device does have a very low (virtual/apparent) resolution of 320x480.
I actually really like getting other people's lists of their favorite ST2 features. It's more digestible than getting the entire list in one go. I find I tend to get one or two features that I put into "rotation" in reading these, while looking at all the keybindings just overwhelms me and leaves me using the features I already know.
115 comments
[ 3.8 ms ] story [ 142 ms ] thread(This is in ST2 for Mac OS X - I'm sure there's an equivalent feature in ST2 for other systems.)
Also:
Ctrl+Shift+D duplicates the current line by default (or the current selection, if any). Ctrl+Shift+K deletes the whole line. Ctrl+K twice deletes to end-of-line. Ctrl+K Ctrl+backspace deletes to beginning-of-line.
Combine duplicate, move up/down, and the Ctrl+D multi-cursor stuff, and you have a copy-and-paste coder’s dream editor. ;-)
http://wbond.net/sublime_packages/package_control
Useful for installing things like themes, syntax awareness, code linters, etc...
Plus it's easy as pie, and as anyone who's actually used Package Control knows, it would be worth it if you had to pluck a hair from an Argentinian llama and place it in your USB port while reciting the gregorian chant from Monty Python and the Holy Grail to install it. One line of actual Python is simply a convenient shortcut.
Man, you got that right. They should make it so that it can be installed through Package Control.
Oh, wait...
For a bootstrapping method, this seems completely reasonable. It doesn't involve downloading inscrutable single-platform installers, or opening a shell window, or any other external dependencies. The whole process runs inside the one environment you're guaranteed to have: Sublime Text itself.
Naturally people ask if the 3rd package manager will become an official feature but that opens up a new can of worms.
"Computer people generally design terrible computer interfaces because they are not only willing to cope with something bad, they're pleased to."
- Alan kay, Personal Computing Historic Beginnings
I'd prefer that to a black-box installer.
A fine grained find+replace/modify :)
Subsequent Cmd + d presses will select the following instance of the word for editing. Makes it easy to do things such as renaming a local variable or changing both the opening and closing element of a HTML tag.
For one thing, it goes a surprisingly long way to making up for not having language-sensitive refactoring tools if you’re renaming things, changing parameter lists, etc.
Also, you can make a selection in advance rather than relying on the default of selecting the current word. That selection can even span line breaks and/or include indentation. If you then select some/all instances of the same text as starting points using Ctrl+D, you can change not only the copies of the text but also (for example) extend the selections to include whatever is immediately before or afterwards (even if that is different in each case) or move to the start or end of each line. It’s a quick way to do a lot of common search-and-replace type operations without getting bogged down in regexes or macros.
A related useful technique is using (on Windows) Ctrl+Alt+up/down, which moves up/down a line creating multiple cursors as you go. If you then do Shift+left/right, you can get a “column selection” effect, for example. (You can also drag with the middle mouse button to select a column.)
I hope ST2 will build on these basic features as time goes on. It could allow incremental forward/backward search without cancelling the multiple cursors, let you cycle around which cursor is shown or will be left when you hit escape to cancel multiple mode, maybe even temporarily split the display to show multiple cursors at once if they are far apart. There’s a huge amount of potential here.
Also good to note: Command-F find also has a "Find All" option which can be faster than pressing Command-D multiple times, and also allows more complex non-word and regexp searches. From there you can use multiple cursors or replace the whole selection just by typing.
Brilliant editor, this one.
One minor complaint: I wish cmd+D had a "whole words only" setting. Its confusing when using with the "highlight all matches" feature, which is "whole words only" IIRC.
[1]http://ajaxorg.github.com/ace/build/kitchen-sink.html
See: http://vimdoc.sourceforge.net/htmldoc/visual.html#blockwise-...
ST2 allows multiple cursors in arbitrary locations - I'm not aware of another editor that supports that.
https://github.com/alfredodeza/plexer.vim
Switches case on lines 4, 15:
:4,15 norm ~
Indents text and changes the first two words of ever line to "duck" from mark a to the end of the file
:'a,$ norm >>2cwduck
Prepends a # to every line of the visual selection
:'<'> norm I#
Applies regex to lines that match a regex
:g/ducks/ s/moo/quack
Ctrl+R for navigating to functions or classes within the current file.
SublimeClang gives you Visual Studio-style Intellisense, static analysis, and jump to definition/implementation.
When setting up Vim emulation, you'll need to install VintageEx and change some of the default bindings (Ctrl+Shift+P+"key" to see the binding files). You'll also want SublimeBlockCursor.
For example, put the following in the user defined keymap to override the defaults: [ { "keys": ["ctrl+f"], "command": "move", "args": {"by": "pages", "forward": true} }, { "keys": ["ctrl+b"], "command": "move", "args": {"by": "pages", "forward": false} }, { "keys": ["ctrl+shift+f"], "command": "move", "args": {"by": "pages", "forward": true, "extend": true} }, { "keys": ["ctrl+shift+b"], "command": "move", "args": {"by": "pages", "forward": false, "extend": true} } ]
So, in this case, you would go to http://wbond.net/sublime_packages/community and search for "indent" or "pretty" or "xml".
I know you're new here, but a little reminder about etiquette, even if you haven't gotten laid in a while, the community here is based on people being helpful rather than trying to be superior. The problem with that attitude is that it backfires and just makes you look insecure.
My comment was really pretty clear, and easy to follow, ST doesn't have a code formatter, you know, like textmate and eclipse do. It's a feature that lets you take poorly aligned code that is difficult to read, and fix up the alignment a la K&R et al. Hope that's clear enough for you :)
If you want to find out if someone is a newcomer, you can click on their profile and see pretty easily.
I linked you to plugins that do that. Also, you can find other such plugins through the site I linked for you. I wasn't inferring that you were a newcomer to Hacker News, I was inferring that you were new to this kind of technology in general (sort of freshmen level). And because my profile is two months old, doesn't mean I haven't been on Hacker News much longer. I'm glad I didn't hurt your feelings :)
> If you want to find out if someone is a newcomer, you can click on their profile and see pretty easily.
> the community here is based on people being helpful rather than trying to be superior
Siodine's account is older than yours. You're rageing on him for trying to help you out by suggesting you find plugins before dismissing ST2. You're making an ass of yourself man. Stop acting like an elitist prick.
Relax.
> even if you haven't gotten laid in a while
> it backfires and just makes you look insecure.
what
I eventually had to get an extension and modify it to replicate emacs' c-x c-f to create files.
https://twitter.com/avand/status/224401243961954304
- Goto file: "con pos" -> app/controllers/posts_controller.rb
- Goto line in file: "con pos:100" -> app/controllers/posts_controller.rb line 100
- Goto function in file: "con pos@foo" function foo in app/controllers/posts_controller.rb
Also one that came up recently is CMD+ALT+Q to auto-wrap long comments to your ruler (e.g. 80 columns).
edit: back at my computer now. to put st2 into vim mode, just comment this line out in the default preferences:
EDIT: Just for fun, here is that file on OS X: https://gist.github.com/3117613 Notice the "context" definitions. Also check out how the auto-pairing functionality is defined in terms of the key binding DSL. And how you can define nonstandard layouts for the panes. And so on.
Sublime is great. It reminds me of a less insane version of Foobar2000.