简体   繁体   中英

vim and snipmate, how to undo expansion

I am using vim with snipmate plugin. How can I undo the expansion?

# 1) before expansion
def[tab here]

# 2) expanded
def method_name
end

# How to get to 1) step?

I have implemented such by explicitly creating an undo point when triggering the snippet. The challenge is that the same key ( <Tab> by default) is used for snippet expansion and to jump to the next tab stop.

These parts in ~/.vim/after/plugin/snipMate.vim should do it. Note that this doesn't deal with the literal tab fallback, as I have remapped the trigger key to something else (see my fork ), and don't care about that part, but you could extract the relevant parts from TriggerSnippet() and add those to the conditional.

function! s:UndoPointBeforeSnippet()
        return (exists('g:snipPos') ? '' : "\<C-g>u")
endfunction
inoremap <expr> <SID>(UndoPointBeforeSnippet) <SID>UndoPointBeforeSnippet()

ino <silent> <script> <tab> <SID>(UndoPointBeforeSnippet) <c-r>=TriggerSnippet()<cr>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM