Giter Club home page Giter Club logo

vim-clevertab's Introduction

vim-clevertab

Tiny replacement for Supertab that DOES do what I need.

If you're on a blank line or at the beginning of a line, it just issues a TAB keypress. Otherwise, it calls UltiSnips (or NeoSnippet). If no snippet was found, it calls the NeoComplete plugin, omni complete and keyword complete one after the other following the order you provided. If there are no matches it calls the following one.

If you are already browsing a completion candidates list, tab will jump to the next one and shift-tab to the previous one.

I did this because SuperTab did not detect if a completion returned something or not, and in some cases I really needed to fall from a completion function back to the other (Omni to Keyword or Keyword to Omni, and later added support for the excellent NeoComplete plugin).

This piece of code is a derivation of the function suggested by: [Nikolay Frantsev] (http://stackoverflow.com/users/256497/nikolay-frantsev) in [StackOverflow.com] (http://stackoverflow.com/questions/2136801/vim-keyword-complete-when-omni-complete-returns-nothing)

Installation

With Pathogen:

cd ~/.vim/bundle/
git clone https://github.com/neitanod/vim-clevertab.git

Edit your .vimrc and then load one of the predefined chains (which try to call UltiSnips), like this:

call CleverTab#KeywordFirst()

or

call CleverTab#OmniFirst()

or

call CleverTab#NeoCompleteFirst()

or define your own chain:

inoremap <silent><tab> <c-r>=CleverTab#Complete('start')<cr>
                      \<c-r>=CleverTab#Complete('tab')<cr>
                      \<c-r>=CleverTab#Complete('ultisnips')<cr>
                      \<c-r>=CleverTab#Complete('keyword')<cr>
                      \<c-r>=CleverTab#Complete('neocomplete')<cr>
                      \<c-r>=CleverTab#Complete('omni')<cr>
                      \<c-r>=CleverTab#Complete('stop')<cr>
inoremap <silent><s-tab> <c-r>=CleverTab#Complete('prev')<cr>

Here is a chain using NeoSnippet instead of UltiSnips:

inoremap <silent><tab> <c-r>=CleverTab#Complete('start')<cr>
                      \<c-r>=CleverTab#Complete('tab')<cr>
                      \<c-r>=CleverTab#Complete('neosnippet')<cr>
                      \<c-r>=CleverTab#Complete('keyword')<cr>
                      \<c-r>=CleverTab#Complete('omni')<cr>
                      \<c-r>=CleverTab#Complete('neocomplete')<cr>
                      \<c-r>=CleverTab#Complete('stop')<cr>
inoremap <silent><s-tab> <c-r>=CleverTab#Complete('prev')<cr>

You must always start with CleverTab#Complete('start'), as it takes care of the bootstrap of the chain.

Likewise, you must always end with CleverTab#Complete('end') which takes care of the cases where Tab means "next entry" on a suggestions menu.

Between those two, you can define which functions and plugins to call, and in which order. Each time that a function finds something to do the chain is broken and the rest of the calls are ignored.

Options:

  • tab

    Issues a Tab press and breaks the call chain, but only if the cursor is at the beginning of a line. Only whitespace is allowed at the left of the cursor. Otherwise this call is skipped.

  • ultisnips

    Starts UltiSnips plugin. If the keyword at the left of the cursor matches a snippet, it gets inserted and the call chain get broken. If UltiSnips fails to match the keyword to a snippet, control is passed to the next call.

  • keyword

    Issues a native <C-P> keypress. This starts the Keyword Completion. If a match is found and inserted into the buffer, or several matches are found and the pop up menu (PUM) is displayed, the call chain gets broken. If no match is found control is passed to the next call.

  • omni

    Just like the previous option, but instead of the native Keyword Completion function, the Omni Function is used by issuing a <C-X><C-O> key sequence press.

  • neocomplete

    Works like the keyword and omni calls, but this one starts the NeoComplete plugin to search for matches.

  • neosnippet

    Starts the NeoSnippet plugin to search for matches.

If you use a completion plugin other than NeoComplete and/or a snippets plugin other than UltiSnips or NeoSnippet, I encourage you to hack into this plugin and add them yourself! Each one is just an elseif block with just one to five lines of code in it. Then send me a pull request or just mail it to me.

Usage

While in insert mode, write some code and then just press TAB.

vim-clevertab's People

Contributors

cartolari avatar faf0 avatar neitanod avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vim-clevertab's Issues

Keyword completion invoked despite it not being configured for use

I configured clevertab to only use Ultisnips with the help of modifying your imap example code.

The result of :imap <tab><cr> shows:

i <Tab> * <C-R>=CleverTab#Complete('start')<CR><C-R>=CleverTab#Complete('tab')<CR><C-R>=CleverTab#Complete('ultisnips')<CR><C-R>=CleverTab#Complete('stop')<CR>

So I only wanted Ultisnips so that it would not be invoked when there is whitespace before the cursor. But keyword completion is invoked which I don't want.

How to reverse Tab and Tab-Shift for keyword completion?

It seems that "keyword" completion is cycling from the bottom to up in my Vim. I was able to fix it with:

diff --git a/autoload/CleverTab.vim b/autoload/CleverTab.vim
index 612bbb0..781761e 100644
--- a/autoload/CleverTab.vim
+++ b/autoload/CleverTab.vim
@@ -54,7 +54,7 @@ function! CleverTab#Complete(type)

   elseif a:type == 'keyword' && !pumvisible() && !g:CleverTab#cursor_moved && !g:CleverTab#stop
     echom "Keyword Complete"
-    let g:CleverTab#next_step_direction="P"
+    let g:CleverTab#next_step_direction="N"
     let g:CleverTab#eat_next=1
     return "\<C-P>"

but do I need to manually alter this plugin to have that behaviour? Is there a reason why default is bottom-up?

Expands UltiSnips snippet instead of progressing through popup completion menu

Example VIMRC

set nocompatible

set runtimepath+=~/.vim/plugins/repos/github.com/Shougo/dein.vim

" Required:
call dein#begin('~/.vim/plugins')

" Let dein manage dein
call dein#add('Shougo/dein.vim')
call dein#add('Shougo/neocomplete.vim')
call dein#add('SirVer/ultisnips')
call dein#add('honza/vim-snippets')
call dein#add('neitanod/vim-clevertab')
call dein#end()

filetype plugin indent on
syntax enable

if dein#check_install()
  call dein#install()
endif

let g:neocomplete#enable_at_startup = 1

call CleverTab#NeoCompleteFirst()

Steps to reproduce

  1. Start Vim using the VIMRC above and edit the VIMRC above
  2. Invoke :call CleverTab#NeoCompleteFirst() (See discussion in #1.)
  3. Go into insert mode and start a new line.
  4. Type c.
  5. Hit <Tab> to open the completion popup menu.
  6. Continue to hit <Tab> until c) is highlighted.
  7. Hit <Tab> one more time.
  8. Observe that, instead of cycling past this entry, the c) copyright snippet gets expanded.

