注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

guoyoooping的博客

audio,picture, text and video

 
 
 

日志

 
 

Vim学习笔记11: 晒晒我的.vimrc  

2010-01-31 19:31:06|  分类: Vim: 学习Vim的心 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
"Author: ypguo<guoyoooping@163.com>
"Date: 2011.8.10
"Version: 1.1


"TOC
"=====
"<#1. encoding and printer>
"<#2. options>
"<#3. Plugins>
"<#4. maps>
"<#5. functions>
"    <#function! SaveSession>
"<#6. Autocommands>
"
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 1. encoding and printer
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"language message zh_CN.UTF-8

"设置编码格式, 在windows和cygwin下必须用cp936编码, 在其它操作系统下, 用utf-8.
if (has("win32") || has("win32unix"))
    "Win32 and Win32 version of Vim, using Unix files (Cygwin)
    au GUIEnter * simalt ~x "maximum the initial window
    set encoding=cp936
    set fileformats=dos,unix,mac " EOL formats(\r\n or \n or \r) in order
else
    set encoding=utf8
    set fileformats=unix,dos,mac " EOL formats(\r\n or \n or \r) in order
endif
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1

if (!has("win32"))
    "set printdevice=iP1880-series "printer, use system printer if not set
    set printencoding=utf-8 "encoding of printing. use encoding if not set.
    set printmbcharset=ISO10646 "charset of print. should be compatible with printencoding.
    "set printmbfont=r:MSungGBK-Light,c:yes
    set printmbfont=r:STSong-Light,c:yes "打印所用字体, 在linux下, 要用ghostscript里已有的字体, 不然会打印乱码.
    "打印可选项, formfeed: 是否处理换页符, header: 页眉大小, paper: 用何种纸, duplex: 是否双面打印, syntax: 是否支持语法高
    set printoptions=formfeed:y,paper:A4,duplex:on,syntax:y",header:3
    "set printheader=%<%f%h%m%=Page\ %N "打印时页眉的格式
endif

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 2. options
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible "be not compatible with vi.
set cursorline
"set background=dark
set nu "显示行号
set autoindent " autoindent 自动缩进
set history=1000 " How many lines of history to remember
set hidden " you can change buffer without saving
set backspace=indent,eol,start "可以使用backspace删除文字.
set report=0 " tell us when anything is modified. 当文件有任何改变时在状态栏报告.
"set backup "make backup file "使能备份文件.
set noerrorbells "no error bell. 有错误发生时不发出嘀嘀声.
"set visualbell "use visual bell(有错误发生时屏幕会一闪一闪地提示.)

"display setting
set ambiwidth=double "ambiwidth默认值为single. 此时若encoding为utf-8, gvim显示全角符号时会当作半角显示.
set mouse=a "can use mouse in any mode.(所有模式下都可以使用鼠标.)

"formatted text files
set wrap "longer lines will be wraped to the next line(设置长行回绕.)
"set linebreak "line break after a word.(只在单词结束后换行, 避免把一个单词显示在两行. 中文不建议打开这个选项)
set nojoinspaces "no space add when join two lines.(用j命令合并两行时, 不在之间加空格.)

"哪些光标移动命令可以移到上一行或下一行: <BS>, <Space>, <Left>, <Right>, h, l
set whichwrap+=<,>,[,],h,l " Which keys can wrap to the last line.

set scrolloff=2 " Keep 2 lines (top/bottom) for scope
"上下移动光标时, 始终保持光标上或下有两行在屏幕上.

"将tab键扩展成空格.
"set noexpandtab "converts tabs to spaces.

"只在行首用tab, 其它地方的tab都用空格代替.
set smarttab " use tabs at the start of a line, spaces elsewhere

"允许撤销操作多少次, 默认值是500.
"set undolevels=1000 "Maximum number of changes that can be undo.

"about searching
"搜索时不区分大小写, 如果键入了大写字母则区分大小写.
set ignorecase smartcase "case-insentive when searching. case-sentive when uper case exist.

"搜索时, 从键入时就开始匹配.
set incsearch " BUT do highlight as you type your search phrase

"高亮搜索结果.
set hlsearch "highlight all the search results.

"set cf " enable error files and error jumping

"确保命令历史被记录在viminfo文件中.
set viminfo+=! " make sure it can save viminfo

"有
set display=lastline "show the last line even if it doesn't fit.

"工具栏设置: 不显示工具栏.
set guioptions-=T "don't show toolbars.

"tab栏显示的格式: "位置: 文件名"
set guitablabel=%N:\ %f

"标尺栏显示及格式, 标尺栏是指右下角显示行号, 列号的状态栏.
set ruler " Always show current positions along the bottom
set rulerformat=%57(%50t[%{&ff},%Y]\ %m\ %l,%c\ %p%%%) "custom my ruler format. "%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
"set rulerformat=%67(%50t\ %m\ %l,%c\ %p%%%) "custom my ruler format. "%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P

"状态栏的格式, 不设置则用默认格式.

au BufEnter *.txt set statusline=%=%F%m%r%h%w\ [ff=%{&ff}]\ [ft=%Y]\ [enc=%{&enc}]\ [fenc=%{&fenc}]\ %l,%v\ %p%%
"set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]

set nosol

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 3. Plugins
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"let Tlist_Ctags_Cmd = '/usr/bin/ctags' " Location of ctags anf conf file.
"auto open Tlist when vim open
"let Tlist_Auto_Open = 1
" Remove extra information and blank lines from the taglist window.
let Tlist_Compact_Format = 1
" if you are the last, kill yourself
let Tlist_Exit_OnlyWindow = 1
" no inc the width of the windows
let Tlist_Inc_Winwidth = 1
" order by name or order, type 's' to change betweent in the taglist window.
let Tlist_Sort_Type = "order"
" Close tag folds for inactive buffers.
let Tlist_File_Fold_Auto_Close = 1
"the default width of the vertically split taglist window
if has("gui_running")
    let Tlist_WinWidth = 35
