4 ms·
I like the way people are starting to look at alternative approaches to text editing. Light Table has some good ideas, for example. For me, multiple cursors and
by lobster_johnson 14y ago
I like the way people are starting to look at alternative approaches to text editing. Light Table has some good ideas, for example. For me, multiple cursors and fast symbol navigation in Sublime Text has been a huge time saver.
Personally, I have never needed code folding (I prefer to have my own map of the code in my head, and anything that obscures that map just gets in the way), or Sublime Text's minimap, nor have I ever needed the symbol sidebar that is found in some IDEs (Eclipse, Netbeans). What I really want is more efficient editing.
For example, text editors like Sublime have zero language-sensitive refactoring support. I can't rename (variables, methods etc.) or extract methods, for example. Even some really simple operations like "select entire current nesting level" are unavailable. I remember using Eclipse 7 years ago and really liking the intelligence of the incremental compiler backend, even though I hated Java; it seems that with backends such as Clang, those tools can once again be applied outside big, annoying IDEs like Eclipse and Xcode.
Not sure if this particular approach is useful except to a small niche, but it looks pretty slick. Good luck with the effort!
- frou_dh 14y agoSublime's "Selection > Expand Selection to Brackets" (which can be repeated) is effectively nesting level selection for bracey languages. I do get what you're saying about the feeling of text manipulation vs. code-aware text manipulation though.
- lobster_johnson 14y agoIndeed, although that one is useless if you want to do something like wrap the current statement in an "if" or "while" or similar. "Expand Selection to Brackets" will actually include the lines containing the brackets, so you can't use it to select the contents of a block. Sublime also has "Expand Selection to Scope", except it doesn't really work that well: First invocation it chooses the current symbol, on 2nd the current brace block except the braces, on 3rd the braces themselves, and so on. And it also has "Expand Selection to Indentation", but I don't see use for it in cases where you want to manipulate blocks of code, since it nearly always doesn't select what you want. What I'd like is a command, let's call it "Expand Selection to Statement or Block", that: * On 1st invocation, selects the current line. int foo(int bar) { bar = mogrify(bar); if (bar > 0) { slartibartfast = 42; [[baz = bar + 1;]] # <-- [[ selection ]] print_report(); } return bar; } * On 2nd invocation, expands to the current contiguous set of lines, bounded by either empty lines or language-specific block (usually braces, or in Ruby's case, "if/while/..." until "end"), but not including the boundary: int foo(int bar) { bar = mogrify(bar); if (bar > 0) { slartibartfast = 42; [[baz = bar + 1; print_report();]] } return bar; } * On 3rd invocation, expands to the current contents of the block, excluding braces and excluding the lines containing the braces. int foo(int bar) { bar = mogrify(bar); if (bar > 0) { [[slartibartfast = 42; baz = bar + 1; print_report();]] } return bar; } * On 4rd invocation, expands to the enveloping statement that uses the block: int foo(int bar) { bar = mogrify(bar); [[if (bar > 0) { slartibartfast = 42; baz = bar + 1; print_report(); }]] return bar; } * On 5th invocation, it would continue to step 2, ie., looking for more lines that are contiguous with the current selection: int foo(int bar) { bar = mogrify(bar); [[if (bar > 0) { slartibartfast = 42; baz = bar + 1; print_report(); } return bar;]] } * And so on. Eventually it will get to the entire function declaration. Combined with a "wrap selection in braces"-type command (that indented the selection, wrapped it in braces, and placed the caret at the beginning so you could start typing something like "if (...) {") you would have a fairly powerful block-manipulating shortcut. It would probably be quite trivial to write such a plugin. I might try my hand at this. Not sure how much language sensitivity it would need, might be doable without anything at all.
- frou_dh 14y agoGood explanation. Thanks. Talking of contiguous lines. I like macros of the following form for quickly hopping around vertically in a file: // .sublime-macro [ {"command": "move", "args": {"by": "stops", "empty_line": true, "forward": false}} ] // .sublime-macro [ {"command": "move", "args": {"by": "stops", "empty_line": true, "forward": false, "extend": true}} ] // .sublime-keymap { "keys": ["ctrl+up"], "command": "run_macro_file", "args": {"file": "Packages/User/HopUp.sublime-macro"} } { "keys": ["ctrl+shift+up"], "command": "run_macro_file", "args": {"file": "Packages/User/HopUpSelect.sublime-macro"} },
- lobster_johnson 14y agoVery nice, I'm copying that one! You don't actually have to use macros for that. This will suffice (in your .sublime-keymap): {"keys": ["alt+up"], "command": "move", "args": {"by": "stops", "empty_line": true, "forward": false}}, {"keys": ["alt+down"], "command": "move", "args": {"by": "stops", "empty_line": true, "forward": true}}, {"keys": ["shift+alt+up"], "command": "move", "args": {"by": "stops", "empty_line": true, "forward": false, "extend": true}}, {"keys": ["shift+alt+down"], "command": "move", "args": {"by": "stops", "empty_line": true, "forward": true, "extend": true}}, (Changed it to alt instead of ctrl because that's how I like it.)
- frou_dh 14y agoOops. Right enough. It was in its own file because before I knew about stops+empty_line, the macro was simply a compound equivalent to pressing up 4 times.
- cytzol 14y agoIntelliJ IDEA has both "expand selection outward" and "wrap selection in if/trycatch/while/etc" functions. They both work pretty much how you describe them here. They're language-dependent, too, so they work in any language that the IDE can understand internally.
- 14y ago
- shabble 14y agoEmacs has a nice package called expand-region[1] which works in a similar, although more context-sensitive fashion. There's a nice intro screencast by Emacs Rocks[2] as well. The context-sensitivity is handled by having a list of expansion/contraction functions to try in sequence, so your region grows outwards by different units. Or you can specify a specific expansion function (like, er/mark-outside-python-string) upfront. As an example, the expand function list I have for a python buffer open is: (er/mark-word er/mark-symbol er/mark-symbol-with-prefix er/mark-next-accessor er/mark-method-call er/mark-inside-pairs er/mark-outside-pairs er/mark-comment er/mark-inside-python-string er/mark-outside-python-string er/mark-python-statement er/mark-python-block er/mark-python-block-and-decorator er/mark-outer-python-block) [1] https://github.com/magnars/expand-region.el https://github.com/magnars/expand-region.el or from ELPA [2] http://emacsrocks.com/e09.html http://emacsrocks.com/e09.html
- frou_dh 14y agoVery cool.
- SeoxyS 14y agoVim does a very good job of this: vi{ v%
- zevyoura 14y agoAfter using Sublime for a little over a year now, I've found the minimap is not useful as a map per se, but I do find it handy for two things. First, it's an omnipresent 'fingerprint' of the file I'm looking at, and I think subconsciously it helps me get my bearings when I switch files. Second, it's a nice fat, instant scroll bar for moving around a file quickly (which, yes, I do occasionally even with all the nice fuzzy search tools).
- lobster_johnson 14y agoI have tried using it, but I always find it a distracting presence. I know my files exceedingly well, and those that I don't know, I learn very quickly. On the other hand, I have colleagues who can't program without having pen and paper around -- people use whatever tools they like based on how their mind works.
- treeface 14y agoWhen I first started using ST, I thought the map would be really helpful. In the end, I typically use it the way you do...as a sort of placeholder and scrollbar. However, the ctrl-R feature has become my go-to tool for finding a subsection quickly. Really useful, I've found.
- cjc1083 14y ago"ctrl-R"..... I love you. Thank you.
- zackham 14y ago> Even some really simple operations like "select entire current nesting level" are unavailable. For anyone else looking for exactly this, here's a great vim extension that gives you "indent" objects: http://www.vim.org/scripts/script.php?script_id=3037 http://www.vim.org/scripts/script.php?script_id=3037