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 say "boom, execute it" rather than having to retype it?
You can run commands in Vim by entering the command mode with : . Then you can execute external shell commands by pre-pending an exclamation mark ( ! ). For example, type :! ls , and Vim will run the shell's ls command from within Vim.
When you press * ( Shift + 8 ) in Normal mode, Vim will search for the word (i.e. keyword ) under the cursor. Assuming the text you want to search is a single word, this is a great way to search.
You can run the shell commands from inside of Vim by just using :! before the command, : means you have to be in command mode. Just after being in command mode, the ! or bang operator will execute the command typed after it from the terminal(Linux/ macOS) or your default shell(Windows -> CMD/Powershell).
To do this, in the command mode of Vim, just input colon (:) followed by a bang (!) and finally the command ('wc' in this case) followed by the file name (use % for current file). After you are done seeing the output, press the Enter key and you'll be taken back to your Vim session.
You can select the lines, yank the selection and execute it with
:@"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With