Skip to content

Instantly share code, notes, and snippets.

@icarofreire
Last active April 19, 2018 23:54
Show Gist options
  • Select an option

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

Select an option

Save icarofreire/586fda790fdb72414e9e47777c760bdf to your computer and use it in GitHub Desktop.
"Cores disponíveis:
"*cterm-colors*
"NR-16 NR-8 COLOR NAME
"0 0 Black
"1 4 DarkBlue
"2 2 DarkGreen
"3 6 DarkCyan
"4 1 DarkRed
"5 5 DarkMagenta
"6 3 Brown, DarkYellow
"7 7 LightGray, LightGrey, Gray, Grey
"8 0* DarkGray, DarkGrey
"9 4* Blue, LightBlue
"10 2* Green, LightGreen
"11 6* Cyan, LightCyan
"12 1* Red, LightRed
"13 5* Magenta, LightMagenta
"14 3* Yellow, LightYellow
"15 7* White
"
"Mdificar a cor do menu de seleção(Exemplo quando for selecionar uma palavra
"para autocompletar);
" # ctermfg neste caso modificará a cor do item quando ele for selecionado;
" # ctermbg neste caso modificará a cor do seletor do item selecionado;
highlight PmenuSel ctermfg=12 ctermbg=9
"Modifica a cor de fundo do menu para selecionar;
" # ctermfg neste caso modificará a cor das letras dos itens do menu;
" # ctermbg neste caso modificará a cor de fundo do menu;
highlight Pmenu ctermfg=0 ctermbg=15
"*************************************************
" ACEJUMP
" Based on emacs' AceJump feature (http://www.emacswiki.org/emacs/AceJump).
" AceJump based on these Vim plugins:
" EasyMotion (http://www.vim.org/scripts/script.php?script_id=3526)
" PreciseJump (http://www.vim.org/scripts/script.php?script_id=3437)
" Type AJ mapping, followed by a lower or uppercase letter.
" All words on the screen starting with that letter will have
" their first letters replaced with a sequential character.
" Type this character to jump to that word.
highlight AceJumpGrey ctermfg=darkgrey guifg=lightgrey
highlight AceJumpRed ctermfg=darkred guibg=NONE guifg=black gui=NONE
function! AceJumpPalavras ()
exe "norm m9"
let ini = str2nr(line('w0'))+5
exe "norm ".ini."gg"
" store some current values for restoring later
let origPos = getpos('.')
let origSearch = @/
" prompt for and capture user's search character
echo "AceJump to words starting with letter: "
let letter = nr2char(getchar())
" return if invalid key, mouse press, etc.
if len(matchstr(letter, '\k')) != 1
echo ""
redraw
return
endif
" redraws here and there to get past 'more' prompts
redraw
" row/col positions of words beginning with user's chosen letter
let pos = []
" monotone all text in visible part of window (dark grey by default)
call matchadd('AceJumpGrey', '\%'.line('w0').'l\_.*\%'.line('w$').'l', 50)
" loop over every line on the screen (just the visible lines)
for row in range(line('w0'), line('w$'))
" find all columns on this line where a word begins with our letter
let col = 0
let matchCol = match(' '.getline(row), '.\<'.letter, col)
while matchCol != -1
" store any matching row/col positions
call add(pos, [row, matchCol])
let col = matchCol + 1
let matchCol = match(' '.getline(row), '.\<'.letter, col)
endwhile
endfor
if len(pos) > 1
" jump characters used to mark found words (user-editable)
let chars = 'abcdefghijlkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.;"[]<>{}|\\'
if len(pos) > len(chars)
" TODO add groupings here if more pos matches than jump characters
endif
" trim found positions list; cannot be longer than jump markers list
let pos = pos[:len(chars)]
" jumps list to pair jump characters with found word positions
let jumps = {}
" change each found word's first letter to a jump character
for [r,c] in pos
" stop marking words if there are no more jump characters
if len(chars) == 0
break
endif
" 'pop' the next jump character from the list
let char = chars[0]
let chars = chars[1:]
" move cursor to the next found word
call setpos('.', [0,r,c+1,0])
" create jump character key to hold associated found word position
let jumps[char] = [0,r,c+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('AceJumpRed', '\%'.r.'l\%'.(c+1).'c', 50)
endfor
call setpos('.', origPos)
exe "norm ".ini."gg"
exe "norm zt"
exe "norm `9"
" this redraw is critical to syntax highlighting
redraw
" prompt user again for the jump character to jump to
echo 'AceJump to words starting with "'.letter.'" '
let jumpChar = nr2char(getchar())
" get rid of our syntax search highlighting
call clearmatches()
" clear out the status line
echo ""
redraw
" restore previous search register value
let @/ = origSearch
" 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
elseif len(pos) == 1
" if we only found one match, just jump to it without prompting
" set position to the one match
let [r,c] = pos[0]
call setpos('.', [0,r,c+1,0])
elseif len(pos) == 0
" no matches; set position back to start
call setpos('.', origPos)
endif
:delmarks 9
" turn off all search highlighting
call clearmatches()
" clean up the status line and return
echo ""
redraw
return
endfunction
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]
if( len(getline(linha)) == 0 ) "se for uma linha vazia, insere um caractere de espaço para poder substituir com uma letra;
exe 'norm I '
endif
" 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])
let li = getline(jumps[jumpChar][1])[0] " pula para a primeira palavra se o primeiro caractere da linha for vazio;
if li == " "
exe "norm w"
endif
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
function! AceJumpLetras ()
"cria uma marca do ponto atual do cursor;
exe "norm m9"
let ini = str2nr(line('w0'))+5
exe "norm ".ini."gg"
" store some current values for restoring later
let origPos = getpos('.')
let origSearch = @/
" prompt for and capture user's search character
echo "Procurar pelo caractere: "
let letter = nr2char(getchar())
" return if invalid key, mouse press, etc.
if letter == ' ' "permite buscar qualquer caractere, exceto espaço em branco;
"if len(matchstr(letter, '\k')) != 1
echo "apagou"
redraw
return
endif
" redraws here and there to get past 'more' prompts
redraw
" row/col positions of words beginning with user's chosen letter
let pos = []
" monotone all text in visible part of window (dark grey by default)
call matchadd('AceJumpGrey', '\%'.line('w0').'l\_.*\%'.line('w$').'l', 50)
" loop over every line on the screen (just the visible lines)
for row in range(line('w0'), line('w$'))
" find all columns on this line where a word begins with our letter
let col = 0
for l in split(getline(row), '\zs')
if( l == letter )
call add(pos, [row, col])
endif
let col = col +1
endfor
endfor
if len(pos) > 1
" jump characters used to mark found words (user-editable)
let chars = "abcdefghijlkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.;\'\"[]<>{}|\\!@#$%&*()_-=+?:^~/`"
if len(pos) > len(chars)
" TODO add groupings here if more pos matches than jump characters
endif
" jumps list to pair jump characters with found word positions
let jumps = {}
" change each found word's first letter to a jump character
for [r,c] in pos "[len(chars):]
" stop marking words if there are no more jump characters
if len(chars) == 0
break
endif
" 'pop' the next jump character from the list
let char = chars[0]
let chars = chars[1:]
" move cursor to the next found word
call setpos('.', [0,r,c+1,0])
" create jump character key to hold associated found word position
let jumps[char] = [0,r,c+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('AceJumpRed', '\%'.r.'l\%'.(c+1).'c', 50)
endfor
call setpos('.', origPos)
exe "norm ".ini."gg"
exe "norm zt"
exe "norm `9"
" this redraw is critical to syntax highlighting
redraw
" prompt user again for the jump character to jump to
echo 'Saltar para o local procurado por "'.letter.'" '
let jumpChar = nr2char(getchar())
" get rid of our syntax search highlighting
call clearmatches()
" clear out the status line
echo ""
redraw
" restore previous search register value
let @/ = origSearch
" 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
elseif len(pos) == 1
" if we only found one match, just jump to it without prompting
" set position to the one match
let [r,c] = pos[0]
call setpos('.', [0,r,c+1,0])
elseif len(pos) == 0
" no matches; set position back to start
exe "norm `9"
endif
:delmarks 9
" turn off all search highlighting
call clearmatches()
" clean up the status line and return
echo ""
redraw
return
endfunction
"map <M-a> :call AceJumpPalavras()<CR>
"map <SPACE> :call AceJumpLetras()<CR>
map <F2> :call AceJumpLinhas()<CR>
function! Colorir22(pos, origPos, origSearch, ini, letter, letras)
let jumps = {}
let chars = a:letras
" jumps list to pair jump characters with found word positions
" change each found word's first letter to a jump character
for [r,c] in a:pos
" stop marking words if there are no more jump characters
if len(chars) == 0
break
endif
" 'pop' the next jump character from the list
let char = chars[0]
let chars = chars[1:]
" move cursor to the next found word
call setpos('.', [0,r,c+1,0])
" create jump character key to hold associated found word position
let jumps[char] = [0,r,c+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('AceJumpRed', '\%'.r.'l\%'.(c+1).'c', 50)
endfor
call setpos('.', a:origPos)
exe "norm ".a:ini."gg"
exe "norm zt"
exe "norm `9"
" this redraw is critical to syntax highlighting
redraw
"" prompt user again for the jump character to jump to
echo 'Saltar para o local procurado por "'.a:letter.'" '
"let jumpChar = nr2char(getchar())
let jumpChar = getchar()
"" get rid of our syntax search highlighting
call clearmatches()
"" clear out the status line
echo ""
redraw
"" restore previous search register value
let @/ = a:origSearch
"" undo all the jump character letter replacement
norm u
return [jumps, jumpChar]
endfunction
function! AceJumpLetras2()
"cria uma marca do ponto atual do cursor;
exe "norm m9"
let ini = str2nr(line('w0'))+5
exe "norm ".ini."gg"
" store some current values for restoring later
let origPos = getpos('.')
let origSearch = @/
" prompt for and capture user's search character
echo "Procurar pelo caractere: "
let letter = nr2char(getchar())
" return if invalid key, mouse press, etc.
if letter == ' ' "permite buscar qualquer caractere, exceto espaço em branco;
"if len(matchstr(letter, '\k')) != 1
echo "apagou"
redraw
return
endif
" redraws here and there to get past 'more' prompts
redraw
" row/col positions of words beginning with user's chosen letter
let pos = []
" monotone all text in visible part of window (dark grey by default)
call matchadd('AceJumpGrey', '\%'.line('w0').'l\_.*\%'.line('w$').'l', 50)
" loop over every line on the screen (just the visible lines)
for row in range(line('w0'), line('w$'))
" find all columns on this line where a word begins with our letter
let col = 0
for l in split(getline(row), '\zs')
if( l == letter )
call add(pos, [row, col])
endif
let col = col +1
endfor
endfor
if len(pos) > 1
" jump characters used to mark found words (user-editable)
let chars = "abcdefghijlkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.;\'\"[]<>{}|\\!@#$%&*()_-=+?:^~/`"
let res = Colorir22(pos, origPos, origSearch, ini, letter, chars)
let jumps = res[0]
let jumpChar = res[1]
let partl = 0
while jumpChar == "\<F1>" || jumpChar == "\<F4>" && partl >= 0 && partl < len(pos)
if jumpChar == "\<F4>"
if (partl + len(chars)) < len(pos)
let partl = partl + len(chars)
endif
elseif jumpChar == "\<F1>"
if partl > 0
let partl = partl - len(chars)
endif
endif
call matchadd('AceJumpGrey', '\%'.line('w0').'l\_.*\%'.line('w$').'l', 50)
let sublist = pos[partl:]
let res = Colorir22(sublist, origPos, origSearch, ini, letter, chars)
let jumps = res[0]
let jumpChar = res[1]
endwhile
let jumpC = nr2char(jumpChar)
" if the user input a proper jump character, jump to it
if has_key(jumps, jumpC)
exe "norm ".ini."gg"
exe "norm zt"
exe "norm `9"
call setpos('.', jumps[jumpC])
else
" if it didn't work out, restore original cursor position
exe "norm ".ini."gg"
exe "norm zt"
exe "norm `9"
endif
elseif len(pos) == 1
" if we only found one match, just jump to it without prompting
" set position to the one match
let [r,c] = pos[0]
call setpos('.', [0,r,c+1,0])
elseif len(pos) == 0
" no matches; set position back to start
exe "norm `9"
endif
:delmarks 9
" turn off all search highlighting
call clearmatches()
" clean up the status line and return
echo ""
redraw
return
endfunction
map <S-SPACE> :call AceJumpLetras2()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment