Chinaunix

标题: [共享交流]请交出你的vimrc [打印本页]

作者: lovesaka    时间: 2006-09-11 21:10
标题: [共享交流]请交出你的vimrc
用VIM朋友如果你们愿意的话可以把你们vimrc里的一些常用配置和一些技巧贴出来大家一起共享和学习
以便使我们的vim功能更加强大写程序时更加得心应手
我先来点

基本的缩进和语言加亮

  1. set syntax=on
  2. set cinoptions+={2,0,p0,t0
  3. set nobackup
  4. set cindent
  5. set syntax=cpp
  6. set formatoptions=tcqr
复制代码


自定义文件头

  1. function Mytitle()
  2. call setline(1,"/**********************************************")
  3. call append(line("."),"作者:自己名字")
  4. call append(line(".")+1,"时间:".strftime("%c"))
  5. call append(line(".")+2,"文件名:".expand("%"))
  6. call append(line(".")+3,"描述:")
  7. call append(line(".")+4,"**********************************************/")
  8. endf
  9. map <home> <Esc>:call Mytitle()<CR><Esc>:$<Esc>o      "<home>键可改为你喜欢的按键
复制代码


K&R式代码格式化

  1. map <F5>   <Esc>:1,$g/^$/d<CR><Esc>gg=G<Esc>gg    "<f5>键可改为你喜欢的按键
复制代码


增加注解

  1. map <F2>   <Esc><S-$>a<TAB>/**/<Esc>2ha         
复制代码


如果你原意的话那么就跟贴吧

[ 本帖最后由 lovesaka 于 2006-9-11 21:27 编辑 ]
作者: flw2    时间: 2006-09-11 21:14
我还不会,我一般就是用那个自带的
作者: lovesaka    时间: 2006-09-11 21:16
不会没关系会用就行了
ctrl+c会吧复制到你的vimrc里
试试效果吧
作者: lovesaka    时间: 2006-09-11 21:19
哈哈
大家一起来不如果你觉得好用的就ctrl+c复制下去提高你的VIM效率
最好给点说明是干什么用的

[ 本帖最后由 lovesaka 于 2006-9-11 21:22 编辑 ]
作者: safedead    时间: 2006-09-11 21:41
学习

我以前只用过这句
set cindent
用来自动缩进和加亮C/C++
作者: flw    时间: 2006-09-11 21:48
我的:
  1. set nobackup
  2. set noswapfile
  3. set helplang=Cn

  4. set autoindent
  5. set cindent

  6. set tabstop=4
  7. set softtabstop=4
  8. set shiftwidth=4
  9. set expandtab
  10. set smarttab

  11. set foldenable
  12. set fdm=marker

  13. nmap <F5> ^W_^W\|
  14. nmap <F6> ^W=
  15. imap <F5> <ESC>^W_^W\|a
  16. imap <F6> <ESC>^W=a
  17. nmap gF ^Wf
复制代码

上面是我的 XP 的,Debian 下的 vim 的默认配置是出了名的差,所以就需要多设置几句:
  1. set expandtab
  2. set shiftwidth=4
  3. set tabstop=4
  4. set softtabstop=4
  5. set nobackup
  6. set cindent
  7. set autoindent
  8. set showcmd
  9. set helplang=Cn
  10. set nofoldenable
  11. set noswapfile
  12. set number
  13. set mouse=nv
  14. set hlsearch
  15. set incsearch
  16. set viminfo+=h

  17. set nocp
  18. filetype plugin on

  19. autocmd FileType perl set keywordprg=perldoc\ -f

  20. nmap <F5> ^W_^W\|
  21. nmap <F6> ^W=
  22. imap <F5> <ESC>^W_^W\|a
  23. imap <F6> <ESC>^W=a
  24. nmap gF ^Wf

  25. syntax on

  26. colorscheme evening
  27. hi Normal ctermfg=grey ctermbg=black
  28. hi Visual ctermfg=green ctermbg=black
  29. hi Search term=reverse cterm=standout ctermfg=green  ctermbg=yellow
  30. hi IncSearch term=reverse cterm=standout ctermfg=green ctermbg=yellow
  31. hi PmenuSel ctermbg=Green ctermfg=Yellow
复制代码

[ 本帖最后由 flw 于 2006-9-11 21:49 编辑 ]
作者: lovesaka    时间: 2006-09-11 22:12
呵呵
连flw老大都拿出了那还说什么大家一起来呀
作者: 飞灰橙    时间: 2006-09-11 23:06
不是我的

  1. !vim
  2. !gvim
复制代码

作者: converse    时间: 2006-09-11 23:17
最近也在玩儿VIM,唯独让我不是很爽的地方就是好像没有特别强大的函数变量补全功能...哪位有好的插件可以推荐一下,谢谢.

之所以想开始学VIM,有如下原因:1)快捷键用的很爽,2)界面主题很酷,3)现在有时也要在linux下面写代码了,不学会这个工具不行.
作者: lovesaka    时间: 2006-09-11 23:20
我再贴上一个

