Skip to content
This repository has been archived by the owner on Dec 26, 2018. It is now read-only.

Commit

Permalink
Add initial version of JumpNextLongLine plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
caio committed Dec 24, 2010
1 parent 6e91697 commit bcf2a39
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
6 changes: 4 additions & 2 deletions README.markdown
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Jump Next Long Line Plugin


Vim script to jump to the next line that exceeds the `&textwidth` option. Vim script to jump to the next line that exceeds the `&textwidth` option.


Author: Caio Romão <caioromao@gmail.com> Author: `Caio Romão <caioromao@gmail.com>`


### License ### License


Expand All @@ -21,4 +21,6 @@ will.
I request that you acknowledge my authorship. I request that you acknowledge my authorship.


Digital versions of the work may be available at Digital versions of the work may be available at
http://github.com/caio/jumpnextlongline.vim/. Learn more at pleasepirate.org. [http://github.com/caio/jumpnextlongline.vim][homepage]. Learn more at pleasepirate.org.

[homepage]: http://github.com/caio/jumpnextlongline.vim
76 changes: 76 additions & 0 deletions plugin/jumpnextlongline.vim
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,76 @@
" Jump Next Long Line
" ===================
"
" Vim plugin to jump to the next line that exceed the textwidth setting
" Last Change: 2010 Dec 24
" Maintainer: Caio Romão <caioromao@gmail.com>
" License: This file is placed in the public domain
"
" Mappings:
" <Leader>l or <Plug>JumpNextLongLine
" Jumps to the next (too) long line
"
" This plugin doesn't have any settings.

if exists("g:loaded_JumpNextLongLine") || &cp
finish
endif

let g:loaded_JumpNextLongLine= 1
let s:save_cpo = &cpo
set cpo&vim

if !hasmapto('<Plug>JumpNextLongLine')
nmap <silent> <unique> <Leader>l <Plug>JumpNextLongLine
endif

noremap <unique> <script> <Plug>JumpNextLongLine :call <SID>JumpNext()<CR>
function! s:JumpNext()
let nline = s:NextLongLine()
execute "normal! " . nline . "gg"
endfunction

function! s:ListLongLines()
let treshold = (&tw ? &tw : 80)
let spaces = repeat(" ", &ts)
let longlines = []

let i = 1
while i <= line("$")
" Respect user's &ts setting
let len = strlen(substitute(getline(i), '\t', spaces, 'g'))
if len > treshold
call add(longlines, i)
endif
let i += 1
endwhile

return longlines
endfunction

function! s:NextLongLine()
if !exists("b:long_lines_list")
let b:long_lines_list = s:ListLongLines()
endif

let curline = line('.')
let listsize = len(b:long_lines_list)

let i = 0
while i < listsize
let nextline = get(b:long_lines_list, i)
if nextline > curline
return nextline
endif
let i += 1
endwhile
" allow wrapping to the beginning of the buffer
return get(b:long_lines_list, 0, curline)
endfunction

" Delete list of long lines when idle and when writing
" to trigger it's re-creation
autocmd cursorhold,bufwritepost * unlet! b:long_lines_list

let &cpo = s:save_cpo

0 comments on commit bcf2a39

Please sign in to comment.