Take the 2-minute tour ×

When I am writing documents, I find myself settling on an orginization convention appropriate to that document, and I would like vim to syntax highlight that convention. But making a ftplugin is too "global", I want the syntax coloring to come with the document, so if I send it somewhere without that plugin they can still get the coloring. I found that you can't do it through the modeline because that only accepts options.

Right now I am trying to find out if there is a way to select some text in visual mode (or whatever, but I use visual line mode for everything so it would be nice) and have it executed as a series of vim commands.

For example, at the bottom of one document I have:

vim highlighting:
    syn match Comment "^>.*$"

How can I select that text and say "boom, execute it" rather than having to retype it?

share|improve this question
Great question -- I've always wished you could enable extended modelines for various things such as custom matchings or similar stuff. Used to write temporary ftplugins for that. –  progo Apr 14 '11 at 12:25

2 Answers 2

up vote 22 down vote accepted

You can select the lines, yank the selection and execute it with

share|improve this answer
Also see [stackoverflow.com/questions/3997078/… ](this answer) for more insight on how to use registers –  Benoit Nov 24 '10 at 16:00
This works with any register, by the way. You can do a "ayy to yank your whole line to a, then use @a to run it. Note that you're going to get a bunch of spaces if you run an indented line, which might screw things up (it'll move you around in normal mode). Might be better to select the command with visual mode v. –  naught101 Apr 11 '12 at 6:50
I have nnoremap <leader>2 :@"<CR> and I use it a lot. (mnemonic is Shift-2=@=Execute.) –  Brady Trainor Aug 20 at 21:35

I've defined a few mappings based on lh-vim-lib that do not involve any register. This is indeed an overkill solution, but a neat one for mappings -- as it will never modify the default register.

share|improve this answer

Your Answer