功能:根椐文件格式加注释你可以自己改一下

  1. function Mycomment()
  2. if &syntax=="cpp" || &syntax=="c"
  3. execute "normal  \<Esc>\<S-$>a\<TAB>/**/\<Esc>2ha"
  4. elseif &syntax=="perl" || &syntax=="sh"
  5. execute "normal \<Esc>\<S-$>a\<TAB>#\<Esc>k\<S-$>"
  6. endif
  7. endf
  8. map <F2> <Esc>:call Mycomment()<CR><Esc>:$<Esc>o
复制代码

作者: lovesaka    时间: 2006-09-11 23:31
我很没用过插件的
VIM网站上可能有吧
是呀VIM里函数变量补全功能很爽加上tags那真是爽得不得了
作者: sttty    时间: 2006-09-11 23:32
路过...
作者: gawk    时间: 2006-09-12 08:40
不错,vim弄了一段时间,由于出差中断了,现在看见了这个帖子,真是亲切啊
作者: chzht001    时间: 2006-09-12 09:10
标题: 回复 6楼 flw 的帖子
哈哈,收藏了先!!!
作者: slay78    时间: 2006-09-12 09:13
我的太长了,忘记从哪儿抄来的了

  1. " vim:shiftwidth=2:tabstop=8:expandtab

  2. if has('autocmd')
  3.   " Remove ALL autocommands for the current group
  4.   au!

  5.   " Mark .asm files MASM-type assembly
  6.   au BufNewFile,BufReadPre *.asm let b:asmsyntax='masm'
  7. endif

  8. if has('gui_running')
  9.   let do_syntax_sel_menu=1
  10. endif

  11. if has('gui_running') && $LANG !~ '\.'
  12.   set encoding=utf-8
  13. endif

  14. set nocompatible
  15. source $VIMRUNTIME/vimrc_example.vim

  16. set autoindent
  17. set nobackup
  18. set showmatch
  19. set formatoptions+=mM
  20. set fileencodings=ucs-bom,utf-8,gbk
  21. set statusline=%<%f\ %h%m%r%=%k[%{(&fenc==\"\")?&enc:&fenc}%{(&bomb?\",BOM\":\"\")}]\ %-14.(%l,%c%V%)\ %P
  22. if has('mouse')
  23.   set mouse=a
  24. endif
  25. if has('multi_byte') && v:version > 601
  26.   if v:lang =~? '^\(zh\)\|\(ja\)\|\(ko\)'
  27.     set ambiwidth=double
  28.   endif
  29. endif

  30. " Key mappings to ease browsing long lines
  31. noremap  <C-J>       gj
  32. noremap  <C-K>       gk
  33. noremap  <Down>      gj
  34. noremap  <Up>        gk
  35. inoremap <Down> <C-O>gj
  36. inoremap <Up>   <C-O>gk

  37. " Key mappings for quick arithmetic inside Vim
  38. nnoremap <silent> <Leader>ma yypV:!calcu '<C-R>"'<CR>k$
  39. vnoremap <silent> <Leader>ma yo<ESC>pV:!calcu '<C-R>"'<CR>k$
  40. nnoremap <silent> <Leader>mr yyV:!calcu '<C-R>"'<CR>$
  41. vnoremap <silent> <Leader>mr ygvmaomb:r !calcu '<C-R>"'<CR>"ay$dd`bv`a"ap

  42. " Key mapping to stop the search highlight
  43. nmap <silent> <F2>      :nohlsearch<CR>
  44. imap <silent> <F2> <C-O>:nohlsearch<CR>

  45. " Key mapping for the taglist.vim plugin
  46. nmap <F9>      :Tlist<CR>
  47. imap <F9> <C-O>:Tlist<CR>

  48. " Key mappings for the quickfix commands
  49. nmap <F11> :cn<CR>
  50. nmap <F12> :cp<CR>

  51. " Non-GUI setting
  52. if !has('gui_running')
  53.   " Do not increase the windows width in the taglist.vim plugin
  54.   if has('eval')
  55.     let Tlist_Inc_Winwidth=0
  56.   endif

  57.   " Set text-mode menu
  58.   if has('wildmenu')
  59.     set wildmenu
  60.     set cpoptions-=<
  61.     set wildcharm=<C-Z>
  62.     nmap <F10>      :emenu <C-Z>
  63.     imap <F10> <C-O>:emenu <C-Z>
  64.   endif
  65. endif

  66. if has('autocmd')
  67.   function! SetFileEncodings(encodings)
  68.     let b:my_fileencodings_bak=&fileencodings
  69.     let &fileencodings=a:encodings
  70.   endfunction

  71.   function! RestoreFileEncodings()
  72.     let &fileencodings=b:my_fileencodings_bak
  73.     unlet b:my_fileencodings_bak
  74.   endfunction

  75.   function! CheckFileEncoding()
  76.     if &modified && &fileencoding != ''
  77.       exec 'e! ++enc=' . &fileencoding
  78.     endif
  79.   endfunction

  80.   function! ConvertHtmlEncoding(encoding)
  81.     if a:encoding ==? 'gb2312'
  82.       return 'gbk'              " GB2312 imprecisely means GBK in HTML
  83.     elseif a:encoding ==? 'iso-8859-1'
  84.       return 'latin1'           " The canonical encoding name in Vim
  85.     elseif a:encoding ==? 'utf8'
  86.       return 'utf-8'            " Other encoding aliases should follow here
  87.     else
  88.       return a:encoding
  89.     endif
  90.   endfunction

  91.   function! DetectHtmlEncoding()
  92.     if &filetype != 'html'
  93.       return
  94.     endif
  95.     normal m`
  96.     normal gg
  97.     if search('\c<meta http-equiv=\("\?\)Content-Type\1 content="text/html; charset=[-A-Za-z0-9_]\+">') != 0
  98.       let reg_bak=@"
  99.       normal y$
  100.       let charset=matchstr(@", 'text/html; charset=\zs[-A-Za-z0-9_]\+')
  101.       let charset=ConvertHtmlEncoding(charset)
  102.       normal ``
  103.       let @"=reg_bak
  104.       if &fileencodings == ''
  105.         let auto_encodings=',' . &encoding . ','
  106.       else
  107.         let auto_encodings=',' . &fileencodings . ','
  108.       endif
  109.       if charset !=? &fileencoding &&
  110.             \(auto_encodings =~ ',' . &fileencoding . ',' || &fileencoding == '')
  111.         silent! exec 'e ++enc=' . charset
  112.       endif
  113.     else
  114.       normal ``
  115.     endif
  116.   endfunction

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

  122.   function! RemoveTrailingSpace()
  123.     if $VIM_HATE_SPACE_ERRORS != '0' &&
  124.           \(&filetype == 'c' || &filetype == 'cpp' || &filetype == 'vim')
  125.       normal m`
  126.       silent! :%s/\s\+$//e
  127.       normal ``
  128.     endif
  129.   endfunction

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

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

  136.   " Show syntax highlighting attributes of character under cursor (Vim
  137.   " script #383)
  138.   map <Leader>a :call SyntaxAttr()<CR>

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

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

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

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

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

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

  159.   " Remove trailing spaces for C/C++ and Vim files
  160.   au BufWritePre *                  call RemoveTrailingSpace()
  161. endif
  162. "me add
  163. "autocmd BufNewFile *.c exec append(0,"/*   */")|exec append(1,"#include <stdio.h>") |exec append(2,"int main(void)")|exec append(3,"{")|exec append(5,"        return 0;")|exec append(6,"}")| exec ':0'
  164. autocmd BufNewFile *.c exec append(0,"#include <stdio.h>") |exec append(1,"int main(void)")|exec append(2,"{")|exec append(4,"        return 0;")|exec append(5,"}")| exec ':4'
  165. autocmd BufNewFile *.pl exec append(0,"#!/usr/bin/perl -w") | exec append(1,"use strict;") | exec append(2,"use warnings;") | exec ':$'
  166. "autocmd BufNewFile *.py 0r ~/.vim/skeleton/skeleton.py
  167. map <F3> ^i#<ESC>
  168. map <F2> ^x
  169. set viminfo='200,\"500
  170. set history=500
  171. set number

复制代码

作者: lowmer    时间: 2006-09-12 09:13
set nocompatible
set nobackup
set nu
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set autoindent
set ai

set foldmethod=syntax "按照语法折叠代码,indent为按照缩进折叠代码,zi命令打开/关闭所有折叠
set foldcolumn=3  "设置折叠区域的宽度
set foldclose=all "设置为自动关闭折叠

''对于安装了中文help有效
        if version >= 603
                set helplang=cn
        endif

source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
source $vimruntime/colors/darkblue.vim  ''设置配色方案
behave mswin

''默认配置
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
  if &sh =~ '\<cmd'
    silent execute '!""C:\Program Files\Vim\vim64\diff" ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . '"'
  else
    silent execute '!C:\Program" Files\Vim\vim64\diff" ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
  endif
endfunction

"设置F5为不同文件类型添加注释
filetype plugin indent on
autocmd FileType cpp,java  map <F5> 0i//<Esc>
autocmd FileType c  map! <F5> /* */<Esc>
autocmd FileType sh        map! <F5> 0i#<Esc>

''设置F12为运行python程序,运行前需要保存
map <F12> :!c:\python24\python.exe % <CR>

[ 本帖最后由 lowmer 于 2006-9-12 17:25 编辑 ]
作者: er    时间: 2006-09-12 09:35
学习
作者: xnkjdx1998    时间: 2006-09-12 10:30
在这里学到很多,不过有个建议,如果各位能在配置时带上点注释会更好,
谢谢
作者: lovesaka    时间: 2006-09-12 11:30
to: slay78,lowmer
谢谢两位大侠能把自己的东西拿来共享从两位贴出来的脚本中自己也偷学了不少东西以前有点不怎么会的也给弄明白了,而且找从中找到了更加简洁的方法来实现自己想要的功能,其实是不是自己亲手写的都无所谓只要你平常觉得好用的就行了,更重要的是你能拿来让大家分享让以免别人写好了的东西自己再写一次,再一个就是能够从别人的东西里吸取很多比较好自己又不知道的知识
to: xnkjdx1998
我想这里再讲什么基本VIM用法那就不必要了不过你的提议不错最好一个功能加上说明也让大家知道是干什么用的
大家继续.........
作者: gawk    时间: 2006-09-12 12:36
  1. function Mycomm()
  2. let  tmphehe=getline(".")
  3. call setline(line("."),"/*")
  4. call append(line(".")," *".tmphehe."   by xx".strftime("%c"))
  5. call append(line(".")+1," */")endf
  6. map <F2> <Esc>:call Mycomm()<CR><ESC>
复制代码

哈哈,我弄的注释掉一行的快捷键

[ 本帖最后由 gawk 于 2006-9-12 16:49 编辑 ]
作者: lowmer    时间: 2006-09-12 17:18
原帖由 lovesaka 于 2006-9-12 11:30 发表
to: slay78,lowmer
谢谢两位大侠能把自己的东西拿来共享从两位贴出来的脚本中自己也偷学了不少东西以前有点不怎么会的也给弄明白了,而且找从中找到了更加简洁的方法来实现自己想要的功能,其实是不是自己亲手写 ...


不是谦虚,真算不上大虾。我只是把7.0的中文help详细地看了一遍,然后又看了“超级长贴”而已。有些选项一眼就看明白的就没加注释。
作者: Benson_linux    时间: 2006-09-12 17:33
我的

  1. set encoding=gb2312
  2. set cindent
  3. set ts=4
  4. set sw=4
  5. set foldcolumn=2
  6. abbreviate // // lyd[
  7. abbreviate //m // lyd[ MARK
  8. abbreviate //c // lyd[ CHANGED
  9. abbreviate //a // lyd[ ADD
  10. abbreviate //d // lyd[ DELETE
  11. abbreviate //D // lyd[ DEBUG
  12. abbreviate //j // lyd[ JSSUPPORT
  13. abbreviate //t // lyd[ TODO
  14. abbreviate printf printf ("####Benson debug:"
  15. abbreviate printk printk ("####Benson debug:"

  16. :map <F2> :s/^/\/\//<CR>

  17. :inoremap( ()<ESC>i
  18. :inoremap) <c-r>=ClosePair(')')<CR>
  19. :inoremap{ {}<ESC>i
  20. :inoremap} <c-r>=ClosePair('}')<CR>
  21. :inoremap[ []<ESC>i
  22. :inoremap] <c-r>=ClosePair(']')<CR>

  23. function ClosePair(char)
  24. if getline('.')[col(',') - 1] == a:char
  25. return "\<Right>"
  26. else
  27. return a:char
  28. endif
  29. endf
复制代码

作者: sithui    时间: 2006-09-12 17:34
弱弱地问一下
自己设置过vim后用什么命令保存到vimrc里面?
作者: slay78    时间: 2006-09-12 17:36
原帖由 sithui 于 2006-9-12 17:34 发表
弱弱地问一下
自己设置过vim后用什么命令保存到vimrc里面?


直接编辑~/.vimrc文件
作者: sithui    时间: 2006-09-12 17:38
原帖由 slay78 于 2006-9-12 17:36 发表


直接编辑~/.vimrc文件


要是我在编辑一个源文件的时候更改了一些设置,非得再输入一次到~/.vimrc里面吗?
作者: lovesaka    时间: 2006-09-12 18:04

  1. :inoremap( ()<ESC>i
  2. :inoremap) <c-r>=ClosePair(')')<CR>
  3. :inoremap{ {}<ESC>i
  4. :inoremap} <c-r>=ClosePair('}')<CR>
  5. :inoremap[ []<ESC>i
  6. :inoremap] <c-r>=ClosePair(']')<CR>

  7. function ClosePair(char)
  8. if getline('.')[col(',') - 1] == a:char
  9. return "\<Right>"
  10. else
  11. return a:char
  12. endif
  13. endf
复制代码


这一段补全很实用希望还有更多的实用技巧一一都给贴上哈哈VIM真是太强了
作者: net_robber    时间: 2006-09-13 17:08
我还没有好好研究过,呵呵
作者: newbuding    时间: 2006-09-13 21:51
没有认真研究,不过/usr/share/vim/vim70/下面有个例子vimrc_example.vim看起来还不错,改改就非常好用了
作者: lovesaka    时间: 2006-09-13 23:48
一个非常好用的插件能显示当前文件函数,宏,变量
只要把taglist.vim放到VIM插件目录就OK了再到vimrc里加上一个键映射就行了
具体怎么用在taglist.txt里说得很清楚

[ 本帖最后由 lovesaka 于 2006-9-13 23:54 编辑 ]

抓图6.png (89.93 KB, 下载次数: 80)

图一

图一

抓图7.png (85.29 KB, 下载次数: 80)

图二

图二

taglist_41.zip

46.12 KB, 下载次数: 240

VIM插件


作者: dlms    时间: 2006-09-14 09:18
你们用的都是什么版本啊!这些都咋用啊!俺一直就用vim当记事本用!
作者: yangkwch    时间: 2006-09-14 13:10
在默认的基础上增加了如下内容:
set number
set hlsearch
set ts=4
set shiftwidth=4
set nobackup
set fencs=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
作者: sailer_sh    时间: 2006-09-14 14:09
我的和你的差不多。。。
作者: lovesaka    时间: 2006-09-15 01:10
原帖由 dlms 于 2006-9-14 09:18 发表
你们用的都是什么版本啊!这些都咋用啊!俺一直就用vim当记事本用!

高手一般都是把VIM当记事本用
差不多都是7点几吧
作者: playmud    时间: 2006-09-15 10:23
taglist都需要那些配置?
文档看不明白
作者: lovesaka    时间: 2006-09-15 14:09
原帖由 playmud 于 2006-9-15 10:23 发表
taglist都需要那些配置?
文档看不明白

几乎可以说不用什么配置
我是直接把包解开然后把taglist.vim文件放到VIM安装目录下的plugin目录
再到vimrc里加上一句

  1. nnoremap <silent> <F8> :TlistToggle<CR>
复制代码

按F8就可以用了
作者: wolfssss    时间: 2006-09-15 15:59
我的,比较简单,个人觉得很好用,注释都加上了

  1. if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
  2.    set fileencodings=utf-8,latin1
  3. endif

  4. set nocompatible        " Use Vim defaults (much better!)
  5. set bs=2                " allow backspacing over everything in insert mode
  6. set ai                  " always set autoindenting on
  7. "set backup             " keep a backup file
  8. set viminfo='20,\"50    " read/write a .viminfo file, don't store more
  9.                         " than 50 lines of registers
  10. set history=50          " keep 50 lines of command line history
  11. set ruler               " show the cursor position all the time
  12. set number              " show the number of lines
  13. set showcmd             " show the cmd
  14. set whichwrap=b,s,<,>   " can use Backspace Space <Left> <Right> wrap
  15. "set mouse=a             " use mouse in terminal
  16. set helplang=cn         " set the vim helpdoc language
  17. set noignorecase        " set case not sensitivity

  18. vnoremap p <Esc>:let current_reg = @"<CR>gvs<C-R>=current_reg<CR><Esc>          " can paste in the VISUAL mode
  19. filetype plugin indent off

  20. " Only do this part when compiled with support for autocommands
  21. if has("autocmd")
  22.   " In text files, always limit the width of text to 78 characters
  23.   autocmd BufRead *.txt set tw=78
  24.   " When editing a file, always jump to the last cursor position
  25.   autocmd BufReadPost *
  26.   \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  27.   \   exe "normal g'\"" |
  28.   \ endif
  29. endif

  30. " Switch syntax highlighting on, when the terminal has colors
  31. " Also switch on highlighting the last used search pattern.
  32. if &t_Co > 2 || has("gui_running")
  33.   syntax on
  34.   set hlsearch
  35. endif

  36. if &term=="xterm"
  37.      set t_Co=8
  38.      set t_Sb=^[4%dm
  39.      set t_Sf=^[3%dm
  40. endif

  41. " Open a file managers
  42. map <F7> <ESC>:vsplit<ENTER>:edit `pwd`<ENTER>i

  43. " Open Tlist
  44. map <F8> <ESC>:Tlist<ENTER>
  45. " Close Tlist width resize
  46. let Tlist_Inc_Winwidth=0

  47. " use Alt+; to add comment,like emacs
  48. autocmd filetype cpp,java map <Esc>; $a<tab><tab>//
  49. autocmd filetype cpp,java imap <Esc>; <End><tab><tab>//
  50. autocmd filetype c map <Esc>; $a<tab><tab>/*   */<Esc>3hi
  51. autocmd filetype c imap <Esc>; <End><tab><tab>/*   */<Left><Left><Left><Left>
  52. autocmd filetype sh map <Esc>; O#
复制代码

作者: lovesaka    时间: 2006-09-15 22:48

不错如果以后不小心把vimrc文件给毁了到这上面来copy下去还是很便的哈哈
作者: lovesaka    时间: 2006-09-16 02:07
修改一下加了一个目录浏览vim自带的功能不过在taglist里面用f键就可以看当前目录
多谢谢楼上兄第脚本提示
小提示:在文件管理器下直接ex可以打开文件比如播放音乐,看电子书等等爽得不得了不过还得要你系统上有文件格式相关连的软件才行

[ 本帖最后由 lovesaka 于 2006-9-16 02:30 编辑 ]

抓图10.png (76.32 KB, 下载次数: 71)

图1

图1

抓图11.png (74.66 KB, 下载次数: 72)

图2

图2

taglist.tar

140 KB, 下载次数: 271

修改过后taglist


作者: lovesaka    时间: 2006-09-16 10:48
想做一个像vc那样的函数原形显示窗口最好和VIM补全的窗口差不多
却一直下不了手
知道的兄弟给点不妨给点提示
作者: lovesaka    时间: 2006-09-17 02:49
上面所说的要求并非空谈我看到有人在WINDOW下用MFC实现这个功能
所以自己想在LINUX写一个那东西

看来此贴生命周期已了
作者: cnscn123    时间: 2006-10-13 17:30
提示: 作者被禁止或删除 内容自动屏蔽
作者: jing18    时间: 2006-10-16 01:44
" 我的 _vimrc 部份設定

" 使用環境:windows XP
" vim 版本:7.0-134

" 編輯 _vimrc
map ,v :e!$vim/_vimrc<CR>

" 開啟個人備忘錄
map ,m :e!D:\117\Cbackup\memo\MEMO.TXT<CR>
" 押日期(map: 命令模式  imap: 搜入模式)
map <F7> a<C-R>=strftime("%c")<CR>
imap <F7> <C-R>=strftime("%c")<CR>

" 檔案瀏覽(開啟的目錄為目前編輯檔案所在之目錄)
map ,e :e <C-R>=expand("%:p:h")<CR><CR>   

" set hidden 始可使用以下二個命令(注意!有修改未存檔之陷阱。)
" 切換檔案編輯
map <F8> :bn<CR>
" 查詢編輯中的檔案編號,在:b後輸入編號即可編輯該檔;:bd!輸入編號可強行刪除buffer檔案
map ,r :ls<CR>:b

" set hlsearch, 字串搜尋吻合者高亮度提示,很好!
" 但用完她還亮著不肯離去,礙眼著很!所以,就 ...
map ,h :nohl<CR>

" set wrap 一眼看盡全行,她棒得很!
" 但想要比對上下行時,下行在下邊那一列呢?這時,就 ...
map ,w :set wrap!<CR>

" set nu 看著行號變大,成就感猶然而生。
" 但在成就之後的落寞時,不再需要閑雜人等,此時,就 ...
map ,n :set nu!<CR>

" set cursorline & set cursorcolumn 人近五十視茫眼瞎,浩瀚字海那點游標,找得辛苦!
" 幸好有了這帖清目丸!
map ,s :set cursorline!<CR>:set cursorcolumn!<CR>

" run perl script
map ;r :w<CR>:!perl -w "%:p"<CR>
" debug perl script
map ;d :w<CR>:!perl -d "%:p"<CR>Sample Text

[ 本帖最后由 jing18 于 2006-10-16 01:47 编辑 ]
作者: shihyu    时间: 2010-03-22 01:35
还有其他人的vimrc 吗?

想看看

谢谢
作者: hy0kl    时间: 2010-03-28 18:52

  1. syntax on
  2. set nocompatible
  3. set number
  4. "set autoindent
  5. "set smartindent
  6. set expandtab   
  7. set ts=4
  8. set shiftwidth=4
  9. set cursorline
  10. set nobackup
  11. " just for encode
  12. set fileencodings=utf-8,gb2312,gbk,gb18030
  13. set termencoding=utf-8
  14. set fileformats=unix
  15. set encoding=prc
  16. set hlsearch
  17. " set foldmethod
  18. set fdm=indent
复制代码

作者: scaleray    时间: 2010-03-28 22:13
600多行了,就不放了,会出事的
作者: wjtmain    时间: 2010-07-30 17:45
  1. "颜色方案
  2. colorscheme desert256

  3. "禁止响铃
  4. set noerrorbells
  5. set autochdir

  6. nnoremap <silent> <F2> :Tlist<CR>
  7. let Tlist_Use_Right_Window=1
  8. let Tlist_File_Fold_Auto_Close=1
  9. "查找 -R ./* 为当前目录
  10. nnoremap <silent> <F3> :Grep<CR>
  11. "退出
  12. nnoremap <silent> <F4> :wall<CR> :qall<CR>
  13. imap <F4> <Esc>:wall<CR> :qall<CR>
  14. "写文件
  15. nnoremap <silent> <F5> :wall<CR> :make<CR>
  16. imap <F5> <Esc>:wall<CR> :make<CR>
  17. "cc和h互换
  18. nnoremap <silent> <F6> :A<CR>
  19. imap <F6> <Esc>:call CppToHFunc()<CR>
  20. func! CppToHFunc()
  21.         "保存文件
  22.         :w
  23.         "头文件和cc文件转化
  24.         :A
  25. endfunc
  26. "打开文件浏览器
  27. nnoremap <silent> <F8> :NERDTreeToggle<CR>
  28. imap <F8> <ESC>:NERDTreeToggle<CR>
  29. "保存所有文件
  30. nnoremap <silent> <F10> :wall<CR>
  31. imap <F10> <Esc>:wall<CR>

  32. imap <C-s> <Esc>:wa<CR>i<Right>
  33. nmap <C-s> :wa<CR>

  34. "保存文件并执行标签脚本
  35. nnoremap <silent> <F11> :call AutoTagsFunc()<CR>
  36. imap <F11> <Esc>:call AutoTagsFunc()<CR>
  37. func! AutoTagsFunc()
  38.         :wall
  39.         :!/home/autotags.sh
  40.         ":cs add /home/CDB/cscope.out
  41.         :cs reset
  42. endfunc
  43. "编译游戏代码
  44. set makeprg=/home/mymake.sh
  45. let &errorformat="%f:%l:%c: %t%*[^:]:%m,%f:%l: %t%*[^:]:%m," . &errorformat
复制代码

作者: linux爽    时间: 2010-08-14 22:11
刚开始一个月的菜鸟路过学习!!
作者: zhanglistar    时间: 2010-11-01 13:02
回复 1# lovesaka


    偶的vimrc   环境 ubuntu   主要用来code, C/C++ php 等  

    个人觉得比较方便。
  1. syntax on

  2. " If using a dark background within the editing area and syntax highlighting
  3. " turn on this option as well
  4. "set background=dark

  5. " Uncomment the following to have Vim jump to the last position when
  6. " reopening a file
  7. "if has("autocmd")
  8. "  au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
  9. "    \| exe "normal g'\"" | endif
  10. "endif

  11. " Uncomment the following to have Vim load indentation rules according to the
  12. " detected filetype. Per default Debian Vim only load filetype specific
  13. " plugins.
  14. "if has("autocmd")
  15. "  filetype indent on
  16. "endif

  17. " The following are commented out as they cause vim to behave a lot
  18. " differently from regular Vi. They are highly recommended though.
  19. "set showcmd                " Show (partial) command in status line.
  20. "set showmatch                " Show matching brackets.
  21. "set ignorecase                " Do case insensitive matching
  22. "set smartcase                " Do smart case matching
  23. "set incsearch                " Incremental search
  24. "set autowrite                " Automatically save before commands like :next and :make
  25. "set hidden             " Hide buffers when they are abandoned
  26. "set mouse=a                " Enable mouse usage (all modes) in terminals

  27. " Source a global configuration file if available
  28. " XXX Deprecated, please move your changes here in /etc/vim/vimrc
  29. filetype plugin on
  30. if filereadable("/etc/vim/vimrc.local")
  31.   source /etc/vim/vimrc.local
  32. endif
  33. syntax on
  34. set tabstop=4
  35. set autoindent shiftwidth=4
  36. set tabstop=4
  37. set shiftwidth=4
  38. let mapleader=","
  39. map <silent><leader>w :w<cr>
  40. map <silent><leader>qa :qa<cr>
  41. map <silent><leader>qq :q!<cr>
  42. map <silent><leader>wq :wq<cr>
  43. "Taglist
  44. map <silent><leader>tl :TlistToggle<cr>
  45. let Tlist_Ctags_Cmd = '/usr/bin/ctags'
  46. let Tlist_Show_One_File = 1
  47. let Tlist_Exit_OnlyWindow = 1
  48. let Tlist_Use_Right_Window = 1
  49. set nohlsearch
  50. set fileencodings=cp936,ucs-bom,utf-8,
  51. set fileencoding=cp936
  52. set encoding=cp936
  53. let &termencoding=&encoding
  54. "colorscheme desert
  55. "colorscheme molokai
  56. " cscope
  57. if has("cscope")
  58.         set csprg=/usr/bin/cscope
  59.         set csto=1
  60.         set cst
  61.         set nocsverb
  62.         " add any database in current directory
  63.         if filereadable("cscope.out")
  64.                 cs add cscope.out
  65.         endif
  66.         set csverb
  67. endif
  68. nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
  69. nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
  70. nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
  71. nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
  72. nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
  73. nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
  74. nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
  75. nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
  76. " bufexploer
  77. map <silent><leader>be :BufExplorer<cr>
  78. map <silent><leader>bs :BufExplorerHorizontalSplit<cr>
  79. map <silent><leader>bv :BufExplorerVerticalSplit<cr>
  80. " quickfix
  81. nmap <F6> :cn<cr>
  82. nmap <F7> :cp<cr>
  83. nmap <F5> :make<cr>
  84. nmap <F8> :cw<cr>
  85. " press control + s to save
  86. "imap <C-c> <ESC> :w<cr>
  87. "nmap <C-c> <ESC> :w<cr>
  88. " quick jump between splits
  89. map <C-j> <C-w>j<C-w>_
  90. map <C-k> <C-w>k<C-w>_
  91. map <C-l> <C-w>l<C-w>_
  92. map <C-h> <C-w>h<C-w>_

  93. " A.vim
  94. map <silent><leader>a :A<cr>
  95. " NERD_tree
  96. map <silent><leader>t :NERDTreeToggle<cr>
  97. " another explorer
  98. map <silent><leader>e :Ex<cr>
  99. " only one window
  100. map <silent><leader>m :only<cr>
  101. " omnicppcomplete
  102. set completeopt=menu
  103. let OmniCpp_SelectFirstItem = 0
  104. map <F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
  105. set tags+=/home/listar/cppstltags
  106. " pydiction
  107. filetype plugin on
  108. let g:pydiction_location = '/home/listar/.vim/tools/pydiction/complete-dict'
  109. "php set
  110. "au FileType php source /usr/share/vim/vim72/colors/murphy.vim
  111. let g:phpColor = "murphy"
  112. let g:defaultColor = "desert"
  113. "au! FileType * exe ":colorscheme " . g:defaultColor
  114. "au! FileType php exe ":colorscheme " . g:phpColor
  115. " neocomplcache
  116. " Disable AutoComplPop.
  117. let g:acp_enableAtStartup = 0
  118. " Use neocomplcache.
  119. let g:neocomplcache_enable_at_startup = 1
  120. " Use smartcase.
  121. let g:neocomplcache_enable_smart_case = 1
  122. " Use camel case completion.
  123. let g:neocomplcache_enable_camel_case_completion = 1
  124. " Use underbar completion.
  125. let g:neocomplcache_enable_underbar_completion = 1
  126. " Set minimum syntax keyword length.
  127. let g:neocomplcache_min_syntax_length = 3
  128. let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*'
  129. colorscheme murphy
复制代码





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2