├── .gitignore ├── README.md └── plugin └── hl-var.vim /.gitignore: -------------------------------------------------------------------------------- 1 | *.org 2 | *.bak 3 | *~ 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vim plugin to highlight variables in Perl 2 | 3 | This Vim plugin will highlight all instances of the Perl variable under the 4 | cursor. It is a fork of Sandeep.c.r's plugin to do the same for PHP. 5 | 6 | ![Imgur](https://i.imgur.com/yBnFrby.gif) 7 | 8 | (Image credit: [Ovid](https://github.com/ovid)) 9 | 10 | Perl variables, of all types, will be highlighted, as will methods. 11 | 12 | ## Installation 13 | 14 | If you are using a package manager such as *Vundle* or *Pathogen*, this plugin 15 | should be installed in the standard manner. If you are not (why not?), you 16 | could just copy *hl-var.vim* into your *~/.vim/plugins* directory. 17 | 18 | Requires Vim version 7.3 or later. 19 | 20 | ## Configuration 21 | 22 | The variables will be highlighted after you have not performed any action for a 23 | certain length of time. That time is controlled by the *updatetime* setting. 24 | (See `:help updatetime`.) The default value is 4000, which is four seconds. 25 | That value is too large for this plugin, so I recommend adjusting it to 500, 26 | which is half a second. You can experiment with the value which works best for 27 | you. 28 | 29 | `set updatetime=500` 30 | 31 | You can customise the highlighting applied by this plugin by using the *hlvarhl* 32 | global variable. This can be set in your *.vimrc* file: 33 | 34 | `let g:hlvarhl="ctermbg=black ctermfg=red guifg=#ff0000 guibg=#000000 gui=bold"` 35 | 36 | If you don't want the variable under cursor to be highlighted, you can disable 37 | it by setting variable *g:hlvarcurrent* to 1. 38 | 39 | `let g:hlvarcurrent = 1` 40 | 41 | ## Licence 42 | 43 | This code is released under the MIT licence, as is Sandeep's original code. See 44 | *hl-var.vim* for the full licence. 45 | 46 | ## Authors 47 | 48 | This version was forked from Sandeep's 49 | [repository](https://bitbucket.org/sras/vawa), with his blessing. Curtis "Ovid" 50 | Poe hacked it to support Perl. It is currently being maintained by Paul 51 | Johnson. 52 | -------------------------------------------------------------------------------- /plugin/hl-var.vim: -------------------------------------------------------------------------------- 1 | " Vim plugin to highlight variables in Perl. 2 | " 3 | " Original author: Sandeep.c.r 4 | " Hacked for Perl by: Curtis "Ovid" Poe 5 | " Current maintainer: Paul Johnson 6 | " 7 | " Copyright (c) 2014 Sandeep.C.R 8 | " 9 | " Permission is hereby granted, free of charge, to any person obtaining a copy 10 | " of this software and associated documentation files (the "Software"), to deal 11 | " in the Software without restriction, including without limitation the rights 12 | " to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | " copies of the Software, and to permit persons to whom the Software is 14 | " furnished to do so, subject to the following conditions: 15 | " 16 | " The above copyright notice and this permission notice shall be included in all 17 | " copies or substantial portions of the Software. 18 | " 19 | " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | " IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | " FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | " AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | " LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | " OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | " SOFTWARE. 26 | 27 | function! s:hlvar() 28 | if (exists("w:current_match")) 29 | call matchdelete(w:current_match) 30 | unlet w:current_match 31 | endif 32 | 33 | let s:temp = getpos('.') 34 | let s:current_col = s:temp[2] 35 | let s:current_line = s:temp[1] 36 | let s:temp = searchpos('[>$@%*&]','bcnW') 37 | let s:sigil_line = s:temp[0] 38 | let s:sigil_col = s:temp[1] 39 | if (s:sigil_line != s:current_line) 40 | return 41 | endif 42 | let s:temp = getbufline(bufnr('%'),line('.')) 43 | let s:varend = match(s:temp[0], '[^a-zA-Z0-9_\x7f-\xff]\|\n', s:sigil_col) + 1 44 | let s:space_col = s:varend 45 | if (s:varend == 0 || (s:space_col > s:sigil_col && s:space_col < s:current_col)) 46 | return 47 | endif 48 | let s:current_char = s:temp[0][s:current_col-1] 49 | if (s:current_char == '>' || s:current_char == '-') 50 | return 51 | endif 52 | 53 | let s:str = strpart(s:temp[0], s:sigil_col - 1, s:varend - s:sigil_col) 54 | let s:prefix = '' 55 | if (s:str == '$' || s:str == '&' || s:str == '*') 56 | return 57 | endif 58 | 59 | if (exists("g:hlvarcurrent") && g:hlvarcurrent == 1) 60 | let s:lineab = s:current_line - 1 61 | let s:linebe = s:current_line + 1 62 | let s:colbf = s:sigil_col + 1 63 | let s:prefix = '\(\%>' . s:lineab . 'l.\%<' . s:linebe . 'l.\%>' . s:colbf . 'c\)\@!' 64 | endif 65 | 66 | let s:match = s:prefix 67 | if (strpart(s:str, 0, 1) == '>') 68 | let s:str = strpart(s:str, 1) 69 | let s:match = s:match . '>\@<=' 70 | else 71 | let s:str = substitute( s:str, '^[$@%]', '[$@%]', '' ) 72 | endif 73 | let s:match = s:match . s:str . '\n\{-\}\(\([^a-zA-Z0-9_\x7f-\xff]\)\|$\)\@=' 74 | let w:current_match = matchadd('VarHl', s:match) 75 | endfunction 76 | 77 | if (!exists("g:hlvarnoauto") || g:hlvarnoauto == 1) 78 | augroup HighlightVar 79 | autocmd! 80 | au FileType perl :au CursorHold * call hlvar() 81 | au FileType perl :au CursorHoldi * call hlvar() 82 | au CursorHold *.pl call hlvar() 83 | au CursorHoldi *.pl call hlvar() 84 | au CursorHold *.pm call hlvar() 85 | au CursorHoldi *.pm call hlvar() 86 | au CursorHold *.t call hlvar() 87 | au CursorHoldi *.t call hlvar() 88 | augroup END 89 | if (exists("g:hlvarhl")) 90 | exe "highlight VarHl " . g:hlvarhl 91 | else 92 | highlight VarHl ctermbg=black guifg=#ff0000 guibg=#000000 ctermfg=LightRed gui=bold 93 | endif 94 | endif 95 | 96 | command! HlVar :call hlvar() 97 | --------------------------------------------------------------------------------