Chinaunix首页 | 论坛 | 博客
  • 博客访问: 540761
  • 博文数量: 83
  • 博客积分: 6010
  • 博客等级: 准将
  • 技术积分: 1169
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-29 22:34
文章分类

全部博文(83)

文章存档

2011年(3)

2010年(29)

2009年(30)

2008年(21)

我的朋友

分类: LINUX

2010-01-25 16:23:08

参考了:
%E6%8A%8Avim%E6%89%93%E9%80%A0%E6%88%90%E4%B8%80%E4%B8%AA%E7%9C%9F%E6%AD%A3%E7%9A%84ide1.html

http://blog.csdn.net/tianxiaogang12/archive/2009/11/16/4817701.aspx

1,基本的vi设置

if(has("win32") || has("win95") || has("win64") || has("win16")) "判定当前操作系统类型
    let g:iswindows=1
else
    let g:iswindows=0
endif
set nocompatible "
不要vim模仿vi模式,建议设置,否则会有很多不兼容的问题
syntax on"打开高亮
if has("
autocmd")
    filetype plugin indent on "
根据文件进行缩进
    augroup vimrcEx
        
        autocmd FileType text setlocal textwidth=78
        autocmd BufReadPost *
                    \ if line("'\"") > 1 && line("'\"") <= line("$") | "实现打开同一文件时,vim能够自动记住上一次的位置
                    \ exe "normal! g`\"" |
                    \ endif
    augroup END
else
    set autoindent " always set autoindenting on "智能缩进,相应的有cindent,官方说autoindent可以支持各种文件的缩进,但是效果会比只?[mf " has("autocmd")
set tabstop=4 "让一个tab等于4个空格
set vb t_vb=
set nowrap "不自动换行
set hlsearch "高亮显示结果
set incsearch "在输入要搜索的文字时,vim会实时匹配
set backspace=indent,eol,start whichwrap+=<,>,[,] "允许退格键的使用
if(g:iswindows==1) "允许鼠标的使用
    "防止linux终端下无法拷贝
    if has('
mouse


2,让vi支持函数列表

2.1 安装

首先需要ctags支持,其次,
到 这里下载包,解压到~/.vim/之下

2.2 配置

在~/.vimrc中加入:

map <F12> :call Do_CsTag()<CR>
nmap <C-@>s :cs find s <C-R>=expand("")<CR><CR>:copen<CR>
nmap <C-@>g :cs find g <C-R>=expand("")<CR><CR>
nmap <C-@>c :cs find c <C-R>=expand("")<CR><CR>:copen<CR>
nmap <C-@>t :cs find t <C-R>=expand("")<CR><CR>:copen<CR>
nmap <C-@>e :cs find e <C-R>=expand("")<CR><CR>:copen<CR>
nmap <C-@>f :cs find f <C-R>=expand("")<CR><CR>:copen<CR>
nmap <C-@>i :cs find i ^<C-R>=expand("")<CR>$<CR>:copen<CR>
nmap <C-@>d :cs find d <C-R>=expand("")<CR><CR>:copen<CR>
function Do_CsTag()
    let dir = getcwd()
    if filereadable("tags")
        if(g:iswindows==1)
            let tagsdeleted=delete(dir."\\"."tags")
        else
            let tagsdeleted=delete("./"."tags")
        endif
        if(tagsdeleted!=0)
            echohl WarningMsg | echo "Fail to do tags! I cannot delete the tags" | echohl None
            return
        endif
    endif
    if has("cscope")
         execute "cs kill -1″
    endif
    if filereadable("
cscope.files")
        if(g:iswindows==1)
            let csfilesdeleted=delete(dir."
\\"."cscope.files")
        else
            let csfilesdeleted=delete("
./"."cscope.files")
        endif
        if(csfilesdeleted!=0)
            echohl WarningMsg | echo "
Fail to do I cannot delete the cscope.files" | echohl None
            return
        endif
    endif
    if filereadable("
cscope.out")
        if(g:iswindows==1)
            let csoutdeleted=delete(dir."
\\"."cscope.out")
        else
            let csoutdeleted=delete("
./"."cscope.out")
        endif
        if(csoutdeleted!=0)
            echohl WarningMsg | echo "
Fail to do I cannot delete the cscope.out" | echohl None
            return
        endif
    endif
    if(executable('ctags'))
        "
execute "!ctags -R –c-types=+p –fields=+S *"
         execute "!ctags -R –c++-kinds=+p –fields=+iaS –extra=+q ."
    endif
    if(executable('cscope') && has("cscope") )
        if(g:iswindows!=1)
             execute "!find . -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.cs' > cscope.files"
        else
             execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"
        endif
         execute "!cscope -b"
        execute "normal :"
        if filereadable("cscope.out")
            execute "cs add cscope.out"
        endif
    endif
endfunction

"进行Tlist的设置
"
TlistUpdate可以更新tags
map <F3> : Tlist<CR> "按下F3就可以呼出了
let Tlist_Ctags_Cmd='ctags' "
因为我们放在环境变量里,所以可以直接执行
let Tlist_Use_Right_Window=0 "让窗口显示在右边,0的话就是显示在左边
let Tlist_Show_One_File=0 "
让taglist可以同时展示多个文件的函数列表,如果想只有1个,设置为1
let Tlist_File_Fold_Auto_Close=1 "非当前文件,函数列表折叠隐藏
let Tlist_Exit_OnlyWindow=1 "
当taglist是最后一个分割窗口时,自动推出vim
"是否一直处理tags.1:处理;0:不处理
"
let Tlist_Process_File_Always=0

这样,在vi中按下F3就会在左边弹出函数列表

2.3 使用函数列表

2.3.1 切换函数列表的开、关
:TlistToggle。
或者F3(上面配置已经设置了F3为快捷键)

2.3.2 在正常编辑区域和函数列表区域中切换
ctrl+w+w。

2.3.3 定位指定内容
在tags区域中,把光标移动到变量、函数名称上,然后敲回车,就会自动在正常编辑区域中定位到指定内容了,很方便的。

在taglist窗口中,可以使用下面的快捷键:

          跳到光标下tag所定义的位置,用鼠标双击此tag功能也一样
o             在一个新打开的窗口中显示光标下tag
       显示光标下tag的原型定义
u             更新taglist窗口中的tag
s             更改排序方式,在按名字排序和按出现顺序排序间切换
x             taglist窗口放大和缩小,方便查看较长的tag
+             打开一个折叠,同zo
-             将tag折叠起来,同zc
*             打开所有的折叠,同zR
=             将所有tag折叠起来,同zM
[[            跳到前一个文件
]]            跳到后一个文件
q             关闭taglist窗口
          显示帮助


3,附件是我的以上vimrc的配置

文件:vimrc_wcw.zip
大小:1KB
下载:下载

阅读(1634) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~