Chinaunix首页 | 论坛 | 博客
  • 博客访问: 311544
  • 博文数量: 126
  • 博客积分: 7051
  • 博客等级: 少将
  • 技术积分: 1425
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-20 13:21
文章分类

全部博文(126)

文章存档

2008年(126)

我的朋友

分类: LINUX

2008-04-27 00:12:27

参考了很多的文章 和 vimrc 后自己根据别人的 vimrc 修改后, 定制了一个vimrc.

主要将一下, 定制的这个 vimrc 所支持的功能.

1:
engspchk(英文拼写检查, 此会 检查文件中英文拼写错误, 然后用 红色高亮显示, 对于 C 源文件来说, 他只会检查 注释中的编写错误, 而不会检查你的 函数), 下载地址:


安装说明:
在 Vim 网站上下载最新版本(engspchk.tar.gz);
使用“tar xvfz engspchk.tar.gz -C ~/.vim”解开;
在Vim中运行“:helptags ~/.vim/doc”安装文档。
提示替换拼写功能需要 agrep [4],可能需要另外下载安装。

功能说明:
一个Vim专用的拼写检查器,其最主要的特点是:

    可以通过变量 spchkdialect 选择英语变体(英国、美国、加拿大),对于找不到的词、不常见的词、不在当前英语变体中的词以不同的方式加亮显示;
    支持用户词典保存在 .vim/CVIMSYN 目录和项目词典(保存在被检查文件所在的目录中)
    对于源代码文件,只对注释进行拼写检查,而不会对你的变量名称胡乱提抗议;
    通过词典文件可支持除英语以外的其它语言。


\ec开始检查, \ee停止, \ea选着替换拼写. 脚本已经设置了可以检查一些文件..


273

(在此加上编号即可下载, 如次处273)

安装说明:

1. 确保机器上有一个可用的 Exuberant Ctags 的版本(可以执行命令“ctags”)

2. 在 Vim 网站上下载 taglist(假设为 taglist.zip);

3. 使用“unzip taglist.zip -d ~/.vim”解开;

4. 在 Vim 中运行“:helptags ~/.vim/doc”安装文档。

虽然 taglist 使用 ctags,但并不要求 tags 文件的存在。


功能说明:

使用命令“:Tlist”启用/关闭 taglist, 脚本中使用 F9 键开启和关闭, 此会在左侧开启一个窗口, 显示 你查看的 源文件 所定义的 宏, 函数等, 并且可以 点击转换到函数处... 很好用.


3:
69

安装说明:

1. 在 Vim 网站上下载最新版本(project-1.3.tar.gz);
2. 使用“tar xvfz project-1.3.tar.gz -C ~/.vim”解开;
3. 在 Vim 中运行“:helptags ~/.vim/doc”安装文档。

功能说明:

该插件可以把文件组织成一棵树的形式,以便于查找和管理。使用命令“:Project”即可打开一个用户的“项目文件”(~/.vimprojects)。项目文件采用普通的文本文件的形式,非常易于浏览和修改... 和上面的一样, 在左侧开启一个窗口, 但是快捷键我没有定义, 目前还用不到. 以上 :helptags ~/.vim/doc , 再vim中不用执行了, 可以放在 .vimrc 中... 放如 ~/.vim/doc 目录中, 视乎会自动查找到.



5:
安装了, 中文帮助手册, 当在vim中执行 :help 时会默认转到中文帮助去, 不过再 xterm 等不支持中文环境 会显示 乱码, 我定义了 快捷键 he 为英文, hc 为中文语言.

(中文)

下载的文件包应该是类似这样的: vimcdoc-1.5.0.tar.gz
解压后其中有个doc文件夹, 将其中的内容全部复制到~/.vim/doc, 或者vim安装目录下的doc目录中, 此时vim中的help信息已经是中文的了.


