Home Download Buy Blog Forum Support

jump to next empty line?

jump to next empty line?

Postby yatayata on Sun Oct 30, 2011 10:06 am

is there a way to remap ctrl-up/down to jumpt to the next empty line?

i use this for navigation in emacs all the time, and just leave an empty line as punctuation in my code...

tx!
yatayata
 
Posts: 1
Joined: Sun Oct 30, 2011 9:26 am

Re: jump to next empty line?

Postby spadgos on Tue Nov 01, 2011 1:37 pm

you could look at using bookmarks. Ctrl+F2 to toggle a bookmark, and F2 to go to the next one.
spadgos
 
Posts: 121
Joined: Thu Oct 06, 2011 12:49 am

Re: jump to next empty line?

Postby lappri on Wed Nov 02, 2011 12:21 am

You could use the code below and tweek it a bit.
My previous editor was TextPad and I used move by paragraph all the time. I missed it dearly and wrote a command for it.
I have it mapped to alt+up/down and the selecting variants mapped to ctrl+shift+up/down.
Hope this helps.

...\AppData\Roaming\Sublime Text 2\Packages\User\move_by_paragraph.py:
Code: Select all
import sublime, sublime_plugin

class MoveByParagraphCommand(sublime_plugin.TextCommand):
    def run(self, edit, extend = False, forward = True):
        self.view.run_command("move_to", {"to": "hardbol", "extend": extend}) # to mimic TextPad's behaviour
        pt = self.view.sel()[0].b
        if forward:
            rg = self.view.find("\n\s*\n", pt)
            new_pt = rg.b if rg else self.view.size()
        else:
            # couldn't find "find previous" command
            rgs = self.view.find_all("\n[\s]*\n")
            new_pt = 0
            for rg in rgs:
                if rg.b < pt:
                    new_pt = rg.b
        new_pt_visible = self.view.visible_region().contains(new_pt)
        #
        # obviously inefficient way of doing it (couldn't find amount for move command)
        # becomes slow for veeeeery long paragraphs
        self.view.run_command("move", {"by": "lines", "forward": forward, "extend": extend})
        while (self.view.sel()[0].b < new_pt) == forward and self.view.sel()[0].b != pt:
            pt = self.view.sel()[0].b
            self.view.run_command("move", {"by": "lines", "forward": forward, "extend": extend})
        while self.view.sel()[0].b != new_pt:
            self.view.run_command("move", {"by": "characters", "forward": self.view.sel()[0].b < new_pt, "extend": extend})
        if not new_pt_visible:
            self.view.show_at_center(new_pt)


In ...\AppData\Roaming\Sublime Text 2\Packages\User\Default (Windows).sublime-keymap:
Code: Select all
   { "keys": ["ctrl+shift+up"], "command": "move_by_paragraph", "args": {"extend": true, "forward": false} },
   { "keys": ["ctrl+shift+down"], "command": "move_by_paragraph", "args": {"extend": true} },
   { "keys": ["alt+up"], "command": "move_by_paragraph", "args": {"extend": false, "forward": false} },
   { "keys": ["alt+down"], "command": "move_by_paragraph", "args": {"extend": false} },
lappri
 
Posts: 1
Joined: Sun Jan 30, 2011 11:02 pm

Re: jump to next empty line?

Postby jps on Wed Nov 02, 2011 12:42 am

Another option is:

Code: Select all
{ "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} }
jps
Site Admin
 
Posts: 3077
Joined: Wed Mar 19, 2008 12:33 pm

Re: jump to next empty line?

Postby tobia on Tue Oct 16, 2012 2:57 pm

jps wrote:Another option is:

Code: Select all
{ "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} }

I was looking for the same command (curly braces in Vim command mode, I always used it) and this is the correct answer, thanks.
tobia
 
Posts: 10
Joined: Tue Oct 16, 2012 2:55 pm

Re: jump to next empty line?

Postby bizoo on Tue Oct 16, 2012 3:27 pm

Didn't know "move by stops" exists !!!

Is there a comprehensive list of command and their arguments ?
Maybe there's a way to generate it automatically ?
bizoo
 
Posts: 888
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: jump to next empty line?

Postby tobia on Fri Oct 19, 2012 10:44 am

More to the point: how do we extend the above command with shift to get selection by whole paragraphs?
(shift+alt+up/down = select up to the prev/next empty line)

This would be very useful to quickly move blocks of code around.

Is there a select by stops command?
tobia
 
Posts: 10
Joined: Tue Oct 16, 2012 2:55 pm

Re: jump to next empty line?

Postby adzenith on Fri Oct 19, 2012 5:07 pm

You can add "extend":"true" to any movement command, I think. Just create another binding with the shift key involved.
adzenith
 
Posts: 1217
Joined: Mon Oct 19, 2009 9:12 pm

Re: jump to next empty line?

Postby tobia on Fri Nov 09, 2012 11:36 am

Thank you!

This is the complete set of bindings that solve my issue:

Code: Select all
{"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}},
tobia
 
Posts: 10
Joined: Tue Oct 16, 2012 2:55 pm

Re: jump to next empty line?

Postby catman on Wed May 08, 2013 5:50 pm

Thanks lappri,

I have been missing paragraph jumping tonnes.
catman
 
Posts: 1
Joined: Wed May 08, 2013 5:48 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 13 guests