txt文件怎么禁用supertab

Vim、Emacs配置和使用
回复
xopher
帖子: 31
注册时间: 2008-09-29 17:08

txt文件怎么禁用supertab

#1

帖子 xopher » 2011-07-29 14:56

我使用了omnicppcomplete和supertab,snipmate插件,在CPP这样的文件里面补全没问题;

但是我在txt文件里面,想输入一个tab的时候(在一个数字后面),就提示:
=<SNR>15_SuperTab('n')
omnifunc is not set

搞到输入tab方便。

下面是我的vimrc
[vim]

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 关闭 vi 兼容模式
set nocompatible

" Have the mouse enabled all the time:
set mouse=a

" Platform
function! MySys()
if has("unix")
return "linux"
elseif has("win32") || has("win64")
return "windows"
else
return "mac"
endif
endfunction

" 禁用 alt键
"set winaltkeys=no

" 设置编码
set enc=utf-8
" 设置文件编码
set fenc=utf-8
" 设置文件编码检测类型及支持格式
set fencs=ucs-bom,utf-8,cp936,gb18030,big5,gbk
language messages en_US.utf-8

" Enable filetype plugin
filetype plugin on
filetype indent on

" Set to auto read when a file is changed from the outside
set autoread

" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = ","
let g:mapleader = ","

" Fast saving
nmap <leader>w :w!<cr>

" Fast editing of the .vimrc
map <leader>e :e! ~/.vimrc<cr>

" When vimrc is edited, reload it
autocmd! bufwritepost vimrc source ~/.vimrc


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM userinterface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set 7 lines to the curors - when moving vertical..
set so=7

" Turn on WiLd menu
set wildmenu

" Always show current position
set ruler

" The commandbar height
set cmdheight=1

" Show line number
set number

" Do not redraw, when running macros.. lazyredraw
set nolazyredraw

" Change buffer - without saving
set hidden

" Set backspace
set backspace=eol,start,indent

" Bbackspace and cursor keys wrap to
set whichwrap+=<,>,h,l

" Ignore case when searching
set ignorecase
set incsearch

" Highlight search things
set hlsearch

" Make search act like search in modern browsers
set incsearch

" Don't redraw while executing macros
set nolazyredraw

" Set magic on, for regular expressions
set magic

" Show matching bracets when text indicator is over them
set showmatch

" How many tenths of a second to blink
set mat=2

" No sound on errors.
set noerrorbells
set novisualbell
set t_vb=
set tm=500

""""""""""""""""""""""""""""""
" Statusline
""""""""""""""""""""""""""""""
" Always hide the statusline
set laststatus=2

function! CurDir()
let curdir = substitute(getcwd(), '/home/randy/', "~/", "g")
return curdir
endfunction

" Format the statusline
set statusline=\ %F%m%r%h\ %w\ %r%{CurDir()}%h\ [%l/%L(%p%%):%c]\[%Y:%{&ff}:%{&fenc!=''?&fenc:&enc}]


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable syntax highlight
syntax enable

" Set font according to system
if MySys() == "linux"
set gfn=Monospace\ 11
elseif MySys() == "windows"
set gfn=Consolas:h12
elseif MySys() == "mac"
set gfn=Bitstream\ Vera\ Sans\ Mono:h14

if has("gui_running")
set nomacatsui
endif

set termencoding=macroman
endif

if has("gui_running")
set guioptions-=T
let psc_style='cool'
colorscheme koehler

" Set Windows Size
set lines=40 columns=120
else
set background=dark
colorscheme evening
endif

" Some nice mapping to switch syntax (useful if one mixes different languages in one file)
map <leader>1 :set syntax=xhtml<cr>
map <leader>2 :set syntax=python<cr>
map <leader>3 :set ft=javascript<cr>
map <leader>$ :syntax sync fromstart<cr>

autocmd BufEnter * :syntax sync fromstart

" Highlight current
if has("gui_running")
set cursorline
hi cursorline guibg=#003853
hi CursorColumn guibg=#003853
endif

" Omni menu colors
hi Pmenu guibg=#333333
hi PmenuSel guibg=#555555 guifg=#ffffff


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Fileformats
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Favorite filetypes
set ffs=unix,dos,mac

nmap <leader>fd :se ff=dos<cr>
nmap <leader>fu :se ff=unix<cr>
nmap <leader>fm :se ff=mac<cr>


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files and backups
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Turn backup off, since most stuff is in SVN, git anyway...
set nobackup
set nowb
set noswapfile


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set expandtab
set shiftwidth=4
set softtabstop=4

set tabstop=4
map <leader>t2 :set shiftwidth=2<cr>
map <leader>t4 :set shiftwidth=4<cr>
au FileType html,python,vim,javascript setl shiftwidth=2
au FileType html,python,vim,javascript setl tabstop=2
au FileType java setl shiftwidth=4
au FileType java setl tabstop=4

set smarttab

set lbr " 智能换行
set tw=500

