1

I am new to vim, I just wonder if I want to actually type the keyword in some cases, how do I do it? Do I need to disable the snippets? For example, if I use impd as keyword for import pandas as pd, then how do I actually type impd without triggering the snippet? I am using Plugin Ultisnip, here's the relevant part in my .vimrc

Plug 'SirVer/ultisnips'  
Plug 'honza/vim-snippets' 
let g:UltiSnipsExpandTrigger = '<tab>' 
let g:UltiSnipsJumpForwardTrigger ='<tab>' 
let g:UltiSnipsJumpBackwardTrigger = '<s-tab>' 
let g:UltiSnipsSnippetDirectories=["UltiSnips"]

And I config the plugin with the following two snippets for LaTeX copied from internet:

snippet beg "begin{} / end{}" bA
\begin{$1}
    $0
\end{$1}
endsnippet

snippet mk "Math" wA
$${1}$`!p
if t[2] and t[2][0] not in [',', '.', '?', '-', ' ']:
    snip.rv = ' '
else:
    snip.rv = ''
`$2
endsnippet

Then the behavior is: the snippet beg only triggers if I type it in a new line, and mk triggers no matter where I type, is there a way to, say, type "mk" without triggering it or disabling the snippet?

Thanks!

0

1 Answer 1

1

Those snippets mentioned in the question have the auto-expand option enabled, as there is an 'A' included in the options of each snippet (eg. bA, wA). To disable auto-expansion of a snippet, remove the 'A'. For example,

snippet mk "Math" w
$${1}$`!p
if t[2] and t[2][0] not in [',', '.', '?', '-', ' ']:
    snip.rv = ' '
else:
    snip.rv = ''
`$2
endsnippet

Now, with <tab> as the trigger, typing mk stays as is, but mk<tab> expands to $$, with the cursor in between the $s.

For more information, have a look at the various snippet options :h Ultisnips-snippet-options (you may need to run :helptags ALL before this).

1
  • Thank you for your generous help!
    – The R
    Jan 16, 2020 at 4:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.