Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim Ultisnips, visual token and system clipboard

Tags:

vim

ultisnips

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.

like image 260
user2183977 Avatar asked Dec 01 '25 19:12

user2183977


1 Answers

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
like image 54
SergioAraujo Avatar answered Dec 03 '25 21:12

SergioAraujo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!