" Auto indent
set autoindent
" Smart indet
set smartindent
" C-style indeting
set cindent
" C++ indeting
set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s
" Wrap lines
set wrap

"Tab configuration
try
set switchbuf=usetab
set stal=2
catch
endtry


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Folding
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Enable folding, I find it very useful
set nofoldenable " 禁止折叠
set foldmethod=syntax " 设置语法折叠
set foldcolumn=0 " 设置折叠区域的宽度
setlocal foldlevel=1 " 设置折叠层数为
" set foldclose=all " 设置为自动关闭折叠


""""""""""""""""""""""""""""""
" Visual
""""""""""""""""""""""""""""""
" From an idea by Michael Naumann
function! VisualSearch(direction) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", '\\/.*$^~[]')
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'b'
execute "normal ?" . l:pattern . "^M"
else
execute "normal /" . l:pattern . "^M"
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction

" Basically you press * or # to search for the current selection !! Really useful
vnoremap <silent> * :call VisualSearch('f')<CR>
vnoremap <silent> # :call VisualSearch('b')<CR>


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General Autocommands
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Switch to current dir
map <leader>cd :cd %:p:h<cr>


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Editing mappings etc.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remap VIM 0
map 0 ^

" Move a line of text using control
nmap <M-j> mz:m+<cr>`z
nmap <M-k> mz:m-2<cr>`z
vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z

if MySys() == "mac"
nmap <D-j> <M-j>
nmap <D-k> <M-k>
vmap <D-j> <M-j>
vmap <D-k> <M-k>
endif

func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
autocmd BufWrite *.py :call DeleteTrailingWS()


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MISC
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remove the Windows ^M
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm

" Paste toggle - when pasting something in, don't indent.
set pastetoggle=<F3>

" Remove indenting on empty lines
map <F2> :%s/\s*$//g<cr>:noh<cr>''

" Super paste
inoremap <C-v> <esc>:set paste<cr>mui<C-R>+<esc>mv'uV'v=:set nopaste<cr>


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Command-line config
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
func! Cwd()
let cwd = getcwd()
return "e " . cwd
endfunc

func! DeleteTillSlash()
let g:cmd = getcmdline()
if MySys() == "linux" || MySys() == "mac"
let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*", "\\1", "")
else
let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\]\\).*", "\\1", "")
endif
if g:cmd == g:cmd_edited
if MySys() == "linux" || MySys() == "mac"
let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*/", "\\1", "")
else
let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\\]\\).*\[\\\\\]", "\\1", "")
endif
endif
return g:cmd_edited
endfunc

func! CurrentFileDir(cmd)
return a:cmd . " " . expand("%:p:h") . "/"
endfunc


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Buffer realted
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Fast open a buffer by search for a name
map <c-q> :sb

" Open a dummy buffer for paste
map <leader>q :e ~/buffer<cr>

" Restore cursor to file position in previous editing session
set viminfo='10,\"100,:20,%,n~/.viminfo
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif

" Buffer - reverse everything ... :)
map <F9> ggVGg?

" Don't close window, when deleting a buffer
command! Bclose call <SID>BufcloseCloseIt()

function! <SID>BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")

if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif

if bufnr("%") == l:currentBufNum
new
endif

if buflisted(l:currentBufNum)
execute("bdelete! ".l:currentBufNum)
endif
endfunction


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin configuration
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" plugin - NERD_commenter.vim 注释代码用的
" ,c<space> " comment <--> uncomment
" ,cs " 简洁美观式注释.
" [count],cc 光标以下count行逐行添加注释(7,cc)
" [count],cu 光标以下count行逐行取消注释(7,cu)
" [count],cm 光标以下count行尝试添加块注释(7,cm)
" ,cA 在行尾插入 /* */,并且进入插入模式。 这个命令方便写注释。
" 注:count参数可选,无则默认为选中行或当前行
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let NERDSpaceDelims=1 " 让注释符与语句之间留一个空格
let NERDCompactSexyComs=1 " 多行注释时样子更好看

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Omni complete functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"autocmd FileType c set omnifunc=ccomplete#Complete
"autocmd FileType java set omnifunc=javacomplete#Complete
"autocmd FileType python set omnifunc=pythoncomplete#Complete
"autocmd FileType javascript set omnifunc=javascrīptcomplete#CompleteJS
"autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
"autocmd FileType css set omnifunc=csscomplete#CompleteCSS
"autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
"autocmd FileType php set omnifunc=phpcomplete#CompletePHP

"
setl omnifunc=nullcomplete#Complete
autocmd FileType * setl omnifunc=nullcomplete#Complete
autocmd FileType python setl omnifunc=pythoncomplete#Complete
autocmd FileType javascript setl omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html setl omnifunc=htmlcomplete#CompleteTags noci
autocmd FileType css setl omnifunc=csscomplete#CompleteCSS noci
autocmd FileType xml setl omnifunc=xmlcomplete#CompleteTags
autocmd FileType php setl omnifunc=phpcomplete#CompletePHP
autocmd FileType c setl omnifunc=ccomplete#Complete

