Skip to content

Instantly share code, notes, and snippets.

@icarofreire
Last active July 19, 2017 06:52
Show Gist options
  • Select an option

  • Save icarofreire/f6cc81f6123583917e99e683b01c2ce1 to your computer and use it in GitHub Desktop.

Select an option

Save icarofreire/f6cc81f6123583917e99e683b01c2ce1 to your computer and use it in GitHub Desktop.
highlight AceJumpGreyLinhas ctermfg=darkgrey guifg=lightgrey
highlight AceJumpRedLinhas ctermfg=darkred guibg=NONE guifg=black gui=NONE
function! AceJumpLinhas ()
"cria uma marca do ponto atual do cursor;
exe "norm m9"
let ini = str2nr(line('w0'))+5
exe "norm ".ini."gg"
let origPos = getpos('.')
" monotone all text in visible part of window (dark grey by default)
call matchadd('AceJumpGreyLinhas', '\%'.line('w0').'l\_.*\%'.line('w$').'l', 50)
let chars = 'abcdefghijlkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.;"[]<>{}|\\'
" jumps list to pair jump characters with found word positions
let jumps = {}
" loop over every line on the screen (just the visible lines)
for linha in range(line('w0'), line('w$'))
if( len(getline(linha)) > 0 ) "colocará as letras nas linhas não vazias;
let char = chars[0]
let chars = chars[1:]
" move cursor to the next found word
call setpos('.', [0,linha,1,0])
" create jump character key to hold associated found word position
let jumps[char] = [0,linha,1,0]
" replace first character in word with current jump character
exe 'norm r'.char
" change syntax on the jump character to make it highly visible
call matchadd('AceJumpRedLinhas', '\%'.linha.'l\%'.(1).'c', 50)
endif
endfor
call setpos('.', origPos)
" this redraw is critical to syntax highlighting
redraw
" prompt user again for the jump character to jump to
echo 'Letra da linha que deseja saltar:'
let jumpChar = nr2char(getchar())
" get rid of our syntax search highlighting
call clearmatches()
" clear out the status line
echo ""
redraw
" undo all the jump character letter replacement
norm u
" if the user input a proper jump character, jump to it
if has_key(jumps, jumpChar)
exe "norm ".ini."gg"
exe "norm zt"
exe "norm `9"
call setpos('.', jumps[jumpChar])
else
" if it didn't work out, restore original cursor position
exe "norm ".ini."gg"
exe "norm zt"
exe "norm `9"
endif
:delmarks 9
call clearmatches()
echo ""
redraw
return
endfunction
nnoremap <SPACE> :call AceJumpLinhas()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment