When I am writing documents, I find myself settling on an organization 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) 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 sa开发者_如何学Pythony "boom, execute it" rather than having to retype it?
You can select the lines, yank the selection and execute it with
:@"
I like to make this mapping which will require you to make a visual selection first and doesn't overwrite your unnamed register:
vmap <space> "xy:@x<CR>
If you like to write Vim commands with line continuations:
vmap <space> :w! /tmp/x.vim<CR>:so /tmp/x.vim<CR>
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.
精彩评论