" Set completement for C++
autocmd FileType h setl omnifunc=cppcomplete#Complete
autocmd FileType cpp setl omnifunc=cppcomplete#Complete

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Ctags
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 自动切换到当前目录
set autochdir
" configure tags - add additional tags here or comment out not-used ones
set tags+=~/.vim/tags/cpp
" add current directory's generated tags file to available tags
set tags+=./tags
" set tags+=~/.vim/tags/gl
" set tags+=~/.vim/tags/sdl
" set tags+=~/.vim/tags/qt4
" build tags of your own project with Ctrl-F12
"map <C-F12> :!ctags -R --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
"map <C-F12> :!ctags -R --c++-kinds=+pl --fields=+iaS --extra=+q .<CR>
" Set F12 to use ctags for C++
map <F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" OmniCppComplete
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let OmniCpp_NamespaceSearch = 1
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters
let OmniCpp_MayCompleteDot = 1 " autocomplete after .
let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
" let OmniCpp_SelectFirstItem = 2 " select first item (but don't insert)

" automatically open and close the popup menu / preview window
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
set completeopt=menu,menuone


" superTab
let g:SuperTabRetainCompletionType=2
" 0 - 不记录上次的补全方式
" 1 - 记住上次的补全方式,直到用其他的补全命令改变它
" 2 - 记住上次的补全方式,直到按ESC退出插入模式为止
let g:SuperTabDefaultCompletionType="<C-X><C-O>"
" let g:SuperTabLeadingSpaceCompletion=0
[/vim]
头像
adam8157
帖子: 2794
注册时间: 2009-03-05 16:31
联系:

Re: txt文件怎么禁用supertab

#2

帖子 adam8157 » 2011-07-29 14:58

两种方法,

1, Ctrl-v, tab

2, :set paste, tab
头像
lilydjwg
论坛版主
帖子: 4258
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: txt文件怎么禁用supertab

#3

帖子 lilydjwg » 2011-07-29 15:41

第三种:在 txt 文件类型时 unmap <Tab>
头像
fanhe
帖子: 2357
注册时间: 2007-03-24 23:45

Re: txt文件怎么禁用supertab

#4

帖子 fanhe » 2011-07-29 17:37

supertab 默认用 <C-Tab> 代替 <Tab> 的, 你用 <C-Tab> 就行了, 只要不用终端的 vim 的话

其实建议楼主不要乱用 supertab, 熟悉的话自己写简单的 supertab 更好控制, 我是用自己的 supertab 的 :em04

我不用 supertab 的, 给你参考下我的
[vim]inoremap <C-Tab> <Tab>
inoremap <silent> <Tab> <C-r>=<SID>i_Tab_plus()<CR>
inoremap <silent> <expr> <S-Tab> pumvisible()?"\<C-p>":"\<C-d>"


function! s:i_Tab_plus()
let preChar = getline('.')[col('.') - 2]
if pumvisible()
" return "\<Down>"
return "\<C-n>"
elseif preChar == '' || preChar =~ '\s'
return "\<Tab>"
elseif (getline('.')[col('.') - 3] == '-' && preChar == '>') || preChar == '.'
" return "\<C-x>\<C-o>\<C-r>=I_OnPopupPost()\<CR>"
return "\<C-x>\<C-o>"
elseif &ft ==# 'c' || &ft ==# 'cpp'
return "\<C-n>"
else
" call feedkeys("\<C-x>\<C-n>" . "\<C-r>=I_OnPopupPost()\<CR>", 'n')
" return ''
" return "\<C-x>\<C-n>\<C-r>=I_OnPopupPost()\<CR>"
return "\<C-x>\<C-n>"
endif
endf
[/vim]
xopher
帖子: 31
注册时间: 2008-09-29 17:08

Re: txt文件怎么禁用supertab

#5

帖子 xopher » 2011-07-29 21:42

我也觉得SuperTab接管的事太多了,只管普通的代码文档的补全就好,其他的不要它管。
头像
lilydjwg
论坛版主
帖子: 4258
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: txt文件怎么禁用supertab

#6

帖子 lilydjwg » 2011-07-29 22:06

xopher 写了:我也觉得SuperTab接管的事太多了,只管普通的代码文档的补全就好,其他的不要它管。
人家是 super 嘛 :em02
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: txt文件怎么禁用supertab

#7

帖子 eexpress » 2011-07-29 22:51

Vundle or Pathogen, 插件管理器。
autocmd FileType tex :AcpDisable

This should disable the auto completion for tex files.
我记得看过类似的,是容易设置的。只是自己没试过。
● 鸣学
xopher
帖子: 31
注册时间: 2008-09-29 17:08

Re: txt文件怎么禁用supertab

#8

帖子 xopher » 2011-07-30 0:37

把SuperTab卸了,改改OmniCppComplete的配置就好了,可以用了。
回复