" VimCompletesMe.vim - For super simple tab completion " Maintainer: Akshay Hegde " Version: 1.2.1 " Website: " Vimscript Setup: {{{1 if exists("g:loaded_VimCompletesMe") || v:version < 703 || &compatible finish endif let g:loaded_VimCompletesMe = 1 " Options: {{{1 if !exists('g:vcm_s_tab_behavior') let g:vcm_s_tab_behavior = 0 endif if !exists('g:vcm_direction') let g:vcm_direction = 'n' endif if !exists('g:vcm_default_maps') let g:vcm_default_maps = 1 endif " Functions: {{{1 function! s:vim_completes_me(shift_tab) let dirs = ["\", "\"] let dir = g:vcm_direction =~? '[nf]' let map = exists('b:vcm_tab_complete') ? b:vcm_tab_complete : '' if pumvisible() if a:shift_tab return dirs[!dir] else return dirs[dir] endif endif " Figure out whether we should indent. let pos = getpos('.') let substr = matchstr(strpart(getline(pos[1]), 0, pos[2]-1), "[^ \t]*$") if strlen(substr) == 0 return (a:shift_tab && !g:vcm_s_tab_behavior) ? "\" : "\" endif " Figure out if user has started typing a path or a period let period = match(substr, '\.') != -1 let file_path = (has('win32') || has('win64')) ? '\\' : '\/' let file_pattern = match(substr, file_path) != -1 if file_pattern return "\\" elseif period && (&omnifunc != '') if get(b:, 'tab_complete_pos', []) == pos let exp = "\" . dirs[!dir] else let exp = "\\" endif let b:tab_complete_pos = pos return exp endif " First fallback to keyword completion if special completion was already tried. if exists('b:completion_tried') && b:completion_tried let b:completion_tried = 0 return "\" . dirs[!dir] endif " Fallback let b:completion_tried = 1 if map ==? "user" return "\\" elseif map ==? "tags" return "\\" elseif map ==? "omni" return "\\" elseif map ==? "dict" return "\\" elseif map ==? "vim" return "\\" else return "\" . dirs[!dir] endif endfunction inoremap vim_completes_me_forward vim_completes_me(0) inoremap vim_completes_me_backward vim_completes_me(1) " Maps: {{{1 if g:vcm_default_maps imap vim_completes_me_forward imap vim_completes_me_backward endif " Autocmds {{{1 augroup VCM autocmd! autocmd InsertEnter * let b:completion_tried = 0 if v:version > 703 || v:version == 703 && has('patch598') autocmd CompleteDone * let b:completion_tried = 0 endif augroup END