Tuesday, September 7, 2010

Re: Quick way to highlight a report file

On Tue, 7 Sep 2010, Christian Brabandt wrote:

> [...]
>
> By the way, typing this might become awkward, especially if you need
> to highlight different columns. So here is a small script, that
> defines the :HiCol command to highlight a specific column. Use :HiCol
> <nr> to have it highlight column <nr>. It uses tab completion so if
> you press <tab> after :HiCol it let's you select the number of columns
> in the current line.
>
> Simply save the following lines in a small file called columns.vim in
> your plugin folder (e.g. ~/.vim/plugin on Unix or $VIM/vimfiles/plugin
> on Windows) and the script will then be loaded automatically whenever
> you start vim. (Again, please make sure, the regular expression uses
> literal tabs instead of white space.)

Why not use '\t' instead of literal tabs? You don't lose whitespace in
translation/conversion. Your script as such:

:com! -nargs=1 -complete=custom,NrDelimiters HiCol :call HighlightColumn(<args>)

fun! NrDelimiters(A,L,P)
return join(range(1,len(split(getline('.'), "\t"))), "\n")
endfun

fun! HighlightColumn(nr)
if exists("b:matchcol")
call matchdelete(b:matchcol)
endif
let b:matchcol=matchadd("WildMenu", '\_^.*\n\%([^\t]*\t\)\{' .
\ (a:nr-1) . '\}\zs[^\t]*')
endfun

" Also note I lopped off the last \t*, since it looked weird to me to
" highlight the separator. e.g. with listchars=tab:»·

--
Best,
Ben

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment