LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1130|回复: 1

交流自己最喜欢使用的vim命令与配置吧

[复制链接]
发表于 2005-4-26 12:39:57 | 显示全部楼层 |阅读模式
无双 loveunix.net
http://www.loveunix.net/bbs/inde ... amp;CODE=00&f=9

我:
C-N C-P 词完成
C-F 文件名完成 可以使用C-N C-P查找上一个 下一个
C-L 行完成

gg=G 代码对齐 (不喜欢写文章 不然可能会试用gggqG)
:%s/\s\+$//g    去掉行尾空格

:%s/\r//g  去掉^M形式的字符 ,另外请设置 set ffs=unix 保证vim不会自动转换^M成\n

然后是目录的打开与关闭了 zM zC cn等  这个写在vim配置文件中的 使用grep时很有用

偶尔也使用
C-E C-Y来复制上行 /下行的字

* # 快速查找
C-r C-w 复制词到命令行上

另外  偶尔使用ctags 进行跳转 但多数会使用cscope查找  
喜欢的插件是 a.vim 在.h与对应的c/cpp中切换
doxgen.vim 名字记不全 可以到vim.sf.net上查找dox插件 自动给函数添加doxgen格式注释的
bufexplore.vim winmanage.vim 完成文件列表与buf列表功能
taglist.vim 列出函数列表
还有c.vim 添加c类型的注释

喜欢使用配置文件中的命令 :
F3 F4 F5 F6 打开关闭代码块 看的方便

