在vim配置中filetype plugin indent on到底有何作用?

Vim、Emacs配置和使用
回复
hugUbuntu
帖子: 141
注册时间: 2009-06-10 9:51

在vim配置中filetype plugin indent on到底有何作用?

#1

帖子 hugUbuntu » 2009-10-23 21:53

我在vimrc若添加filetype plugin indent on,则我的omnicomplete就无法找到匹配模式,就是c语言中普通的匹配。
若去掉这句,则我添加注释时:
如:
/*
*
*
*/
输入一个*,按回车,就无法出现自动出现一个*并对齐,我确实被这个filetype plugin indent on弄晕了,到底如何配置才能让我的
omnicomplete可以找到匹配模式,也同时让我的注释自动匹配!
等待高手指教!
头像
lilydjwg
论坛版主
帖子: 4249
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: 在vim配置中filetype plugin indent on到底有何作用?

#2

帖子 lilydjwg » 2009-10-23 22:14

indent on就是按 indent 目录下的脚本自动缩进,
plugin on就是允许执行 ftplugin 目录下的文件类型特定的脚本。
你可以试试

代码: 全选

filetype plugin off
filetype indent on
我在vimrc若添加filetype plugin indent on,则我的omnicomplete就无法找到匹配模式,就是c语言中普通的匹配。
我不清楚为什么会这样子,以及具体表现是怎样的。我这里一切正常。
hugUbuntu
帖子: 141
注册时间: 2009-06-10 9:51

Re: 在vim配置中filetype plugin indent on到底有何作用?

#3

帖子 hugUbuntu » 2009-10-23 22:32

lilydjwg 写了:indent on就是按 indent 目录下的脚本自动缩进,
plugin on就是允许执行 ftplugin 目录下的文件类型特定的脚本。
你可以试试

代码: 全选

filetype plugin off
filetype indent on
我在vimrc若添加filetype plugin indent on,则我的omnicomplete就无法找到匹配模式,就是c语言中普通的匹配。
我不清楚为什么会这样子,以及具体表现是怎样的。我这里一切正常。
明白了,lilydjwg兄,能否把你的vimrc借小弟一观?
头像
lilydjwg
论坛版主
帖子: 4249
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: 在vim配置中filetype plugin indent on到底有何作用?

#4

帖子 lilydjwg » 2009-10-24 0:25

hugUbuntu 写了: 明白了,lilydjwg兄,能否把你的vimrc借小弟一观?
那可是大观啊!

代码: 全选

" 原有设置[[[1
set nocompatible
source $VIMRUNTIME/vimrc_example.vim

set diffexpr=MyDiff()
function MyDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  let eq = ''
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      let cmd = '""' . $VIMRUNTIME . '\diff"'
      let eq = '"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
"]]]
" 我的设置
 " 函数[[[1
 "   关闭某个窗口[[[2
function Lilydjwg_close(winnr)
  let winnum = bufwinnr(a:winnr)
  if winnum == -1
    return 0
  endif
  " Goto the workspace window, close it and then come back to the
  " original window
  let curbufnr = bufnr('%')
  exe winnum . 'wincmd w'
  close
  " Need to jump back to the original window only if we are not
  " already in that window
  let winnum = bufwinnr(curbufnr)
  if winnr() != winnum
    exe winnum . 'wincmd w'
  endif
  return 1
endfunction
 "  取得光标处的匹配[[[2
function Lilydjwg_get_pattern_at_cursor(pat)
  let col = col('.') - 1
  let line = getline('.')
  let ebeg = -1
  let cont = match(line, a:pat, 0)
  while (ebeg >= 0 || (0 <= cont) && (cont <= col))
    let contn = matchend(line, a:pat, cont)
    if (cont <= col) && (col < contn)
      let ebeg = match(line, a:pat, cont)
      let elen = contn - ebeg
      break
    else
      let cont = match(line, a:pat, contn)
    endif
  endwh
  if ebeg >= 0
    return strpart(line, ebeg, elen)
  else
    return ""
  endif
endfunction
 "  平台判断[[[2
function Lilydjwg_haswin32()
  if (has("win32") || has("win95") || has("win64") || has("win16"))
    return 1
  else
    return 0
  endif
endfunction
 "   KWD---打开/关闭对应的 .kwd 文件[[[2
function Lilydjwg_KWD(ft)
  if a:ft != ''
    exe 'vs ~/.vim/kwd/'.a:ft.'.kwd'
    set columns+=20
    exe "normal! \<C-W>L20\<C-W>|\<C-W>W"
  else
    if Lilydjwg_close('*.kwd')
      set columns-=20
    endif
  endif
endfunction
 "   WsOpen [[[2
function Lilydjwg_ws(...)
  if g:Ws_File != ""
    WsToggle
  else
    if a:1 != ""
      exe "WsOpen ~/.vim/workspace/".a:1
    else
      exe "WsOpen ~/.vim/workspace/ws1"
    endif
  endif
endfunction
 "   切换配色方案[[[2
function Lilydjwg_toggle_color()
  let colors = ['pink_lily', 'lilypink', 'lilac', 'spring']
  try
    let i = index(colors, g:colors_name)
    let i = (i+1) % len(colors)
  catch /E121/
    let i = 0
  endtry
  exe 'colorscheme ' . get(colors, i)
endfunction
 "   草稿buffer[[[2
"   受Emacs的启发而作
function! Lilydjwg_scratch()
  " FIXME 在一个会话期内保存文本
  sil split \[Scratch\]
  set ft=scratch
