I have two commands for somewhat emulating the Emacs command narrow-to-defun.

I have two commands that move to the top/bottom of the current paragraph

nnoremap <silent> <leader>gt mp{zfgg`p

nnoremap <silent> <leader>gb mp}zfG`p

And this works really well for languages where people don't tend to leave blank lines in the middle of function bodies or other "interesting" pieces of code.

However, I have some projects where I use >=2 blank lines to separate units of code and liberally use single blank lines inside function bodies.

Is there an easy way to move by "big paragraphs", skipping over singleton blank lines?

For instance a lot of python code looks like, with occasional blank lines within function bodies and two blank lines separating them. Other things that are similar to top-level function definitions, like classes, are spaced accordingly.

def some_function(a, b, c):
    # do stuff

def some_other_function(a, c):
    # do stuff

1 Answer 1


You can use the regex:

nnoremap <silent> <leader>gt ?^\n\{2,}<CR>
nnoremap <silent> <leader>gb /^\n\{2,}<CR>

Find more with :help regex

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.