6:
  Ctags. 即上面, 2中 taglist, 所提到的 tags, 从名字上面就知道作用于C上, 配合 taglist 使用,可以列出 宏, 函数. 并且, 点击左窗口的 函数 或者 在源程序的函数上 Ctrl -]就可以实现自动跳转到你所调用的函数处, 强吧, 不然, 你想知道这个函数再哪里, grep目录, 或再程序中查找吧..

下载:

然后:

$ tar -xzvf ctags-5.6.tar.gz
$ cd ctags-5.6
$ make
# make install   // 需要root权限

然后去你的源码目录, 如果你的源码是多层的目录, 假设ctags解压在 ~/ctags下
$ cd ~/ctags
$ ctags -R
$ cp ~/ctags/tags ~/.vim/doc   //复制到 .vim 中, 因为系统会读取这个目录, 并且我在 .vimrc中也指定了 targs=~/.vim/doc/tags.

7:
  QuickFix 窗口 (不用安装, vim标准部分)
   主要用来不用推出  vim , 再内部执行 :make 编译源文件, 当出现错误时后, 在vim 的下半部分会指出 错误, 像 windows 下的 TC 编译器那样. :cw 调出窗口

:cn        // 切换到下一个结果, 错误处, 我绑定键为 F11
:cp        // 切换到上一个结果, 如上, 绑定了键为F12.

8:
快速浏览和操作Buffer -- 插件: MiniBufExplorer
下载地址
版本     6.3.2
安装     将下载的 minibufexpl.vim文件丢到 ~/.vim/plugin 文件夹中即可
手册     在minibufexpl.vim 文件的头部

编辑多文件时候, 在最上面显示一个 源文件列表, 可以用 Ctrl_w jk上去下来, tab键切换.

还有一些 小插件, 要不要也无所谓, 基本上工作的很好了, 可以阅读下 次文件, 我都加上了注释, 了解一下热键, 功能等, 以方便修改... 我最后面定义了一些 C 语言的 缩写, 以后边写程序 边 加进去就得了.


" ================================================
"       filename: ~/.vimrc
"       author: zyl
"       reference author: wuyongwei@gmail.com
"       email: zyl19861126@163.com
"       blog: www.gdzyl.cublog.cn
"       made in: 24/04/2008
" ================================================
" vim:shiftwidth=2:tabstop=8:expandtab
" """"""""""""""""""""""""""""""""""""""""""""""""
" ==> Both for vim and gvim.
" """"""""""""""""""""""""""""""""""""""""""""""""
" Remove ALL autocommands for the current group
" Mark .asm files MASM-type assembly
if has('autocmd')
  au!
  au BufNewFile,BufReadPre *.asm let b:asmsyntax='masm'
endif

" Enable filetype plugin .
" And use instead of
if has("eval") && has("insert_expand")
  filetype plugin on
  filetype indent on
endif

" Set helplang support chinese
if version >= 603
  set helplang=cn
  noremap hc :set helplang=cn
  noremap he :set helplang=en
endif

" Enable ctags for c, cpp.
set tags=~/.vim/doc/tags

" Quick switch buffer, use the MiniBufExplorer plugin
let g:minBufExplMapCTabSwitchBufs=1
let g:miniBufExplMapWindowNavVim=1
let g:miniBufExplMapWindowNavArrows=1

" Always show current position
set ruler

" some nice mapping to switch syntax (useful if on mixers
" different languages in one file)
" Enable syntax hl
syntax on
noremap   :set syntax=cheetah
noremap   :set syntax=xhtml
noremap   :set ft=javascript
noremap   :syntax sync fromstart

" Change buffer - whichout saving
set hid

" Show line number
set nu

" Set backspace
set backspace=eol,start,indent

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

" Highlight search thing and increase.
set hlsearch
set incsearch

" Auto indent and Smart indent
set ai
set si

" Enable folding, I find it very useful
set fen
set fdl=0

" Trun backup off and set noswapfile
" or backup a orig file
" set patchmode=.org
set nobackup
set nowb
set noar

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

" Wrap line
set wrap
set lbr

" Auto switch to current dir or arm to
noremap cd :cd %p:h
set autochdir

" Show matching bracet
set showmatch

" Set how many lines of history vim have to remember
set history=100

" Set mapleader, if not defined use for \.
" Now let us define mapleader instead of \ .
let mapleader=","
let g:mapleader=","

" set not compatible tradition's vi.
" and then use system's vimrc
" source $VIMRUNTIME/vimrc_example.vim
set nocompatible

" No sound on errors
set noerrorbells
set novisualbell
set t_vb=

" Statusline, 2 is alaws show, but would use some space
" The commandbar is 1 high
set cmdheight=1
set laststatus=2
set statusline=%<%f\ %h%m%r%=%k[%{(&fenc==\"\")?&enc:&fenc}%{(&bomb?\",BOM\":\"\")}]\ %-14.(%l,%c%V%)\ %P


" ==> Fileformat
" """""""""""""""""""""""""""""""""""""""
" Favorite filetype, example unix, dos
set fileencodings=ucs-bom,utf-8,gbk
set formatoptions+=mM
set ffs=unix,dos
nmap fd :set ff=dos
nmap fu :set ff=unix

