I'm using the UltiSnips plugin. When selecting text, you can press the trigger key to enter Insert mode, and the deleted text can then be used in a subsequent snippet. The snippet I'm using is as following:
snippet # "Put in brackets" i
\\${1:emph}{${VISUAL}$2}$0
endsnippet
So the way I use it is I select some text, press my trigger key (<TAB>
), enter #
, and press tab again. That works fine, but I want to map it a key (<C-S-E>
), such that I can simply select the text and press that key to do the same thing.
I've tried different ways, but none of them work:
vnoremap <buffer> <C-S-E> #
vnoremap <buffer> <C-S-E> :call UltiSnips#ExpandSnippet()#(<C-O>):call UltiSnips#ExpandSnippet()
function! WrapBrack()
call UltiSnips#ExpandSnippet()
normal i#
call UltiSnips#ExpandSnippet()
return ''
endfunction
vnoremap <buffer><expr> <C-S-E> WrapBrack()
This last one says that it won't allow autocommand to write because it's not safe, and I don't want to overrule that.
I don't know what to try next, and I can't find helpful documentation. Also I'm not very good with VimScript.
Here's the plugin settings I have:
Plug 'sirver/ultisnips'
let g:UltiSnipsExpandTrigger = '<tab>'
let g:UltiSnipsJumpForwardTrigger = '<tab>'
let g:UltiSnipsJumpBackwardTrigger = '<s-tab>'
let g:UltiSnipsSnippetDirectories=["UltiSnips", "my_snippets"]