else
    let Tlist_WinWidth = 27
endif
"display the tags defined only in the current buffer
let Tlist_Show_One_File = 1
"Display the tags menu.
"let Tlist_Show_Menu = 1


" F5: (normal mode) brings up the tag list
nmap <silent> <F5> <ESC>:TlistUpdate<RETURN>
" F7: (normal mode)Toggle the NERD_tree.vim separately
nmap <F7> <ESC>:NERDTreeToggle<RETURN>
" F8: (normal mode) brings up the tag list
nmap <silent> <F8> <ESC>:Tlist<RETURN>
"F10: (normal mode)Toggle sketch
map <F10> :call ToggleSketch()<CR>

"NERDTree plugin
let NERDTreeWinPos = "right" "where NERD tree window is placed on the screen
"let NERDTreeWinSize = 31 "size of the NERD tree


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 4. maps: personal maps for easy use.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let mapleader = ","
noremap <M-j> 3<C-e>
noremap <M-k> 3<C-y>
noremap <C-j> 3<C-e>
noremap <C-k> 3<C-y>
nnoremap <SPACE> 2<C-e>
nnoremap m 2<C-y>
set clipboard=unnamed "The * register is the default register.
"quit
noremap qq <ESC>:q<CR>
noremap j gj
noremap k gk
noremap gh 10h
noremap gj 10j
noremap gk 10k
noremap gl 10l

"save
noremap t <ESC>:w<CR>

if has("gui_running")
    "autocmd FileType txt colorscheme default
    colorscheme default
    set background=light
    set guifont=新宋体:h13:cGB2312 "set the gui font.(gvim使用的字体.)
    "set guifont=Monospace\ 10 "新宋体:h11:cGB2312 "set the gui font.(gvim使用的字体.)
    set linespace=3 "row space.(两行的间距, 只对gvim有效.)
    "autocmd FileType c,cpp :colorscheme evening
    " Ctrl+S实现保存,如果未命名文件名会提示你选择保存路径和文件名
    :map <silent> <C-S> :if expand("%") == ""<CR>:browse confirm w<CR>:else<CR>:confirm w<CR>:endif<CR>
    noremap <M-1> 1gt
    noremap <M-2> 2gt
    noremap <M-3> 3gt
    noremap <M-4> 4gt
    noremap <M-5> 5gt
    noremap <M-6> 6gt
    noremap <M-7> 7gt
    noremap <M-8> 8gt
    noremap <M-9> 9gt
    noremap <M-0> 10gt
    noremap <C-TAB> gt
    noremap <C-F4> <ESC>:bd<CR>
    noremap qt <ESC>:bd<CR>
    au BufEnter * simalt ~x "maximum the initial window
else
    colorscheme desert"torte
endif

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 5. functions
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"reload the project's last setting: ":mksession" in the first open a project.
set sessionoptions+=resize,winpos "setting options of mksession.
autocmd VimEnter * call LoadSession()
autocmd VimLeave * call SaveSession()
function! SaveSession()
    if (filereadable("Session.vim"))
        execute 'mksession!'
    endif
endfunction
function! LoadSession()
    if argc() == 0
    silent! execute 'source Session.vim'
    if (has("win32") && has("gui_running"))
        simalt ~x "maximum the initial window
    endif
    endif
endfunction

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 6. Autocommands
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" do c-style indenting, cinoptions changes:
":N    Place case labels N characters from the indent of the switch(). (default 'shiftwidth').
"gN    Place C++ scope declarations N characters from the indent of the block they are in. (default 'shiftwidth').
"tN    Indent a function return type declaration N characters from the margin. (default 'shiftwidth').
"(N    When in unclosed parentheses, indent N characters from the line with the unclosed parentheses. (default 'shiftwidth' * 2).
autocmd FileType c,cpp :set cindent cinoptions=:0,g0,t0,(0 textwidth=79 formatoptions=tcroqmB
autocmd FileType c,cpp :set number shiftwidth=4 expandtab tabstop=4 softtabstop=4 linespace=0 keywordprg=man
autocmd FileType c,cpp :match ErrorMsg /\%>80v.\+/ "highlight characters after column 80.

"plain text language
"au BufEnter *.txt TxtBrowserDebug  txtbrowser.log
"au BufRead,BufNewFile *.txt TlistDebug  taglist.log

" Pay attention difference between 'BufEnter' and 'BufRead,BufNewFile'
au BufRead,BufNewFile *.txt setlocal nu formatoptions=t2crmB textwidth=79 bg& ft=txt
syntax on "是否打开语法高亮, 使得Vim可以用不同的字体或颜色显示文本的不同部分
filetype plugin indent on "使能 "文件类型", "插件" 和 "自动缩进"

au BufEnter *.log setlocal ft=txt nu bg&

"Use www.dict.cn as my web dictionary in vim.
let TxtBrowser_Dict_Url = 'http://dict.cn/text'
"let TxtBrowser_Dict_Url = 'http://www.iciba.com/text'
"Use www.baidu.com as my favorate search engine in vim.
"let Txtbrowser_Search_Engine = 'http://www.baidu.com/s?wd=text'
"let TxtBrowser_Title_Level = 4


set noswapfile

" vim:ft=vim sw=4
  评论这张
 
阅读(3368)| 评论(7)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017