GithubHelp home page GithubHelp logo

Comments (13)

butterflyfish avatar butterflyfish commented on July 28, 2024 1

would you like to try ?

key map

let g:ulti_expand_or_jump_res = 0

function! SmartTab()
    if pumvisible() == 1
        return "\<C-n>"
    else
        let snippet = UltiSnips#ExpandSnippetOrJump()
        if g:ulti_expand_or_jump_res > 0
            return snippet
        else
            return "\<Tab>"
        endif
    endif
endfunction
inoremap <silent><expr><CR> pumvisible() ? "<C-R>=<SID>ExpandOrClosePopup()<CR>" : "\<Cr>"
snoremap <silent><Tab>      <Esc>:call UltiSnips#JumpForwards()<CR>
inoremap <silent><S-Tab>    <C-R>=SmartSTab()<CR>

Steps:

  • please use above key map
  • plugin ncm2/go-languageserver
  • input if, then press Tab to trigger snippet, then cursor is at first placeholder
  • input "tr", then ncm2 will popup menu. press Tab/C-n to choose completion true
  • press Enter key, you will find cursor is at if block body(in {})

But above keymap lose function parameter expand. Then change Entry map to your suggestion:

inoremap <silent> <expr> <CR> ncm2_ultisnips#expand_or("\<CR>", 'n')

Re-execute above steps, you will find explicit Enter key is accepted, as result, newline is inserted, { is moved to newline

from ncm2-ultisnips.

butterflyfish avatar butterflyfish commented on July 28, 2024 1

i understand now, but it will cause vimrc ugly/complex. UltiSnips provide API UltiSnips#ExpandSnippetOrJump(). How about change ncm2_ultisnips#expand_or to ncm2_ultisnips#expand_or_jump_or ? appreciated for this wonderful plugin.

from ncm2-ultisnips.

roxma avatar roxma commented on July 28, 2024

I'm not sure what you what.

After the snippet is expanded, ultisnips will automatically jumps to the first snippet tabstop/placeholder.

If you're encountering wired behavior, better to post a gif to describe the issue.

from ncm2-ultisnips.

butterflyfish avatar butterflyfish commented on July 28, 2024

maybe i hope to jump next placeholder. currently, based on example, press Enter key, it will input new line, but i want to jump to next placeholder(if body). i will try to find a gif tool to record.

thank you!

from ncm2-ultisnips.

roxma avatar roxma commented on July 28, 2024

If you want a different order of placeholder, you should modify the snippet instead of modify the plugin

from ncm2-ultisnips.

butterflyfish avatar butterflyfish commented on July 28, 2024
diff --git a/autoload/ncm2_ultisnips.vim b/autoload/ncm2_ultisnips.vim
index ac80a21..e165896 100644
--- a/autoload/ncm2_ultisnips.vim
+++ b/autoload/ncm2_ultisnips.vim
@@ -33,6 +33,11 @@ func! ncm2_ultisnips#_do_expand_or()
         call feedkeys("\<Plug>(ncm2_ultisnips_expand)", "im")
         return ''
     endif
+    let g:ulti_jump_forwards_res = 0
+    call UltiSnips#JumpForwards()
+    if g:ulti_jump_forwards_res == 1
+        return ''
+    endif
     call call('feedkeys', s:or_key)
     return ''
 endfunc

That's what I want.

from ncm2-ultisnips.

roxma avatar roxma commented on July 28, 2024

You could wrap your own <Plug>forward_or_cr key so that you could map a key like this:

inoremap <silent> <expr> <CR> ncm2_ultisnips#expand_or("\<Plug>forward_or_cr", 'm')

from ncm2-ultisnips.

roxma avatar roxma commented on July 28, 2024

I have exported two API, you should be able to program you own key mapping based on

ncm2_ultisnips#completed_is_snippet()

and

ncm2_ultisnips#inject_completed_snippet()

from ncm2-ultisnips.

butterflyfish avatar butterflyfish commented on July 28, 2024

thank you. Based on requirement, would you like to give an example ? Sorry, I don't know how to do because knowledge of vim script is very limited.

Anyway, thank you!

from ncm2-ultisnips.

roxma avatar roxma commented on July 28, 2024

ncm2_ultisnips#expand_or is an example for the two APIs

from ncm2-ultisnips.

partounian avatar partounian commented on July 28, 2024

Sorry if I am overly confused. Using this extension for ncm2 with your recommended configs for both does not allow for auto-completion and rotation through options with and . How should we go about solving this?

from ncm2-ultisnips.

roxma avatar roxma commented on July 28, 2024

@partounian

If you're having trouble, you need to post your minimal vimrc and elaborate the reproducing steps. Another issue should be open too.

from ncm2-ultisnips.

matt-snider avatar matt-snider commented on July 28, 2024

This isssue is a bit old, but yes this would be great to have.

Currently I can expand a snippet from ncm2 by pressing enter with the following mapping:

inoremap <silent> <expr> <cr> pumvisible() 
    \ ? ncm2_ultisnips#expand_or("\<c-y>", 'n') 
    \ : "\<cr>"

But I'd like to additionally be able to press enter again to jump to the next placeholder.

This is how <Plug>(neosnippet_expand_or_jump) in neosnippet works.

Edit - it occurred to me that something like this might work but it doesn't:

let g:UltiSnipsJumpForwardTrigger="<c-b>"
inoremap <silent> <expr> <cr> pumvisible()
    \ ? ncm2_ultisnips#expand_or("\<c-y>", 'n')
    \ : ncm2_ultisnips#completed_is_snippet()
    \   ? "\<c-b>"
    \   : "\<cr>"

from ncm2-ultisnips.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.