I am quite new to vim but I found it to be powerful tool (especially with plugins such as UltiSnips and YouCompleteMe). I quite like the idea of creating personal snippets in conjunction with visual token to perform quick text transformations. However I would like to be able to select some text in web browser, copy it to clipboard and simply type my_snippet in vim to expand my_snippet with text from clipboard as visual token. It would be quite useful but I have no idea how to arrange it. It would be great if somebody can instruct me how to set up vim to do this.
I will try to give you an example, an issue I had for some time. I am constantly trying out new plugins so, copying the github project name like:
psliwka/vim-smoothie
And transforming it on:
Plug 'psliwka/vim-smoothie'
Is something problematic, because along with typing the word Plug at the beggining of the line I have to type the single quotes and remove three spaces and one caridge return
psliwka /
vim-smoothie
So my snippet has to wrap it all in one go. After some research I ended up with this:
snippet plug "Insert a new plugin on my vimrc" w
Plug '${1:`!v substitute(@+, ' \|\n', '', 'g' )`}'
endsnippet
Some Explanation: The !v part of the snippet means "vim interpolation", so I can use some vim commands. The substitute() command rules are:
where-substitue, what-substitute, substitution, flags
| | | |
@+ ' \|\n' '' g
clipboard space or enter nothing globally
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