1

I have this following mapping in my .vimrc

" Toggle search next with blink and without blink
let s:enabled = 0

function! NextMatchToggle()
    if s:enabled
        unmap <buffer> n
        unmap <buffer> N
        let s:enabled = 0
    else
        nnoremap <buffer> n nzvzz
        nnoremap <buffer> N Nzvzz
        let s:enabled = 1
    endif
endfunction

nnoremap <buffer> <localleader>nmt :call NextMatchToggle()<cr>

It helps me toggle between two different behaviours of n and N.

I want this similar thing with UltiSnips[https://github.com/SirVer/ultisnips].

What I could do is to add two snippets with same string "describing" these snippets, and when I type this "describing" string followed by <tab> I will be asked which snippet I want to use, then I could choose which one to use. I don't want this, I want the same "describing" string to act differently at different times.

I am mainly going to use any solution to this problem (if exists) to .tex files. Here's an example, it may be dull, but it'll explain what I mean: I'm writing some maths sets, say $SL(n, \mathbb{R}$, but for some other .tex document I might want to write this same set like this- $SL_n(\mathbb{R})$ (maybe I am a coauthor and the other author has already written it like this). But I want slnr to be the string "describing" both the snippets. That's why I wanted a mechanism to switch between these two. Could this be done some other way?

  • 1
    I don't think it's possible and I don't see why anyone would want such a behavior: a snippet is triggered when you write a string "describing" the snippet followed by a key to expand your snippet. For example, you could write loop to get a for loop template and fun to get a function template. Using the same "describing" string would completely defeat the purpose of a snippet. I believe that you are facing a XY problem, so you should tell us more in details what you are trying to do and maybe someone will come up with a better solution. – statox Sep 27 '18 at 12:09
  • @statox I am mainly going to use any solution to this problem (if exists) to .tex files. Here's an example, it may be dull, but it describes what I mean: I'm writing some maths sets, say $SL(n, \mathbb{R}$, but for some other .tex document I might want to write this same set like this- $SL_n(\mathbb{R})$ (maybe I am a coauthor and the other author has already written it like this). But I want slnr to be the string "describing" both the snippets. That's why I wanted a mechanism to switch between these two. Could this be done some other way? – Mahbub Alam Sep 29 '18 at 14:34
  • @user938271 As far as I know there isn't, it's just a .tex file. Do you think this kind of toggling is possible? – Mahbub Alam Sep 30 '18 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.