" If you use vim in tty, uxterm -cjk or
" putty with option 'Treat CJK ambiguous
" characters as wide's on
if has('multi_byte') && v:version > 601
  if v:lang =~? '^\(zh\)\|\(ja\)\|\(ko\)'
    set ambiwidth=double
  endif
endif

" ==> Key mappings to ease browsing long lines
" """"""""""""""""""""""""""""""""""""""""""""
noremap           gj
noremap         gk
noremap        gj
noremap          gk
inoremap gj
inoremap    gk

" Split window
nmap wv v
nmap ws s
nmap wc c

" Key mappings for quick arithmetic inside Vim
" If not used, then use instead of
" And delete the mapleader.
nnoremap ,ma yypV:!calcu '"'k$
vnoremap ,ma yopV:!calcu '"'k$
vnoremap ,ma yopV:!calcu '"'k$
nnoremap ,mr yyV:!calcu '"'$
vnoremap ,mr ygvmaomb:r !calcu '"'"ay$dd`bv`a"ap

" Key mapping to stop the search highlight
nmap       :nohlsearch
imap :nohlsearch

" Key mapping for the taglist.vim plugin
nmap       :Tlist
imap :Tlist

" Key mappings for the quickfix commands
nmap :cn
nmap :cp

" Move a line of text using control
" nmap mz :m-2`z
nmap mz :m+`z

" Remove the windows ~M
noremap mr :%s/\r//g

" """""""""""""""""""""""""""""""""""""""
" ==> for the x window of gvim.
" """""""""""""""""""""""""""""""""""""""
if has('gui_running')
  " let do_syntax_sel_menu=1
  set guioptions-=m
  set guioptions-=T
  set guioptions-=l
  set guioptions-=L
  set guioptions-=r
  set guioptions-=R
  set guifont=Terminus\ 12
  colorscheme desert

  " Highlight cursorline
  if has("cursorline")
     set cursorline
     "hi cursorline guibg=#333333
     "hi CursorColumn guibg=#333333
  endif

  " If not define systerm lang
  " then define gvim encoding
  if  $LANG !~ '\.'
         set encoding=utf-8
  endif

  " Enable mouse of gvim
  if has('mouse')
         set mouse=a
  endif
endif

" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" ==> Non-GUI setting
" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if !has('gui_running')
  " Do not increase the windows width in the taglist.vim plugin
  " Enable filetype plugin
  if has('eval')
    let Tlist_Inc_Winwidth=0
  endif

  " Set text-mode menu
  if has('wildmenu')
    set wildmenu
    set cpoptions-=<
    set wildcharm=
    nmap       :emenu
    imap :emenu
  endif
endif

if has('autocmd')
  function! SetFileEncodings(encodings)
    let b:my_fileencodings_bak=&fileencodings
    let &fileencodings=a:encodings
  endfunction

  function! RestoreFileEncodings()
    let &fileencodings=b:my_fileencodings_bak
    unlet b:my_fileencodings_bak
  endfunction

  function! CheckFileEncoding()
    if &modified && &fileencoding != ''
      exec 'e! ++enc=' . &fileencoding
    endif
  endfunction

  function! ConvertHtmlEncoding(encoding)
    if a:encoding ==? 'gb2312'
      return 'gbk'              " GB2312 imprecisely means GBK in HTML
    elseif a:encoding ==? 'iso-8859-1'
      return 'latin1'           " The canonical encoding name in Vim
    elseif a:encoding ==? 'utf8'
      return 'utf-8'            " Other encoding aliases should follow here
    else
      return a:encoding
    endif
  endfunction

  function! DetectHtmlEncoding()
    if &filetype != 'html'
      return
    endif
    normal m`
    normal gg
    if search('\c') != 0
      let reg_bak=@"
      normal y$
      let charset=matchstr(@", 'text/html; charset=\zs[-A-Za-z0-9_]\+')
      let charset=ConvertHtmlEncoding(charset)
      normal ``
      let @"=reg_bak
      if &fileencodings == ''
        let auto_encodings=',' . &encoding . ','
      else
        let auto_encodings=',' . &fileencodings . ','
      endif
      if charset !=? &fileencoding &&
         \(auto_encodings =~ ',' . &fileencoding . ',' || &fileencoding == '')
        silent! exec 'e ++enc=' . charset
      endif
    else
      normal ``
    endif
  endfunction

  function! GnuIndent()
    setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1
    setlocal shiftwidth=4
    setlocal tabstop=8
  endfunction

  function! RemoveTrailingSpace()
    if $VIM_HATE_SPACE_ERRORS != '0' &&
          \(&filetype == 'c' || &filetype == 'cpp' || &filetype == 'vim')
      normal m`
      silent! :%s/\s\+$//e
      normal ``
    endif
  endfunction

  " Highlight space errors in C/C++ source files (Vim tip #935)
  if $VIM_HATE_SPACE_ERRORS != '0'
    let c_space_errors=1
  endif

  " Use Canadian spelling convention in engspchk (Vim script #195)
  let spchkdialect='can'

  " Show syntax highlighting attributes of character under cursor (Vim
  " script #383)
  map a :call SyntaxAttr()

  " Automatically find scripts in the autoload directory
  au FuncUndefined * exec 'runtime autoload/' . expand('') . '.vim'

  " File type related autosetting
  au FileType c,cpp setlocal cinoptions=:0,g0,(0,w1 shiftwidth=4 tabstop=8
  au FileType diff  setlocal shiftwidth=4 tabstop=4
  au FileType html  setlocal autoindent indentexpr=
  au FileType changelog setlocal textwidth=76

  " Text file encoding autodetection
  au BufReadPre  *.gb               call SetFileEncodings('gbk')
  au BufReadPre  *.big5             call SetFileEncodings('big5')
  au BufReadPre  *.nfo              call SetFileEncodings('cp437')
  au BufReadPost *.gb,*.big5,*.nfo  call RestoreFileEncodings()
  au BufWinEnter *.txt              call CheckFileEncoding()

  " Detect charset encoding in an HTML file
  au BufReadPost *.htm* nested      call DetectHtmlEncoding()

  " Recognize standard C++ headers
  au BufEnter /usr/include/c++/*    setf cpp
  au BufEnter /usr/include/g++-3/*  setf cpp

  " Setting for files following the GNU coding standard
  au BufEnter /usr/*                call GnuIndent()

  " Remove trailing spaces for C/C++ and Vim files
  au BufWritePre *                  call RemoveTrailingSpace()
endif

" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" ==> Define iabrev for C.
" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("eval") && has("autocmd")
  fun! c:()
   iab it int
   iab #d #define
   iab #i #include
   iab pr printf
   iab rn return
   iab tyf typedef
  endfun

  autocmd FileType c,cpp :call c:()
endif

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