[ACCEPTED]-Vim: How to jump to first/last line of the current paragraph?-vim

Accepted answer
Score: 14

Go to the start of the first word of a paragraph: {w

Go 1 to the end of the last word of a paragraph: }ge

Score: 6

Map some new commands:

Start of first line 3 of paragraph:

:map f {)

Start of last line of paragraph:

:map l }(

Then 2 use f and l to navigate. You might want to 1 choose alternate keys.

Score: 1

I can only suggest

set whichwrap+=b,s
set virtualedit=onemore
nnoremap { k{<Space>0
vnoremap { k{<Space>0
nnoremap } j}<BS>0
vnoremap } j}<BS>0



Score: 0

I wanted to be able to do something similar 14 (programmatically convert the lines of the 13 current paragraph to an ordered or unordered 12 list) using Vimscript. Dealing with the 11 cases where the first line of the current 10 paragraph is also the first line of the 9 current buffer (or the last line of the 8 paragraph is the last line of the buffer) was 7 problematic and took a few hours to solve.

To 6 answer this question, I adapted the functions 5 I came up with to solve my problem by modifying 4 them to move the cursor instead of returning 3 a line number. Note that my solution preserves 2 the column position of the cursor but that 1 may not be necessary.

function! MoveParagraphFirstLine()
  let column = col(".")
  let first_line = line("'{")
  " Detect if the first line of the current paragraph is also the first line
  " of the current buffer and move cursor position accordingly.
  if first_line == 1
    call cursor(1, column)
    call cursor(first_line + 1, column)

function! MoveParagraphLastLine()
  let column = col(".")
  let last_line = line("'}")
  " Detect if the last line of the paragraph is also last line of the buffer.
  if line("$") == last_line
    call cursor(last_line, column)
    call cursor(last_line - 1, column)

nnoremap <leader>f :call MoveParagraphFirstLine()<CR>
nnoremap <leader>l :call MoveParagraphLastLine()<CR>

More Related questions