附 vim配置文件:

  1. set nocompatible
  2. source $VIMRUNTIME/vimrc_example.vim
  3. source $VIMRUNTIME/mswin.vim
  4. behave xterm
  5. set ffs=unix

  6. set diffexpr=MyDiff()
  7. function MyDiff()
  8.   let opt = '-a --binary '
  9.   if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  10.   if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  11.   let arg1 = v:fname_in
  12.   if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  13.   let arg2 = v:fname_new
  14.   if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  15.   let arg3 = v:fname_out
  16.   if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  17.   silent execute '!D:\tools\gnu\Vim\vim63\diff ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
  18. endfunction

  19. hi  HL_HiCurLine ctermfg=blue ctermbg=cyan guifg=blue guibg=cyan
  20. let HL_HiCurLine= "HL_HiCurLine"

  21. set formatoptions=tcrqn2
  22. set guifont=FixedsysTTF:h14   "如果没有这个字体那就不要加
  23. set tabstop=8
  24. set softtabstop=4
  25. set shiftwidth=4
  26. colorscheme ps_color            "在gvim下可以看到有多少coloscheme

  27. set lsp=0
  28. set sw=4      " shiftwidth
  29. set et        " expandtab
  30. "set wm=8      " wrapmargin
  31. set bs=2      " backspace
  32. set ru        " ruler
  33. set ic        " ignorecase      "忽略大小写 但是输入中有大写的话不忽略
  34. set is        " incsearch
  35. set scs       " smartcase: override the 'ic' when searching
  36. "     if search pattern contains uppercase char


  37. set wmnu
  38. set wildignore=*.bak,*.o,*.e,*~

  39. iab #i #include
  40. iab #d #define
  41. iab #e #endif

  42. set cst
  43. set csto=1
  44. "D:\tools\dev\Microsoft Visual Studio\VC98\MFC\Include\tags
  45. "D:\tools\dev\Microsoft Visual Studio\VC98\Include\tags
  46. "C:\Symbian\UIQ_21\epoc32\include\tags
  47. set tags=./tags,../tags,../../tags,../../../tags,D:/tools/dev/Microsoft\ Visual\ Studio/VC98/Include/tags
  48. set cspc=3  " show file path's last three part

  49. set grepprg=grep\ -nH

  50. map <F1>    :Tlist<cr>
  51. map <F2>    :WMToggle<cr>
  52. map <F3>    zO
  53. map <F4>    zc
  54. map <F5>    zR
  55. map <F6>    zM
  56. map <F7>    :cn<CR>

  57. "     
  58. set vb t_vb=  " set visual bell and disable screen flash
  59. set backup    " enable backup and define the backup file
  60. set backupext=.bak
  61. set hlsearch  " hlsearch
  62. " allow backspacing over everything in
  63. " the insert mode
  64. set backspace=indent,eol,start
  65. set dir=D:\tmp\vim
  66. " 设置swap文件的目录上面
  67. set backupdir=D:\tmp\vim
  68. "设置备份文件的目录上面 我不喜欢看到每个目录下都有备份 因为一般备份用不到


  69. "下面是设置自动folder的 而且是根据写C代码设置的 如果你不喜欢使用folder那么可以省略掉
  70. "au BufReadPost *.h,*.c,*.cpp,*.java,*.pl    syn region myFold start="{" end="}" transparent fold
  71. "au BufReadPost *.h,*.c,*.cpp,*.java,*.pl    syn sync fromstart
  72. "au BufReadPost *.h,*.c,*.cpp,*.java,*.pl    set foldmethod=syntax
  73. "set foldlevel=0
  74. set foldmarker={,}
  75. set foldmethod=marker
  76. set foldlevel=100 " Don't autofold anything (but I can still fold manually)
  77. set foldopen-=search " don't open folds when you search into them
  78. set foldopen-=undo " don't open folds when you undo stuff


  79. "-------------------------------------------------------------------------------
  80. " C-support.vim
  81. "-------------------------------------------------------------------------------
  82. let g:C_AuthorName   = 'Zhonglei Li'
  83. let g:C_AuthorRef    = ''
  84. let g:C_Email        = 'Zhonglei_Li@trendmicro.com.cn'
  85. let g:C_Company      = 'Trend Micro Incorporated'





  86. "-------------------------------------------------------------------------------
  87. "   copy from web
  88. "-------------------------------------------------------------------------------

  89. set history=1000 " How many lines of history to remember
  90. set cf " enable error files and error jumping
  91. set clipboard+=unnamed " turns out I do like is sharing windows clipboard
  92. set ffs=dos,unix,mac " support all three, in this order
  93. filetype plugin on " load filetype plugins
  94. set viminfo+=! " make sure it can save viminfo
  95. set isk+=_,$,@,%,#,- " none of these should be word dividers, so make them not be

  96. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  97. " Vim UI
  98. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  99. set lsp=0 " space it out a little more (easier to read)
  100. set wildmenu " turn on wild menu
  101. set ruler " Always show current positions along the bottom
  102. set cmdheight=1 " the command bar is 2 high
  103. "set number " turn on line numbers
  104. set lz " do not redraw while running macros (much faster) (LazyRedraw)
  105. "set hid " you can change buffer without saving
  106. set backspace=2 " make backspace work normal
  107. set whichwrap+=<,>,h,l  " backspace and cursor keys wrap to
  108. set mouse=a " use mouse everywhere
  109. set shortmess=atI " shortens messages to avoid 'press a key' prompt
  110. set report=0 " tell us when anything is changed via :...
  111. set noerrorbells " don't make noise
  112. " make the splitters between windows be blank
  113. set fillchars=vert:\ ,stl:\ ,stlnc:\

  114. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  115. " Visual Cues
  116. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  117. "set showmatch " show matching brackets
  118. "set mat=5 " how many tenths of a second to blink matching brackets for
  119. "set nohlsearch " do not highlight searched for phrases
  120. set incsearch " BUT do highlight as you type you search phrase
  121. set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$ " what to show when I hit :set list
  122. set lines=80 " 80 lines tall
  123. set columns=160 " 160 cols wide
  124. set so=0 " Keep 10 lines (top/bottom) for scope
  125. set novisualbell " don't blink
  126. set noerrorbells " no noises
  127. set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
  128. set laststatus=2 " always show the status line

  129. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  130. " Text Formatting/Layout
  131. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  132. set fo=tcrqn " See Help (complex)
  133. "set ai " autoindent
  134. "set si " smartindent
  135. "set cindent " do c-style indenting
  136. "set tabstop=8 " tab spacing (settings below are just to unify it)
  137. "set softtabstop=8 " unify
  138. "set shiftwidth=8 " unify
  139. "set noexpandtab " real tabs please!
  140. "set nowrap " do not wrap lines  
  141. "set smarttab " use tabs at the start of a line, spaces elsewhere

  142. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  143. " Folding
  144. "    Enable folding, but by default make it act like folding is off, because folding is annoying in anything but a few rare cases
  145. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  146. "set foldenable " Turn on folding
  147. "set foldmethod=indent " Make folding indent sensitive
  148. "set foldlevel=100 " Don't autofold anything (but I can still fold manually)
  149. "set foldopen-=search " don't open folds when you search into them
  150. "set foldopen-=undo " don't open folds when you undo stuff

  151. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  152. " File Explorer
  153. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  154. let g:explVertical=1 " should I split verticially
  155. let g:explWinSize=20 " width of 35 pixels

  156. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  157. " Win Manager
  158. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  159. let g:winManagerWidth=20 " How wide should it be( pixels)
  160. let g:winManagerWindowLayout = 'FileExplorer,TagsExplorer|BufExplorer' " What windows should it

  161. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  162. " CTags
  163. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  164. "let Tlist_Ctags_Cmd = $VIM.'\ctags.exe' " Location of ctags
  165. let Tlist_Sort_Type = "name" " order by
  166. "let Tlist_Use_Right_Window = 1 " split to the right side of the screen
  167. let Tlist_Compart_Format = 1 " show small meny
  168. let Tlist_Exist_OnlyWindow = 1 " if you are the last, kill yourself
  169. let Tlist_File_Fold_Auto_Close = 0 " Do not close tags for other files
  170. let Tlist_Enable_Fold_Column = 0 " Do not show folding tree

  171. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  172. " Minibuf
  173. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  174. "let g:miniBufExplTabWrap = 1 " make tabs show complete (no broken on two lines)
  175. "let g:miniBufExplModSelTarget = 1

  176. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  177. " Matchit
  178. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  179. let b:match_ignorecase = 1

  180. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  181. " Perl
  182. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  183. let perl_extended_vars=1 " highlight advanced perl vars inside strings

  184. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  185. " Custom Functions
  186. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  187. " Select range, then hit :SuperRetab($width) - by p0g and FallingCow
  188. function! SuperRetab(width) range
  189.         silent! exe a:firstline . ',' . a:lastline . 's/\v%(^ *)@<= {'. a:width .'}/\t/g'
  190. endfunction

  191. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  192. " Mappings
  193. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  194. "map <right> <ESC>:MBEbn<RETURN> " right arrow (normal mode) switches buffers  (excluding minibuf)
  195. "map <left> <ESC>:MBEbp<RETURN> " left arrow (normal mode) switches buffers (excluding minibuf)
  196. "map <up> <ESC>:Sex<RETURN><ESC><C-W><C-W> " up arrow (normal mode) brings up a file list
  197. "map <down> <ESC>:Tlist<RETURN> " down arrow  (normal mode) brings up the tag list
  198. "map <A-i> i <ESC>r " alt-i (normal mode) inserts a single char, and then switches back to normal
  199. "map <F2> <ESC>ggVG:call SuperRetab()<left>
  200. "map <F12> ggVGg? " encypt the file (toggle)

  201. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  202. " Autocommands
  203. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  204. "autocmd BufEnter * :syntax sync fromstart " ensure every file does syntax highlighting (full)
  205. "au BufNewFile,BufRead *.asp :set ft=aspjscript " all my .asp files ARE jscript
  206. "au BufNewFile,BufRead *.tpl :set ft=html " all my .tpl files ARE html
  207. "au BufNewFile,BufRead *.hta :set ft=html " all my .tpl files ARE html

  208. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  209. " Useful abbrevs
  210. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  211. "iab xasp <%@language=jscript%><CR><%<CR><TAB><CR><BS>%><ESC><<O<TAB>
  212. "iab xdate <c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>

复制代码
 楼主| 发表于 2005-4-26 12:41:09 | 显示全部楼层
喜欢的colorschems是 ps_color 习惯了 其它的应该也不错  如desert 不过没试
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表