我的VIM配置文件

最近几天写些东西,尽量的使用VIM,不论是在Linux下,还是在Win下。感觉越来越喜欢这个强大的“小”工具了。虽然以前也一直多少用一些,但没把它当回事,只是用一些简单的编辑功能。这回好好整理了一下配置文件,又翻了翻Learning the VI editor,已经开始入点门了。

现在把我的配置文件共享一下(~/.vimrc):


  1  " An example for a vimrc file.
  2  "
  3  " Maintainer:   Bram Moolenaar <Bram@vim.org>
  4  " Last change:  2002 Sep 19
  5  "
  6  " To use it, copy it to
  7  "     for Unix and OS/2:  ~/.vimrc
  8  "             for Amiga:  s:.vimrc
  9  "  for MS-DOS and Win32:  $VIM\_vimrc
 10  "           for OpenVMS:  sys$login:.vimrc
 11  
 12  " When started as "evim", evim.vim will already have done these settings.
 13  if v:progname =~? "evim"
 14    finish
 15  endif
 16  
 17  " Use Vim settings, rather then Vi settings (much better!).
 18  " This must be first, because it changes other options as a side effect.
 19  set nocompatible
 20  
 21  " allow backspacing over everything in insert mode
 22  set backspace=indent,eol,start
 23  
 24  "if has("vms")
 25  "  set nobackup         " do not keep a backup file, use versions instead
 26  "else
 27  "  set backup           " keep a backup file
 28  "endif
 29  set history=50          " keep 50 lines of command line history
 30  set ruler               " show the cursor position all the time
 31  set showcmd             " display incomplete commands
 32  set incsearch           " do incremental searching
 33  
 34  " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
 35  " let &guioptions = substitute(&guioptions, "t", "", "g")
 36  
 37  " Don't use Ex mode, use Q for formatting
 38  map Q gq
 39  
 40  " This is an alternative that also works in block mode, but the deleted
 41  " text is lost and it only works for putting the current register.
 42  "vnoremap p "_dp
 43  
 44  " Switch syntax highlighting on, when the terminal has colors
 45  " Also switch on highlighting the last used search pattern.
 46  if &t_Co > 2 || has("gui_running")
 47    syntax on
 48    set hlsearch
 49  endif
 50  
 51  " Only do this part when compiled with support for autocommands.
 52  if has("autocmd")
 53  
 54    " Enable file type detection.
 55    " Use the default filetype settings, so that mail gets 'tw' set to 72,
 56    " 'cindent' is on in C files, etc.
 57    " Also load indent files, to automatically do language-dependent indenting.
 58    filetype plugin indent on
 59  
 60    " Put these in an autocmd group, so that we can delete them easily.
 61    augroup vimrcEx
 62    au!
 63  
 64    " For all text files set 'textwidth' to 78 characters.
 65    autocmd FileType text setlocal textwidth=78
 66  
 67    " When editing a file, always jump to the last known cursor position.
 68    " Don't do it when the position is invalid or when inside an event handler
 69    " (happens when dropping a file on gvim).
 70    autocmd BufReadPost *
 71      \ if line("'\"") > 0 && line("'\"") <= line("$") |
 72      \   exe "normal g`\"" |
 73      \ endif
 74  
 75    augroup END
 76  
 77  else
 78  
 79    set autoindent                " always set autoindenting on
 80  
 81  endif " has("autocmd")
 82  set fileencodings=ucs-bom,utf-8,cp936,big5,euc-jp,euc-kr,latin1
 83  set mouse=a
 84  
 85  "   Edit another file in the same directory as the current file
 86  "   "   uses expression to extract path from current file's path
 87  "   "  (thanks Douglas Potts)
 88  if has("unix")
 89          map ,e :e <C-R>=expand("%:p:h") . "/" <CR>
 90  else
 91          map ,e :e <C-R>=expand("%:p:h") . "\" <CR>
 92  endif
 93  
 94  " lhs comments
 95  map ,# :s/^/#/<CR>
 96  map ,/ :s/^/\/\//<CR>
 97  map ,> :s/^/> /<CR>
 98  map ," :s/^/\"/<CR>
 99  map ,% :s/^/%/<CR>
100  map ,! :s/^/!/<CR>
101  map ,; :s/^/;/<CR>
102  map ,- :s/^/--/<CR>
103  map ,c :s/^\/\/\\|^--\\|^> \\|^[#"%!;]//<CR>
104  
105  " wrapping comments
106  map ,* :s/^\(.*\)$/\/\* \1 \*\//<CR>
107  map ,( :s/^\(.*\)$/\(\* \1 \*\)/<CR>
108  map ,< :s/^\(.*\)$/<!-- \1 -->/<CR>
109  map ,d :s/^\([/(]\*\\|<!--\) \(.*\) \(\*[/)]\\|-->\)$/\2/<CR> 
110  
111  set guifont=courier\ new
112  set number
113  set ruler
114  set wrap
115  
116  map <F12> :set number!<bar>set number?<CR>
117  map <F11> :set hls!<bar>set hls?<CR>
118  map <F9> :set wrap!<bar>set wrap?<CR>

这段代码是用Vim的2HTML转换的。另外我在.gvimrc中放了一句win 120 35,主要是为了打开gVIM时窗口不至于总是那么小。





0 条评论

添加评论