Expected outcome:

<Tab> would have continued to cycle through the popup completion menu, rather than invoke the snippet.

Note this behavior is present even if g:UltiSnipsExpandTrigger is set to something other than <Tab>, e.g.,

let g:UltiSnipsExpandTrigger = '<F5>'

I think the priority of checking pumvisible needs to be higher (e.g., first thing checked) when CleverTab is handling <Tab>.

Doesn't cycle through popup completion menu when started by neocomplete

My example VIMRC

set nocompatible

set runtimepath+=~/.vim/plugins/repos/github.com/Shougo/dein.vim

" Required:
call dein#begin('~/.vim/plugins')

" Let dein manage dein
call dein#add('Shougo/dein.vim')
call dein#add('Shougo/neocomplete.vim')
call dein#add('SirVer/ultisnips')
call dein#add('honza/vim-snippets')
call dein#add('neitanod/vim-clevertab')
call dein#end()

filetype plugin indent on
syntax enable

if dein#check_install()
  call dein#install()
endif

let g:neocomplete#enable_at_startup = 1

call CleverTab#NeoCompleteFirst()

Steps to reproduce the behavior

  1. Start Vim using the VIMRC above and edit a file; best to just use the VIMRC as the file
  2. Invoke :call CleverTab#NeoCompleteFirst() (See discussion in #1.)
  3. Induce neocomplete to bring up the popup menu by typing 3 characters; for example neo
  4. Try to use <Tab> to select the completion
  5. Observe that no action takes place

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.