Live data from Hacker News

Handy text manipulation tricks in Sublime Text 2

whiletruecode.com

21–30 of 99 posts

Re: Handy text manipulation tricks in Sublime Text 2

#21
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

Re: Handy text manipulation tricks in Sublime Text 2

#22

Now that I've gotten used to first class refactoring support in the Jetbrains products any other editor just seems archaic. IntelliJ has all the features mentioned in this article and intelligent code restructuring.

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

Re: Handy text manipulation tricks in Sublime Text 2

#23

Vim equivalents if you're feeling jealous (matching the order in the article): J Join line. ddp Swap line with the one below. ddkP Swap line with the one above. dd Delete current line yyp Duplicate line gq} Rewrap a paragraph. Vu Lowercase a line VU Uppercase a line Sort the selection by the Unix `sort` command (eg. sort -rn for reverse numeric order): V :!sort It goes a bit pear-shaped for these ones, though: Title-…

>I'm a bit stumped on toggling comments, though. Any ideas?

    " comentify/uncommentify a line or a visual block"
     function! Komment()
     if getline(".") =~ '^[ \t]*#'
             let hls=@/
             s/^\([ \t]*\)#\(.*\)$/\1\2
             let @/=hls
         else
             let hls=@/
             s/^\([ \t]*\)\(.*\)$/\1#\2
             let @/=hls
         endif
     endfunction
     :vnoremap // :call Komment()
     :nnoremap // :call Komment()

    If you want to use c style comment : 
    function! Komment()
         if getline(".") =~ '^[ \t]*\/\*'
             let hls=@/
             s/^\(\s*\)\/\*\(.*\)\*\/\(\s*\)$/\1\2\3/
             let @/=hls
         else
             let hls=@/
             s/[ \t]*$//
             s/^\(\s*\)\(.*\)\(\s*\)$/\1\/\* \2 \*\//
             let @/=hls
         endif
     endfunction
     :vnoremap  // :call Komment()
     :nnoremap   // :call Komment()
edited formatting

Re: Handy text manipulation tricks in Sublime Text 2

#24

Vim equivalents if you're feeling jealous (matching the order in the article): J Join line. ddp Swap line with the one below. ddkP Swap line with the one above. dd Delete current line yyp Duplicate line gq} Rewrap a paragraph. Vu Lowercase a line VU Uppercase a line Sort the selection by the Unix `sort` command (eg. sort -rn for reverse numeric order): V :!sort It goes a bit pear-shaped for these ones, though: Title-…

gqap uses a paragraph as a text object so you don't have to be at the start of the paragraph for it to work, just somewhere inside it.

Re: Handy text manipulation tricks in Sublime Text 2

#25

Vim equivalents if you're feeling jealous (matching the order in the article): J Join line. ddp Swap line with the one below. ddkP Swap line with the one above. dd Delete current line yyp Duplicate line gq} Rewrap a paragraph. Vu Lowercase a line VU Uppercase a line Sort the selection by the Unix `sort` command (eg. sort -rn for reverse numeric order): V :!sort It goes a bit pear-shaped for these ones, though: Title-…

> I'm a bit stumped on toggling comments, though. Any ideas? http://www.vim.org/scripts/script.php?script_id=1218

Simpler alternative: tComment http://www.vim.org/scripts/script.php?script_id=1173

Re: Handy text manipulation tricks in Sublime Text 2

#26
I often paste into it texts from other sources, and enable syntax highlight quickly using the command palette. For example, if I paste an XML into a new tab, I'd click

CTRL+SHIFT+P - X - Enter

The first part opens the command palette, the second selects XML syntax, and enter applies it.

Re: Handy text manipulation tricks in Sublime Text 2

#27

Vim equivalents if you're feeling jealous (matching the order in the article): J Join line. ddp Swap line with the one below. ddkP Swap line with the one above. dd Delete current line yyp Duplicate line gq} Rewrap a paragraph. Vu Lowercase a line VU Uppercase a line Sort the selection by the Unix `sort` command (eg. sort -rn for reverse numeric order): V :!sort It goes a bit pear-shaped for these ones, though: Title-…

Unless I'm misunderstanding the purpose of your 'TwiddleCase' function, you can simply highlight the text that you want to flip and hit ~ to invert the case.

Re: Handy text manipulation tricks in Sublime Text 2

#29
I use both Emacs and vim on a daily basis. Emacs is my main editor and vim is for quickly dropping in to make a change in a terminal either locally or on a server.

Both are amazing. Both are rock solid. Both are infinitely extensible. Both are free as in beer and as in freedom.

I'm not afraid of paying good money for software. I don't think it is necessary to pay for a closed-source text editor when such good open-source options exist that can do everything the commercial product can do and more.

TextMate (and now Sublime Text) have been popular in the hacker community, particularly with Rails people. The only advantage I can see is eye-candy. They look great on Macs.

I tried TextMate and put it in the trash as soon as I found it had no split windows. Not only that, I couldn't add split windows even if I had the time. If vim or Emacs is missing something, you can add it.

End of rant.

Re: Handy text manipulation tricks in Sublime Text 2

#30

My favourite feature is definently multiple cursors; Ctrl+D selects the next occurance of your highlighted word, Alt+F3 selects all occurances.

That's interesting. Can you edit all selected occurrences at once? I don't think there's an immediate analogue in Vim.

There is no analogue in Vim. It's the one thing I hate about vim.
Post reply on HN