当要自动完成的单词没有被空格包围时,Vim自动完成失败

当要自动完成的单词没有被空格包围时,Vim自动完成失败,vim,editor,vi,Vim,Editor,Vi,有人能帮我调试为什么自动完成在这种情况下无法工作吗?(例如,TAB实际上是我点击TAB以自动完成): 我相信这是因为第二个案例中的单词是自动完成的,换句话说,它被空格包围着。它失败了,因为第一个示例用其他字符填充了单词 以下是我的vimrc: set history=700 侦测文件类型 文件类型缩进 设置自动读取 让mapleader=“,” 设g:mapleader=“,” nmap w:w! 将so设置为7 设置菜单 设置wildignore=*.o、*~、*.pyc 定尺 地图j_ 地图

有人能帮我调试为什么自动完成在这种情况下无法工作吗?(例如,TAB实际上是我点击TAB以自动完成):

我相信这是因为第二个案例中的单词是自动完成的,换句话说,它被空格包围着。它失败了,因为第一个示例用其他字符填充了单词

以下是我的vimrc:
set history=700
侦测文件类型
文件类型缩进
设置自动读取
让mapleader=“,”
设g:mapleader=“,”
nmap w:w!
将so设置为7
设置菜单
设置wildignore=*.o、*~、*.pyc
定尺
地图j_
地图k_
设置winminheight=0
设置winwidth=80
设置cmdheight=2
设置隐藏
设置退格=下线、开始、缩进
设置包裹+=,h,l
置之不理
设置smartcase
取消高亮显示
在搜索中设置
设懒虫
设置魔法
布景
设置匹配时间=3
设置mat=2
设置无错误单元格
设置novisualbell
设置tm=500
集合连接空间
集合列表
设置scrolloff=4
设置foldminlines=1
设置completeopt=菜单
沙漠配色方案
设置背景=暗
如果有(“gui_正在运行”)
设置guioptions-=T
设置guioptions+=e
设置t_Co=256
设置吉他标签=%M\%t
恩迪夫
设置guioptions=gmrLt
set guifont=Lucida_Consoloe:h8:cANSI
设置编码=utf8
设置ffs=unix、dos、mac
设置目录=。/\u备份
设置backupdir=./.backup
立即开始
设置noswapfile
设置扩展选项卡
设置智能选项卡
设置softtabstop=4
智能对齐
不显示行号
立即开始
设置shiftwidth=4
设置tabstop=4
设置lbr
设置tw=500
设置ai“自动缩进”
设置si“智能缩进
设置“换行”换行
vnoremap*:调用VisualSelection('f')
vnoremap#:调用VisualSelection('b')
地图/
地图?
地图:noh
地图bd:Bclose
地图ba:11000 bd!
地图tn:tabnew
映射到:tabonly
地图tc:tabclose
地图tm:tabmove
映射te:tabedit=expand(“%:p:h”)/
地图cd:cd%:p:h:pwd
尝试
设置switchbuf=useopen、usetab、newtab
设置stal=2
抓住
末日
设置laststatus=2
set statusline=\%{HasPaste()}%F%m%r%h\%w\\CWD:\%r%{getcwd()}%h\\\Line:\%l
地图0^
vnoremap gv:调用VisualSelection('gv')
地图g:vimgrep//***。
地图:vimgrep/%
vnoremap r:调用VisualSelection('replace')
地图抄送:右上角
map co ggVGy:tabnew:set syntax=qfpgg
地图n:cn
地图p:cp
地图ss:setlocal咒语!
地图编号]s
映射sp[s]
地图sa zg
地图s?z=
noremap m mmHmt:%s///ge'tzt'm
映射q:e~/缓冲区
地图pp:SetLocalPaste!
函数!智能选项卡完成()
让line=getline('.')“当前行
让substr=strpart(第-1行,第('.')+1列)“从当前
光标的位置
让substr=matchstr(substr,[^\t]*$”)字直到光标

