GithubHelp home page GithubHelp logo

vim-acf's Introduction

vim-acf (Vim Auto Completion Framework)

  • Timer (+timers) based auto completion framework for vim8.
  • Written by pure vim script.
  • Simple and thin framework because it uses built-in completion with a feedkeys().

Requirements

  • Vim8 with +timers and +lambda
    • patch-8.0.0283 or later is recommended for mode(1).

Install

  • vim-plug

    Plug 'presuku/vim-acf.vim'

Feature

  • Timer(+timers)-based callback.

    • vim-acf callback a function every g:acf_update_time.
  • Rule-based fallback searching.

    • Searching matched rule by at in order of priority in same filetype.
  • Filetype-based fallback searching.

    • No found matched rule in current filetype, to next search in "" (blank) filetype.

Usage

Options

let g:acf_update_time = 250 " default 250ms

Recommend setting

set completeopt=menuone,noselect,noinsert

Add rules to trigger func.

First, you need to install the omnifunc plugin for each language (ex. vim-clag for C).

C or other

  • Completing file (and directory) names by i_CTRL-X_CTRL-F on Comment and String syntax when the cursor after /.

    call acf#add_rule({
          \ 'filetype' : ['c'],
          \ 'priority' : 8,
          \ 'at'       : '/\%#',
          \ 'func'     : function("feedkeys", ["\<C-x>\<C-f>", "n"]),
          \ 'syntax'   : ['Comment', 'String']
          \})
  • Call omnifunc by i_CTRL-X_CTRL-O when the cursor after a \k. or \k-> or \k::. (\k is keyword characters. see :help \k)

    call acf#add_rule({
          \ 'filetype' : ['c', 'cpp', 'java'],
          \ 'priority' : 9,
          \ 'at'       : '\k\{1,}\%(\.\|->\|::\)\%#',
          \ 'func'     : function("feedkeys", ["\<C-x>\<C-o>", "n"]),
          \})

Vim script

  • Completing file (and directory) names by i_CTRL-X_CTRL-F on Comment and String syntax when the cursor after /. vim commands by i_CTRL-X_CTRL-V when the cursor after a \k or :. (\k is keyword characters. see :help \k)

    call acf#add_rule({
          \ 'filetype' : ['vim'],
          \ 'priority' : 9,
          \ 'at'       : '\%(\k\|:\)\{1,}\%#',
          \ 'func'     : function("feedkeys", ["\<C-x>\<C-v>", "n"]),
          \})

For any filetype.

  • Completing keywords by i_CTRL-N when the cursor after a \k\k\k (three keyword characters).

    call acf#add_rule({
          \ 'filetype' : [''],
          \ 'priority' : 7,
          \ 'at'       : '\k\{3,}\%#',
          \ 'func'     : function("feedkeys", ["\<C-n>", "n"]),
          \})
  • Fallback-ed completing file names by i_CTRL-X_CTRL-F when the cursor after a /.

    call acf#add_rule({
          \ 'filetype' : [''],
          \ 'priority' : 8,
          \ 'at'       : '/\%#',
          \ 'func'     : function("feedkeys", ["\<C-x>\<C-f>", "n"]),
          \})
  • Completing neosnippet's list when the cursor after snip.

    • you can also use complete() function.
    let g:nsnip_prefix="snip"
    function! s:acf_neosnippet_complete()
      let ctx = acf#get_context()
      let n_prefix = len(g:nsnip_prefix)
      let base = l:ctx.base[n_prefix:]
      let list = []
      let val = values(neosnippet#helpers#get_completion_snippets())
      for v in val
        if v.word =~ '^'. l:base
          let v.menu = '[nsnip]'
          call add(list, v)
        endif
      endfor
      call sort(list)
      call complete(l:ctx.startcol, list)
      return ''
    endfunction
    
    call acf#add_rule({
          \ 'filetype' : [''],
          \ 'priority' : 9,
          \ 'at'       : '\%(^\|\s\)\zs'.g:nsnip_prefix.'\%#',
          \ 'func'     : {-> s:acf_neosnippet_complete() },
          \})

Thanks

  • lexima.vim by @cohama

    • Base plugin system from this plugin, and a lot of vim script to be used for reference or study.
  • SimpleAutoComplPop by @roxma, ns9tks

    • Just idea from this plugin.
  • quickrun by @thinca

    • Easy and quickly debugging (learning) for vim script.

License

MIT (c) @presuku

vim-acf's People

Contributors

presuku avatar

Stargazers

 avatar

Watchers

 avatar

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.