endfunction
"   %xx -> 对应的字符(到消息)[[[2
function Lilydjwg_hexchar()
  let chars = Lilydjwg_get_pattern_at_cursor('\(%[[:xdigit:]]\{2}\)\+')
  if chars == ''
    echohl WarningMsg
    echo '在光标处未发现%表示的十六进制字符串!'
    echohl None
    return
  endif
  let str = substitute(chars, '%', '\\x', 'g')
  exe 'py print ''' . str . ''''
endfunction
"   字符 -> %xx,取代当前选区 [[[2
function Lilydjwg_strhex(str)
  python << EOF
import vim
s = vim.eval('a:str')
l = ''
for i in s:
  l += '%' + hex(ord(i))[2:].rjust(2, '0')
vim.command("let ret = '"+l+"'")
EOF
  exe 'normal gvs' . ret
endfunction
 "   在插入模式下用Tab实现补全[[[2
function! CleverTab()
  if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
    return "\<Tab>"
  else
    return "\<C-P>"
  endif
endfunction
inoremap <Tab> <C-R>=CleverTab()<CR>
 "  将 C 风格缩进改成我喜欢的缩进[[[2
function Lilydjwg_no_CStyle()
  normal mxgg
  " 行首的 {
  let s:found=1
  while s:found
    let s:found = search('^\v\s*\{','W','',1000)
    if s:found
      " 含代码和注释者
      s/\v(^\s*)@<=\{(\s*((\S[^\/'"]+)|('[^']*')|("[^"]*"))+)(\s*)((\/\/|\/\*).*)/ \2\7\8/e
      " 只含注释者
      s/\v(^\s*)@<=\{(\s*)((\/\/|\/\*).*)/\2 \3/e
      " 只含代码者
      s/\v(^\s*)@<=\{(\s*)(\S.*)/\2 \3/e
      " 只含 { 者
      s/\v^\s*\{\s*$\n//e
      normal k
      " 把 { 移到上一行
      s/\v(\s*((\/\/|\/\*).*)?$)/\{\1/
    endif
  endwhile
  " 行末的 } 前有代码
  normal gg
  let s:found=1
  while s:found
    let s:found = search('\v;\s*\}','W','',1000)
    if s:found
      s/\}//
      normal o}
      normal ==
    endif
  endwhile
  " 孤单的 else
  normal gg
  let s:found=1
  while s:found
    let s:found = search('^\s*else\s*$','W','',1000)
    if s:found
      normal kJx
    endif
  endwhile
  unlet s:found
  normal `x
endfunction
 "  用火狐打开链接[[[2
function Lilydjwg_open_url()
  let s:url = Lilydjwg_get_pattern_at_cursor('\v(https?://|ftp://|file:/{3}|www\.)((\w|-)+\.)+(\w|-)+(:\d+)?(/(\w|[~@#$%^&+=/.?-])+)?')
  if s:url == ""
    echohl WarningMsg
    echomsg '在光标处未发现URL!'
    echohl None
  else
    echo '打开URL:' . s:url
    if !Lilydjwg_haswin32()
      " call system("gnome-open " . s:url)
      call system("setsid firefox '" . s:url . "' &")
    else
      call system("start '" . s:url . "'")
    endif
  endif
  unlet s:url
endfunction
 "  Title Save [[[2
function Lilydjwg_TSave()
  let line = getline(1)
  if line =~ '^\s*$'
    let line = getline(2)
  endif
  let line = substitute(line, '[:/\\]', '-', 'g')
  let line = substitute(line, '^\s\+', '', 'g')
  let line = substitute(line, '\s\+$', '', 'g')
  let line = substitute(line, ' ', '\\ ', 'g')
  let line = substitute(line, '\r', '', 'g')
  exe 'w ' . line . '.txt'
  " echo line
  unlet line
endfunction
 "  切换 ve [[[2
function Lilydjwg_toggle_ve()
  if &ve == 'all'
    let &ve = ''
  else
    let &ve = 'all'
  endif
endfunction
 "  切换 ambiwidth [[[2
function Lilydjwg_toggle_ambiwidth()
  if &ambiwidth == 'double'
    let &ambiwidth = 'single'
  else
    let &ambiwidth = 'double'
  endif
endfunction
 "  重新载入 mark.vim 的高亮 [[[2
"     因为 .gvimrc、启动命令等 在脚本之后执行,而配色方案文件会清除高亮
function Lilydjwg_remark()
  highlight def MarkWord1  ctermbg=Cyan     ctermfg=Black  guibg=#8CCBEA    guifg=Black
  highlight def MarkWord2  ctermbg=Green    ctermfg=Black  guibg=#A4E57E    guifg=Black
  highlight def MarkWord3  ctermbg=Yellow   ctermfg=Black  guibg=#FFDB72    guifg=Black
  highlight def MarkWord4  ctermbg=Red      ctermfg=Black  guibg=#FF7272    guifg=Black
  highlight def MarkWord5  ctermbg=Magenta  ctermfg=Black  guibg=#FFB3FF    guifg=Black
  highlight def MarkWord6  ctermbg=Blue     ctermfg=Black  guibg=#9999FF    guifg=Black
endfunction
 " set 相关[[[1
set viminfo='100,:1000,<50,s10,h
set history=1000
set wildmenu
set wildmode=longest:full
cnoremap <Left> <Space><BS><Left>
cnoremap <Right> <Space><BS><Right>
set ambiwidth=double
set cursorline
set diffopt+=vertical,context:3
set fileencodings=ucs-bom,utf-8,gb18030,cp936,latin1
set diffexpr=
set errorfile=/home/lilydjwg/tmpfs/error
set grepprg=grep\ -nH\ $*
set keywordprg=:help
set mousemodel=popup
set formatoptions=croqn2mB1
set guioptions=egmrLtai
set helplang=cn
" 没必要,而且很多时候 = 表示赋值
set isfname-==
set nolinebreak
set nowrapscan
set scrolloff=5
set sessionoptions=blank,buffers,curdir,folds,help,options,tabpages,winsize,slash,unix,resize
set shell=/bin/bash
set term=xterm-256color
set shiftwidth=2
set winaltkeys=no
set columns=88
set lines=38
set noequalalways
set listchars=eol:$,tab:>-,nbsp:~
set completeopt+=longest

 " map 相关[[[1
 "   nmap [[[2
"     Fx 相关 [[[3
nmap <F4> :hid e #<CR>
nmap <F6> :cnext<CR>
nmap <S-F6> :cprevious<CR>
nmap <F8> :mks! ~/TODO/
nmap <F11> :next<CR>
nmap <S-F11> :previous<CR>
nmap <C-F12> :lcd %:p:h<CR>:!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
"     重新载入当前文件
nmap <F5> :e!<CR>
"     保存所有并编译当前文件
nmap <C-F5> :wa<CR>:mak<CR>
"     编译好后,运行编译的文件
nmap <S-F5> :!./"%<"<CR>
"     用默认的程序打开文件
nmap <C-S-F5> :!gnome-open "%"<CR>
"     t 开头 [[[3
nmap t= mxHmygg=G`yzt`x
nmap t{ A{{{1<ESC>
nmap tO O<ESC>
nmap ta ggVG
nmap <silent> tf :call Lilydjwg_open_url()<CR>
"     清除高亮
nmap <silent> th :nohls<CR>
nmap tj Jx
nmap tl ^v$h
nmap tm :MarksBrowser<CR>
nmap to o<ESC>
nmap tp "+P
nmap ts tadtp:TSave<CR>
nmap tt :tabnew<CR>
nmap <silent> tv :call Lilydjwg_toggle_ve()<CR>
nmap tw :call Lilydjwg_toggle_ambiwidth()<CR>
"     w 开头 [[[3
nmap wc :set cursorline!<CR>
nmap wd :vertical diffsplit 
nmap wf :FilesystemExplorer<CR>
nmap wn :set number!<CR>
nmap w<Space> :WsToggle<CR>
nnoremap <silent> wt :TlistToggle<CR>
"     - 开头 [[[3
nmap -+ :set nomodified<CR>
nmap -c :TColor<CR>
nmap -ft :exe 'tabe ~/.vim/ftplugin/'.&ft.'.vim'<CR>
nmap -syn :exe 'tabe ~/.vim/syntax/'.&ft.'.vim'<CR>
"     显示高亮组 [[[4
nnoremap wh :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
"     Meta [[[3
nmap <unique> <silent> <M-L> <Plug>LookupFile
nmap <silent> <M-f> :echo expand('%:p')<CR>
"     打开草稿
nmap <silent> <M-s> :call Lilydjwg_scratch()<CR>
" lusty-explorer [[[4
"   <M-b>不能用 :BufferExplorer,因为它已经被 bufexplorer 用了
nmap <M-b> <Leader>lb
nmap <M-l> :FilesystemExplorerFromHere<CR>
"     其它开头的 [[[3
nmap <BS> <C-O>
nmap <C-D> :q<CR>
nnoremap <Space> za
nmap ' <C-W>
nmap 'm :MarksBrowser<CR>
nmap :: :!
nnoremap +x :!chmod +x <C-R>=expand("%:p")<CR><CR>
nmap cd :silent lcd %:p:h<CR>:echo expand('%:p:h')<CR>
nmap gb :set fenc=gb18030<CR>
nmap z<Space> i <ESC>
 "   imap [[[2
inoremap <S-CR> <CR>    
inoremap <S-Tab> <C-N>
imap <S-BS> <C-W>
cmap <S-BS> <C-W>
"     日期和时间 [[[3
imap <F5> <C-R>=strftime("%Y年%m月%d日")<CR><ESC>:sil s/[年月]\@<=0//ge<CR>thhf日a
imap <S-F5> <C-R>=strftime("%Y-%m-%d")<CR>
imap <C-F5> <C-R>=strftime("%Y-%m-%d %H:%M")<CR>
"     补全 [[[3
imap <F2> <C-X><C-O>
imap <F3> <C-X><C-F>
imap <S-F3> <C-X><C-L>
imap <F7> <C-X><C-V>
 "   vmap [[[2
"     删除空行 [[[3
vmap x :s/^\s*$\n<CR>:nohls<CR>
"     快速查找 [[[3
vmap v y/\V<C-R>"<CR>
vmap <S-V> y?\V<C-R>"<CR>
"     括号和中文引号 [[[3
" 有了 surround.vim 就不用它们了
" vmap ( <ESC>`>a)<ESC>`<i(<ESC>
" vmap ) <ESC>`<i(<ESC>`>la)<ESC>
vmap “ <ESC>`<i“<ESC>`>a”<ESC>
vmap ” <ESC>`>a”<ESC>`<i“<ESC>
 "   cmap [[[2
"     常用的目录 [[[3
cmap <C-T> ~/tmpfs/
cmap <C-X> /media/soft/home/home/private/
 "   各模式下都有的 [[[2
"     gj & gk
nmap <M-j> gj
nmap <M-k> gk
vmap <M-j> gj
vmap <M-k> gk
 "   surround [[[2
"      比起 c,我更喜欢用 s
vmap c <Plug>Vsurround
vmap C <Plug>VSurround
"      原 cs 和 cscope 的冲突了
nmap cS <Plug>Csurround
"     以 % 表示的字符 [[[3
nmap <silent> t% :call Lilydjwg_hexchar()<CR>
vmap <silent> t% y:call Lilydjwg_strhex(@")<CR>
"     Ctrl-S 保存文件 [[[3
nmap <C-S> :w<CR>
imap <C-S> <ESC>:w<CR>
vmap <C-S> <ESC>:w<CR>
"     快速隐藏当前窗口内容[[[3
nmap <F12> :tabnew<CR>
imap <F12> <ESC>:tabnew<CR>
vmap <F12> <ESC>:tabnew<CR>
"     Shift+鼠标滚动[[[3
"     FIXME 不要在当前窗口滚动,而是在鼠标所在的窗口滚动
nmap <silent> <S-MouseDown> zhzhzh
nmap <silent> <S-MouseUp> zlzlzl
vmap <silent> <S-MouseDown> zhzhzh
vmap <silent> <S-MouseUp> zlzlzl
 " 自动命令[[[1
"   自动关闭预览窗口(不能用在命令窗口,所以指定了文件类型)
autocmd InsertLeave	*.c,*.cpp,*.h,*.php,*.py,scripts/py/* if pumvisible() == 0|pclose|endif
autocmd VimEnter,ColorScheme	* call Lilydjwg_remark()

" 自定义命令[[[1
command Set tabe ~/.vimrc
command TColor call Lilydjwg_toggle_color()
command -nargs=1 So runtime so/<args>.vim
command -nargs=? Ws sil call Lilydjwg_ws("<args>")
"   读取命令内容并将其插入到当前光标下
command -nargs=1 -complete=command ReadCommand redir @">|exe "<args>"|normal $p:redir END<CR>
"   删除空行
command DBlank :g/^\s*$/d
"   以第一行的文字为名保存当前文件
command TSave call Lilydjwg_TSave()
command -nargs=1 Template e ~/.vim/templates/template.<args>
command -nargs=? -complete=file RSplit vs <args>|normal <C-W>L<C-W>w
"   将 C++ 注释转为 C 注释
command FScreen winpos 0 0|set lines=40|set columns=172
command SQuote %s/“\|”/"/ge|%s/‘\|’/'/ge
command RJ e /media/soft/home/home/private/日记/2009.rj|normal gg
" FIXME 不知为什么,“集”字会导致乱码
" command DDJ e /media/soft/home/home/private/点滴集|normal gg
nnoremap 'd :e /media/soft/home/home/private/点滴集<CR>gg
"   载入 kwd 文件
command -nargs=? KWD silent call Lilydjwg_KWD("<args>")
"   用 VimExplorer 插件打开当前文件所在的目录
command Path VE %:p:h
command CS call Lilydjwg_no_CStyle()
command CD silent cd %:p:h
command Hex silent !setsid ghex2 '%'
command SHELL silent cd %:p:h|silent exe '!setsid gnome-terminal'|silent cd -
"   第一次缓冲区里有文章;以后每次有两行空行,方便粘贴
command EnPublicMailBoxHandler exe 'normal :TS\<CR>tadto'
command ClsXML %s/></>\r</g|normal t=:DBlank<CR>
command -nargs=1 Enc e ++enc=<args> %
command CPP w|exe '!g++ -g "%:p" -o "%:p:r" 2> ' . &errorfile | cfile

 " 其它命令[[[1
colorscheme pink_lily
"   workspace
let Ws_File = '~/.vim/workspace/ws1'
let Ws_Auto_Save = 1
"   Align
let g:Align_xstrlen = 3
"   xml.vim,使所有的标签都关闭
let xml_use_xhtml = 1
"   2html.vim, 使用XHTML格式
let use_xhtml = 1
"   VimIm,不要更改弹出菜单的颜色
let g:vimim_menu_color = 1
let g:netrw_list_hide = '^\.[^.].*'
let g:VEConf_showHiddenFiles = 0
let g:EnhCommentifyRespectIndent = 'Yes'
let g:EnhCommentifyUseSyntax = 'Yes'
let g:EnhCommentifyPretty = 'Yes'
let g:EnhCommentifyBindInInsert = 'No'
let g:LookupFile_DisableDefaultMap = 1
let g:LookupFile_MinPatLength = 2
let g:LookupFile_DefaultCmd = ':LUWalk'
let g:LookupFile_PreserveLastPattern = 0
let g:LookupFile_AlwaysAcceptFirst = 1
let g:LookupFile_AllowNewFiles = 0
"   fcitx [[[1
let g:inputtoggle = 0
function Fcitx2en()
  let s:inputstatus = system("fcitx-remote")
  if s:inputstatus == 2
    let g:inputtoggle = 1
    let l:a = system("fcitx-remote -c")
  endif
endfunction
function Fcitx2zh()
  let s:inputstatus = system("fcitx-remote")
  if s:inputstatus != 2 && g:inputtoggle == 1
    let l:a = system("fcitx-remote -o")
    let g:inputtoggle = 0
  endif
endfunction
autocmd! InsertLeave * call Fcitx2en()
autocmd! InsertEnter * call Fcitx2zh()
 " cscope setting [[[1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 " 设置 [[[2
if has("cscope")
  " set csprg=/usr/bin/cscope
  set csto=1
  set cst
  set cscopequickfix=s-,c-,d-,i-,t-,e-
endif

" add any database in current directory
function Lilydjwg_csadd()
  set nocsverb
  if filereadable(expand('%:h:p') . "/cscope.out")
    exe 'cs add ' . expand('%:h:p') . '/cscope.out'
  elseif filereadable("cscope.out")
    cs add cscope.out
  endif
  set csverb
endfunction

autocmd BufRead *.c,*.cpp,*.h call Lilydjwg_csadd()

 " 映射 [[[2
" 查找C语言符号,即查找函数名、宏、枚举值等出现的地方
nmap css :cs find s <C-R>=expand("<cword>")<CR><CR>
" 查找函数、宏、枚举等定义的位置,类似ctags所提供的功能
nmap csg :cs find g <C-R>=expand("<cword>")<CR><CR>
" 查找本函数调用的函数
nmap csd :cs find d <C-R>=expand("<cword>")<CR><CR>
" 查找调用本函数的函数
nmap csc :cs find c <C-R>=expand("<cword>")<CR><CR>
" 查找指定的字符串
nmap cst :cs find t <C-R>=expand("<cword>")<CR><CR>
" 查找egrep模式,相当于egrep功能,但查找速度快多了
nmap cse :cs find e <C-R>=expand("<cword>")<CR><CR>
" 查找并打开文件,类似vim的find功能
nmap csf :cs find f <C-R>=expand("<cfile>")<CR><CR>
" 查找包含本文件的文件
nmap csi :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
" 生成新的数据库
nmap csn :lcd %:p:h<CR>:!my_cscope<CR>
" 自己来输入命令
nmap cs<Space> :cs find 
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" vim:fdm=marker:fmr=[[[,]]]

希望其中没有涉及隐私,呵呵。
说明一下,很多设置是和某插件/软件相关的
hugUbuntu
帖子: 141
注册时间: 2009-06-10 9:51

Re: 在vim配置中filetype plugin indent on到底有何作用?

#5

帖子 hugUbuntu » 2009-10-24 12:23

lilydjwg 写了:
hugUbuntu 写了: 明白了,lilydjwg兄,能否把你的vimrc借小弟一观?
那可是大观啊!

代码: 全选

" 原有设置[[[1
set nocompatible
source $VIMRUNTIME/vimrc_example.vim

set diffexpr=MyDiff()
function MyDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  let eq = ''
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      let cmd = '""' . $VIMRUNTIME . '\diff"'
      let eq = '"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
"]]]
" 我的设置
 " 函数[[[1
 "   关闭某个窗口[[[2
function Lilydjwg_close(winnr)
  let winnum = bufwinnr(a:winnr)
  if winnum == -1
    return 0
  endif
  " Goto the workspace window, close it and then come back to the
  " original window
  let curbufnr = bufnr('%')
  exe winnum . 'wincmd w'
  close
  " Need to jump back to the original window only if we are not
  " already in that window
  let winnum = bufwinnr(curbufnr)
  if winnr() != winnum
    exe winnum . 'wincmd w'
  endif
  return 1
endfunction
 "  取得光标处的匹配[[[2
function Lilydjwg_get_pattern_at_cursor(pat)
  let col = col('.') - 1
  let line = getline('.')
  let ebeg = -1
  let cont = match(line, a:pat, 0)
  while (ebeg >= 0 || (0 <= cont) && (cont <= col))
    let contn = matchend(line, a:pat, cont)
    if (cont <= col) && (col < contn)
      let ebeg = match(line, a:pat, cont)
      let elen = contn - ebeg
      break
    else
      let cont = match(line, a:pat, contn)
    endif
  endwh
  if ebeg >= 0
    return strpart(line, ebeg, elen)
  else
    return ""
  endif
endfunction
 "  平台判断[[[2
function Lilydjwg_haswin32()
  if (has("win32") || has("win95") || has("win64") || has("win16"))
    return 1
  else
    return 0
  endif
endfunction
 "   KWD---打开/关闭对应的 .kwd 文件[[[2
function Lilydjwg_KWD(ft)
  if a:ft != ''
    exe 'vs ~/.vim/kwd/'.a:ft.'.kwd'
    set columns+=20
    exe "normal! \<C-W>L20\<C-W>|\<C-W>W"
  else
    if Lilydjwg_close('*.kwd')
      set columns-=20
    endif
  endif
endfunction
 "   WsOpen [[[2
function Lilydjwg_ws(...)
  if g:Ws_File != ""
    WsToggle
  else
    if a:1 != ""
      exe "WsOpen ~/.vim/workspace/".a:1
    else
      exe "WsOpen ~/.vim/workspace/ws1"
    endif
  endif
endfunction
 "   切换配色方案[[[2
function Lilydjwg_toggle_color()
  let colors = ['pink_lily', 'lilypink', 'lilac', 'spring']
  try
    let i = index(colors, g:colors_name)
    let i = (i+1) % len(colors)
  catch /E121/
    let i = 0
  endtry
  exe 'colorscheme ' . get(colors, i)
endfunction
 "   草稿buffer[[[2
"   受Emacs的启发而作
function! Lilydjwg_scratch()
  " FIXME 在一个会话期内保存文本
  sil split \[Scratch\]
  set ft=scratch
endfunction
"   %xx -> 对应的字符(到消息)[[[2
function Lilydjwg_hexchar()
  let chars = Lilydjwg_get_pattern_at_cursor('\(%[[:xdigit:]]\{2}\)\+')
  if chars == ''
    echohl WarningMsg
    echo '在光标处未发现%表示的十六进制字符串!'
    echohl None
    return
  endif
  let str = substitute(chars, '%', '\\x', 'g')
  exe 'py print ''' . str . ''''
endfunction
"   字符 -> %xx,取代当前选区 [[[2
function Lilydjwg_strhex(str)
  python << EOF
import vim
s = vim.eval('a:str')
l = ''
for i in s:
  l += '%' + hex(ord(i))[2:].rjust(2, '0')
vim.command("let ret = '"+l+"'")
EOF
  exe 'normal gvs' . ret
endfunction
 "   在插入模式下用Tab实现补全[[[2
function! CleverTab()
  if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
    return "\<Tab>"
  else
    return "\<C-P>"
  endif
endfunction
inoremap <Tab> <C-R>=CleverTab()<CR>
 "  将 C 风格缩进改成我喜欢的缩进[[[2
function Lilydjwg_no_CStyle()
  normal mxgg
  " 行首的 {
  let s:found=1
  while s:found
    let s:found = search('^\v\s*\{','W','',1000)
    if s:found
      " 含代码和注释者
      s/\v(^\s*)@<=\{(\s*((\S[^\/'"]+)|('[^']*')|("[^"]*"))+)(\s*)((\/\/|\/\*).*)/ \2\7\8/e
      " 只含注释者
      s/\v(^\s*)@<=\{(\s*)((\/\/|\/\*).*)/\2 \3/e
      " 只含代码者
      s/\v(^\s*)@<=\{(\s*)(\S.*)/\2 \3/e
      " 只含 { 者
      s/\v^\s*\{\s*$\n//e
      normal k
      " 把 { 移到上一行
      s/\v(\s*((\/\/|\/\*).*)?$)/\{\1/
    endif
  endwhile
  " 行末的 } 前有代码
  normal gg
  let s:found=1
  while s:found
    let s:found = search('\v;\s*\}','W','',1000)
    if s:found
      s/\}//
      normal o}
      normal ==
    endif
  endwhile
  " 孤单的 else
  normal gg
  let s:found=1
  while s:found
    let s:found = search('^\s*else\s*$','W','',1000)
    if s:found
      normal kJx
    endif
  endwhile
  unlet s:found
  normal `x
endfunction
 "  用火狐打开链接[[[2
function Lilydjwg_open_url()
  let s:url = Lilydjwg_get_pattern_at_cursor('\v(https?://|ftp://|file:/{3}|www\.)((\w|-)+\.)+(\w|-)+(:\d+)?(/(\w|[~@#$%^&+=/.?-])+)?')
  if s:url == ""
    echohl WarningMsg
    echomsg '在光标处未发现URL!'
    echohl None
  else
    echo '打开URL:' . s:url
    if !Lilydjwg_haswin32()
      " call system("gnome-open " . s:url)
      call system("setsid firefox '" . s:url . "' &")
    else
      call system("start '" . s:url . "'")
    endif
  endif
  unlet s:url
endfunction
 "  Title Save [[[2
function Lilydjwg_TSave()
  let line = getline(1)
  if line =~ '^\s*$'
    let line = getline(2)
  endif
  let line = substitute(line, '[:/\\]', '-', 'g')
  let line = substitute(line, '^\s\+', '', 'g')
  let line = substitute(line, '\s\+$', '', 'g')
  let line = substitute(line, ' ', '\\ ', 'g')
  let line = substitute(line, '\r', '', 'g')
  exe 'w ' . line . '.txt'
  " echo line
  unlet line
endfunction
 "  切换 ve [[[2
function Lilydjwg_toggle_ve()
  if &ve == 'all'
    let &ve = ''
  else
    let &ve = 'all'
  endif
endfunction
 "  切换 ambiwidth [[[2
function Lilydjwg_toggle_ambiwidth()
  if &ambiwidth == 'double'
    let &ambiwidth = 'single'
  else
    let &ambiwidth = 'double'
  endif
endfunction
 "  重新载入 mark.vim 的高亮 [[[2
"     因为 .gvimrc、启动命令等 在脚本之后执行,而配色方案文件会清除高亮
function Lilydjwg_remark()
  highlight def MarkWord1  ctermbg=Cyan     ctermfg=Black  guibg=#8CCBEA    guifg=Black
  highlight def MarkWord2  ctermbg=Green    ctermfg=Black  guibg=#A4E57E    guifg=Black
  highlight def MarkWord3  ctermbg=Yellow   ctermfg=Black  guibg=#FFDB72    guifg=Black
  highlight def MarkWord4  ctermbg=Red      ctermfg=Black  guibg=#FF7272    guifg=Black
  highlight def MarkWord5  ctermbg=Magenta  ctermfg=Black  guibg=#FFB3FF    guifg=Black
  highlight def MarkWord6  ctermbg=Blue     ctermfg=Black  guibg=#9999FF    guifg=Black
endfunction
 " set 相关[[[1
set viminfo='100,:1000,<50,s10,h
set history=1000
set wildmenu
set wildmode=longest:full
cnoremap <Left> <Space><BS><Left>
cnoremap <Right> <Space><BS><Right>
set ambiwidth=double
set cursorline
set diffopt+=vertical,context:3
set fileencodings=ucs-bom,utf-8,gb18030,cp936,latin1
set diffexpr=
set errorfile=/home/lilydjwg/tmpfs/error
set grepprg=grep\ -nH\ $*
set keywordprg=:help
set mousemodel=popup
set formatoptions=croqn2mB1
set guioptions=egmrLtai
set helplang=cn
" 没必要,而且很多时候 = 表示赋值
set isfname-==
set nolinebreak
set nowrapscan
set scrolloff=5
set sessionoptions=blank,buffers,curdir,folds,help,options,tabpages,winsize,slash,unix,resize
set shell=/bin/bash
set term=xterm-256color
set shiftwidth=2
set winaltkeys=no
set columns=88
set lines=38
set noequalalways
set listchars=eol:$,tab:>-,nbsp:~
set completeopt+=longest

 " map 相关[[[1
 "   nmap [[[2
"     Fx 相关 [[[3
nmap <F4> :hid e #<CR>
nmap <F6> :cnext<CR>
nmap <S-F6> :cprevious<CR>
nmap <F8> :mks! ~/TODO/
nmap <F11> :next<CR>
nmap <S-F11> :previous<CR>
nmap <C-F12> :lcd %:p:h<CR>:!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
"     重新载入当前文件
nmap <F5> :e!<CR>
"     保存所有并编译当前文件
nmap <C-F5> :wa<CR>:mak<CR>
"     编译好后,运行编译的文件
nmap <S-F5> :!./"%<"<CR>
"     用默认的程序打开文件
nmap <C-S-F5> :!gnome-open "%"<CR>
"     t 开头 [[[3
nmap t= mxHmygg=G`yzt`x
nmap t{ A{{{1<ESC>
nmap tO O<ESC>
nmap ta ggVG
nmap <silent> tf :call Lilydjwg_open_url()<CR>
"     清除高亮
nmap <silent> th :nohls<CR>
nmap tj Jx
nmap tl ^v$h
nmap tm :MarksBrowser<CR>
nmap to o<ESC>
nmap tp "+P
nmap ts tadtp:TSave<CR>
nmap tt :tabnew<CR>
nmap <silent> tv :call Lilydjwg_toggle_ve()<CR>
nmap tw :call Lilydjwg_toggle_ambiwidth()<CR>
"     w 开头 [[[3
nmap wc :set cursorline!<CR>
nmap wd :vertical diffsplit 
nmap wf :FilesystemExplorer<CR>
nmap wn :set number!<CR>
nmap w<Space> :WsToggle<CR>
nnoremap <silent> wt :TlistToggle<CR>
"     - 开头 [[[3
nmap -+ :set nomodified<CR>
nmap -c :TColor<CR>
nmap -ft :exe 'tabe ~/.vim/ftplugin/'.&ft.'.vim'<CR>
nmap -syn :exe 'tabe ~/.vim/syntax/'.&ft.'.vim'<CR>
"     显示高亮组 [[[4
nnoremap wh :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
"     Meta [[[3
nmap <unique> <silent> <M-L> <Plug>LookupFile
nmap <silent> <M-f> :echo expand('%:p')<CR>
"     打开草稿
nmap <silent> <M-s> :call Lilydjwg_scratch()<CR>
" lusty-explorer [[[4
"   <M-b>不能用 :BufferExplorer,因为它已经被 bufexplorer 用了
nmap <M-b> <Leader>lb
nmap <M-l> :FilesystemExplorerFromHere<CR>
"     其它开头的 [[[3
nmap <BS> <C-O>
nmap <C-D> :q<CR>
nnoremap <Space> za
nmap ' <C-W>
nmap 'm :MarksBrowser<CR>
nmap :: :!
nnoremap +x :!chmod +x <C-R>=expand("%:p")<CR><CR>
nmap cd :silent lcd %:p:h<CR>:echo expand('%:p:h')<CR>
nmap gb :set fenc=gb18030<CR>
nmap z<Space> i <ESC>
 "   imap [[[2
inoremap <S-CR> <CR>    
inoremap <S-Tab> <C-N>
imap <S-BS> <C-W>
cmap <S-BS> <C-W>
"     日期和时间 [[[3
imap <F5> <C-R>=strftime("%Y年%m月%d日")<CR><ESC>:sil s/[年月]\@<=0//ge<CR>thhf日a
imap <S-F5> <C-R>=strftime("%Y-%m-%d")<CR>
imap <C-F5> <C-R>=strftime("%Y-%m-%d %H:%M")<CR>
"     补全 [[[3
imap <F2> <C-X><C-O>
imap <F3> <C-X><C-F>
imap <S-F3> <C-X><C-L>
imap <F7> <C-X><C-V>
 "   vmap [[[2
"     删除空行 [[[3
vmap x :s/^\s*$\n<CR>:nohls<CR>
"     快速查找 [[[3
vmap v y/\V<C-R>"<CR>
vmap <S-V> y?\V<C-R>"<CR>
"     括号和中文引号 [[[3
" 有了 surround.vim 就不用它们了
" vmap ( <ESC>`>a)<ESC>`<i(<ESC>
" vmap ) <ESC>`<i(<ESC>`>la)<ESC>
vmap “ <ESC>`<i“<ESC>`>a”<ESC>
vmap ” <ESC>`>a”<ESC>`<i“<ESC>
 "   cmap [[[2
"     常用的目录 [[[3
cmap <C-T> ~/tmpfs/
cmap <C-X> /media/soft/home/home/private/
 "   各模式下都有的 [[[2
"     gj & gk
nmap <M-j> gj
nmap <M-k> gk
vmap <M-j> gj
vmap <M-k> gk
 "   surround [[[2
"      比起 c,我更喜欢用 s
vmap c <Plug>Vsurround
vmap C <Plug>VSurround
"      原 cs 和 cscope 的冲突了
nmap cS <Plug>Csurround
"     以 % 表示的字符 [[[3
nmap <silent> t% :call Lilydjwg_hexchar()<CR>
vmap <silent> t% y:call Lilydjwg_strhex(@")<CR>
"     Ctrl-S 保存文件 [[[3
nmap <C-S> :w<CR>
imap <C-S> <ESC>:w<CR>
vmap <C-S> <ESC>:w<CR>
"     快速隐藏当前窗口内容[[[3
nmap <F12> :tabnew<CR>
imap <F12> <ESC>:tabnew<CR>
vmap <F12> <ESC>:tabnew<CR>
"     Shift+鼠标滚动[[[3
"     FIXME 不要在当前窗口滚动,而是在鼠标所在的窗口滚动
nmap <silent> <S-MouseDown> zhzhzh
nmap <silent> <S-MouseUp> zlzlzl
vmap <silent> <S-MouseDown> zhzhzh
vmap <silent> <S-MouseUp> zlzlzl
 " 自动命令[[[1
"   自动关闭预览窗口(不能用在命令窗口,所以指定了文件类型)
autocmd InsertLeave	*.c,*.cpp,*.h,*.php,*.py,scripts/py/* if pumvisible() == 0|pclose|endif
autocmd VimEnter,ColorScheme	* call Lilydjwg_remark()

" 自定义命令[[[1
command Set tabe ~/.vimrc
command TColor call Lilydjwg_toggle_color()
command -nargs=1 So runtime so/<args>.vim
command -nargs=? Ws sil call Lilydjwg_ws("<args>")
"   读取命令内容并将其插入到当前光标下
command -nargs=1 -complete=command ReadCommand redir @">|exe "<args>"|normal $p:redir END<CR>
"   删除空行
command DBlank :g/^\s*$/d
"   以第一行的文字为名保存当前文件
command TSave call Lilydjwg_TSave()
command -nargs=1 Template e ~/.vim/templates/template.<args>
command -nargs=? -complete=file RSplit vs <args>|normal <C-W>L<C-W>w
"   将 C++ 注释转为 C 注释
command FScreen winpos 0 0|set lines=40|set columns=172
command SQuote %s/“\|”/"/ge|%s/‘\|’/'/ge
command RJ e /media/soft/home/home/private/日记/2009.rj|normal gg
" FIXME 不知为什么,“集”字会导致乱码
" command DDJ e /media/soft/home/home/private/点滴集|normal gg
nnoremap 'd :e /media/soft/home/home/private/点滴集<CR>gg
"   载入 kwd 文件
command -nargs=? KWD silent call Lilydjwg_KWD("<args>")
"   用 VimExplorer 插件打开当前文件所在的目录
command Path VE %:p:h
command CS call Lilydjwg_no_CStyle()
command CD silent cd %:p:h
command Hex silent !setsid ghex2 '%'
command SHELL silent cd %:p:h|silent exe '!setsid gnome-terminal'|silent cd -
"   第一次缓冲区里有文章;以后每次有两行空行,方便粘贴
command EnPublicMailBoxHandler exe 'normal :TS\<CR>tadto'
command ClsXML %s/></>\r</g|normal t=:DBlank<CR>
command -nargs=1 Enc e ++enc=<args> %
command CPP w|exe '!g++ -g "%:p" -o "%:p:r" 2> ' . &errorfile | cfile

 " 其它命令[[[1
colorscheme pink_lily
"   workspace
let Ws_File = '~/.vim/workspace/ws1'
let Ws_Auto_Save = 1
"   Align
let g:Align_xstrlen = 3
"   xml.vim,使所有的标签都关闭
let xml_use_xhtml = 1
"   2html.vim, 使用XHTML格式
let use_xhtml = 1
"   VimIm,不要更改弹出菜单的颜色
let g:vimim_menu_color = 1
let g:netrw_list_hide = '^\.[^.].*'
let g:VEConf_showHiddenFiles = 0
let g:EnhCommentifyRespectIndent = 'Yes'
let g:EnhCommentifyUseSyntax = 'Yes'
let g:EnhCommentifyPretty = 'Yes'
let g:EnhCommentifyBindInInsert = 'No'
let g:LookupFile_DisableDefaultMap = 1
let g:LookupFile_MinPatLength = 2
let g:LookupFile_DefaultCmd = ':LUWalk'
let g:LookupFile_PreserveLastPattern = 0
let g:LookupFile_AlwaysAcceptFirst = 1
let g:LookupFile_AllowNewFiles = 0
"   fcitx [[[1
let g:inputtoggle = 0
function Fcitx2en()
  let s:inputstatus = system("fcitx-remote")
  if s:inputstatus == 2
    let g:inputtoggle = 1
    let l:a = system("fcitx-remote -c")
  endif
endfunction
function Fcitx2zh()
  let s:inputstatus = system("fcitx-remote")
  if s:inputstatus != 2 && g:inputtoggle == 1
    let l:a = system("fcitx-remote -o")
    let g:inputtoggle = 0
  endif
endfunction
autocmd! InsertLeave * call Fcitx2en()
autocmd! InsertEnter * call Fcitx2zh()
 " cscope setting [[[1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 " 设置 [[[2
if has("cscope")
  " set csprg=/usr/bin/cscope
  set csto=1
  set cst
  set cscopequickfix=s-,c-,d-,i-,t-,e-
endif

" add any database in current directory
function Lilydjwg_csadd()
  set nocsverb
  if filereadable(expand('%:h:p') . "/cscope.out")
    exe 'cs add ' . expand('%:h:p') . '/cscope.out'
  elseif filereadable("cscope.out")
    cs add cscope.out
  endif
  set csverb
endfunction

autocmd BufRead *.c,*.cpp,*.h call Lilydjwg_csadd()

 " 映射 [[[2
" 查找C语言符号,即查找函数名、宏、枚举值等出现的地方
nmap css :cs find s <C-R>=expand("<cword>")<CR><CR>
" 查找函数、宏、枚举等定义的位置,类似ctags所提供的功能
nmap csg :cs find g <C-R>=expand("<cword>")<CR><CR>
" 查找本函数调用的函数
nmap csd :cs find d <C-R>=expand("<cword>")<CR><CR>
" 查找调用本函数的函数
nmap csc :cs find c <C-R>=expand("<cword>")<CR><CR>
" 查找指定的字符串
nmap cst :cs find t <C-R>=expand("<cword>")<CR><CR>
" 查找egrep模式,相当于egrep功能,但查找速度快多了
nmap cse :cs find e <C-R>=expand("<cword>")<CR><CR>
" 查找并打开文件,类似vim的find功能
nmap csf :cs find f <C-R>=expand("<cfile>")<CR><CR>
" 查找包含本文件的文件
nmap csi :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
" 生成新的数据库
nmap csn :lcd %:p:h<CR>:!my_cscope<CR>
" 自己来输入命令
nmap cs<Space> :cs find 
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" vim:fdm=marker:fmr=[[[,]]]

希望其中没有涉及隐私,呵呵。
说明一下,很多设置是和某插件/软件相关的
ok,收到!^-^,你的vimrc比我强悍!学习了!
回复