免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: lovesaka
打印 上一主题 下一主题

[共享交流]请交出你的vimrc [复制链接]

论坛徽章:
0
11 [报告]
发表于 2006-09-11 23:31 |只看该作者
我很没用过插件的
VIM网站上可能有吧
是呀VIM里函数变量补全功能很爽加上tags那真是爽得不得了

论坛徽章:
0
12 [报告]
发表于 2006-09-11 23:32 |只看该作者
路过...

论坛徽章:
0
13 [报告]
发表于 2006-09-12 08:40 |只看该作者
不错,vim弄了一段时间,由于出差中断了,现在看见了这个帖子,真是亲切啊

论坛徽章:
0
14 [报告]
发表于 2006-09-12 09:10 |只看该作者

回复 6楼 flw 的帖子

哈哈,收藏了先!!!

论坛徽章:
0
15 [报告]
发表于 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

复制代码

论坛徽章:
0
16 [报告]
发表于 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 编辑 ]

论坛徽章:
0
17 [报告]
发表于 2006-09-12 09:35 |只看该作者
学习

论坛徽章:
0
18 [报告]
发表于 2006-09-12 10:30 |只看该作者
在这里学到很多,不过有个建议,如果各位能在配置时带上点注释会更好,
谢谢

论坛徽章:
0
19 [报告]
发表于 2006-09-12 11:30 |只看该作者
to: slay78,lowmer
谢谢两位大侠能把自己的东西拿来共享从两位贴出来的脚本中自己也偷学了不少东西以前有点不怎么会的也给弄明白了,而且找从中找到了更加简洁的方法来实现自己想要的功能,其实是不是自己亲手写的都无所谓只要你平常觉得好用的就行了,更重要的是你能拿来让大家分享让以免别人写好了的东西自己再写一次,再一个就是能够从别人的东西里吸取很多比较好自己又不知道的知识
to: xnkjdx1998
我想这里再讲什么基本VIM用法那就不必要了不过你的提议不错最好一个功能加上说明也让大家知道是干什么用的
大家继续.........

论坛徽章:
0
20 [报告]
发表于 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 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP