Saturday, October 30, 2010

Re: Coloring a line by keystroke: TODO file in vim

Gareth Oakes wrote:
> On Oct 14, 10:18 am, Stahlman Family <brettstahl...@comcast.net>
> wrote:
>> Christian Brabandt wrote:
>>> Hi Rahul!
>>> On Mi, 13 Okt 2010, Rahul wrote:
>>>> I maintain a simple Todo file using vim. Each line has a task.
>>>> Sometimes for an important task it would be nice if I had a keystroke
>>>> that would make the whole line (or visually selected set of lines) a
>>>> particular color, say "Red".
>>>> Is there a way of setting this up? I've colored before but it is via a
>>>> Syntax File looking for keywords. That might also work in this case
>>>> but I was wondering if people have a way to dot this.
>>> I have never used it, but this sounds like you want the txtfmt plugin.
>>> http://www.vim.org/scripts/script.php?script_id=2208
>
> Very cool! I was using a much simpler method for my TODO files:
>
> nmap <A-v> :2match IncSearch /.*\%'<\_.*\%'>.*/<CR>
>
> Select line(s) using visual mode then Alt-V once finished to highlight
> the lines. Txtfmt sounds way better though!

Gareth,
If you find yourself performing the same highlighting operations often
in your TODO files, you might want to check out the "user-maps" feature
in the Txtfmt help. The basic idea is that you can build Vim maps from
both Vim commands (e.g., motion/delete commands) and Txtfmt primitives
(e.g., insert red-bold tokens, jump to next format token, etc...) to
automate common highlighting operations (e.g., make the current line
bold-red on a blue background). The following example was copied from
the help file to illustrate the concept...

" Map <LocalLeader>rb in normal mode to make the current line bold with
" a red background.
let g:txtfmtUsermap1 =
\'nnoremap <LocalLeader>rb <<n\vI:kr,fb>><<n\vA:f-,k->>'

:help txtfmt-user-maps
:help txtfmt-user-map-examples

You might also wish to create maps for common operations such as making
the current word bold, italic, red, yellow, etc... The odd-looking
syntax of the user-maps seems to frighten some new users away, but it
actually looks worse than it is, and the examples can serve as a
pattern. Also, I'm happy to provide more tailored examples as necessary...

Sincerely,
Brett Stahlman

>
> -Gareth
>

--
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