如果(strlen(substr)你的直觉是正确的。这一行来自你的完成函数

let substr = matchstr(substr, "[^ \t]*$")       " word till cursor
获取光标前面的所有非空白字符;
m/$variab

因为它包含斜线,然后触发文件完成,这自然不会考虑<代码> $变量< /> >

要解决此问题,您可以切换到仅匹配关键字字符(
\k*$
,默认完成情况会考虑这一点),但这可能会对文件完成情况产生负面影响

$second_var = $variabTAB
set history=700
filetype on
filetype indent on
set autoread
let mapleader = ","
let g:mapleader = ","
nmap <leader>w :w!<cr>
set so=7
set wildmenu
set wildignore=*.o,*~,*.pyc
set ruler
map <C-J> <C-W>j<C-W>_
map <C-K> <C-W>k<C-W>_
set winminheight=0
set winwidth=80
set cmdheight=2
set hid
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
set ignorecase
set smartcase
set nohlsearch
set incsearch
set lazyredraw
set magic
set showmatch
set matchtime=3
set mat=2
set noerrorbells
set novisualbell
set tm=500
set joinspaces
set nolist
set scrolloff=4
set foldminlines=1
set completeopt=menu
colorscheme desert
set background=dark
if has("gui_running")
    set guioptions-=T
    set guioptions+=e
    set t_Co=256
    set guitablabel=%M\ %t
endif
set guioptions=gmrLt
set guifont=Lucida_Consoloe:h8:cANSI
set encoding=utf8
set ffs=unix,dos,mac
set directory=./_backup
set backupdir=./.backup
set nowb
set noswapfile
set expandtab
set smarttab
set softtabstop=4
set smartindent
set nonumber
set nowarn
set shiftwidth=4
set tabstop=4
set lbr
set tw=500
set ai "Auto indent
set si "Smart indent
set wrap "Wrap lines
vnoremap <silent> * :call VisualSelection('f')<CR>
vnoremap <silent> # :call VisualSelection('b')<CR>
map <space> /
map <c-space> ?
map <silent> <leader><cr> :noh<cr>
map <leader>bd :Bclose<cr>
map <leader>ba :1,1000 bd!<cr>
map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
map <leader>cd :cd %:p:h<cr>:pwd<cr>
try
  set switchbuf=useopen,usetab,newtab
  set stal=2
catch
endtry
set laststatus=2
set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l
map 0 ^
vnoremap <silent> gv :call VisualSelection('gv')<CR>
map <leader>g :vimgrep // **/*.<left><left><left><left><left><left><left>
map <leader><space> :vimgrep // <C-R>%<C-A><right><right><right><right><right><right><right><right><right>
vnoremap <silent> <leader>r :call VisualSelection('replace')<CR>
map <leader>cc :botright cope<cr>
map <leader>co ggVGy:tabnew<cr>:set syntax=qf<cr>pgg
map <leader>n :cn<cr>
map <leader>p :cp<cr>
map <leader>ss :setlocal spell!<cr>
map <leader>sn ]s
map <leader>sp [s
map <leader>sa zg
map <leader>s? z=
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
map <leader>q :e ~/buffer<cr>
map <leader>pp :setlocal paste!<cr>
function! Smart_TabComplete()
  let line = getline('.')                         " current line
  let substr = strpart(line, -1, col('.')+1)      " from the start of the current
                                                  " of the cursor
  let substr = matchstr(substr, "[^ \t]*$")       " word till cursor
  if (strlen(substr)<2)                          " nothing to match on empty string
    return "\<tab>"
  endif
  let has_period = match(substr, '\.') != -1      " position of period, if any
  let has_slash = match(substr, '\/') != -1       " position of slash, if any
  if (!has_period && !has_slash)
    return "\<C-X>\<C-P>"                         " existing text matching
  elseif ( has_slash )
    return "\<C-X>\<C-F>"                         " file matching
  else
    return "\<C-X>\<C-O>"                         " plugin matching
  endif
endfunction

inoremap <tab> <c-r>=Smart_TabComplete()<CR>
let substr = matchstr(substr, "[^ \t]*$")       " word till cursor