vimrc

vimrc (待整理)

" 禁用 vi 兼容模式,这个一般来说是必须的
set nocompatible
" Don't use Ex mode, use Q for formatting
map Q gq
" CTRL-U in insert mode deletes a lot.
" Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap  u
" set mouse=a
" Only do this part when compiled with support for autocommands.
if has("autocmd")
	" Enable file type detection.
	" Use the default filetype settings, so that mail gets 'tw' set to 72,
	" 'cindent' is on in C files, etc.
	" Also load indent files, to automatically do language-dependent indenting.
	filetype plugin indent on
	" Put these in an autocmd group, so that we can delete them easily.
	augroup vimrcEx
		au!
		" For all text files set 'textwidth' to 78 characters.
		autocmd FileType text setlocal textwidth=78
		" When editing a file, always jump to the last known cursor position.
		" Don't do it when the position is invalid or when inside an event handler
		" (happens when dropping a file on gvim).
		" Also don't do it when the mark is in the first line, 
		" that is the defaul tposition when opening a file.
		autocmd BufReadPost *
					\ if line("'\"") > 1 && line("'\"") <= line("$") |
					\ exe "normal! g`\"" |
					\ endif
	augroup END
else
	set autoindent " always set autoindenting on
endif " has("autocmd")
" Convenient command to see the difference between the current buffer 
" and the file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
	command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
				\ | wincmd p | diffthis
endif
set ruler " 总是显示光标位置
set showcmd " display incomplete commands
" 编码设置,内部编码设置为 utf-8
" 文件编码检测顺序为:cs-bom,utf-8,gbk,default,latin1
let &termencoding= &encoding
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,gbk,default,latin1
" 使用中文帮助文档 (要到 http://vimcdoc.sf.net 下载 vim 中文文档并到到~/.vim/doc 下面)
set helplang=cn
set t_Co=256
" 启用语法高亮显示
syntax enable
" 显示行号
set number

colorscheme desert
"colorscheme monokai
" 高亮显示配对括号
"set showmatch
"下一行取消括号高亮显示
"let loaded_matchparen=1
" Basic editing options
" 不将 tab 转换为空格
"set noexpandtab
" 将 tab 转换为空格
set expandtab
" tab 占 4 个字符宽
set shiftwidth=2
" 不同文件的tab宽度设置 au=autocmd setl=setlocal
au FileType html,python,vim,javascript setl shiftwidth=2
au FileType html,python,vim,javascript setl tabstop=2
au FileType java,php setl shiftwidth=4
au FileType java,php setl tabstop=4
" 智能tab
set smarttab
" 打开linebreak,光标将不能左右移动到各行
set lbr
" textwidth
set tw=0
" 设置自动缩进 Auto indent 上面(if 语句里)设置了,这里取消
" set ai
" Smart indent 设置智能缩进
" set smartindent
" 还是用cindent,它更聪明些(设置了cindent,smartindent无效)
" C-style indeting
set cindent
" Wrap lines 超过窗口宽度的行自动回绕
set wrap
" jquery 语法高亮 ( 要将 jquery.vim 放置在 ~/.vim/syntax/下 )
au BufRead,BufNewFile *.js set syntax=jquery
" Sets how many lines of history VIM har to remember
set history=50
"  Set to auto read when a file is changed from the outside
set autoread
" Do not redraw, when running macros.. lazyredraw
set lz
" set 7 lines to the curors - when moving vertical..
" scrolloff 光标上下两侧最少保留的屏幕行数,使得总有一些可见的上下文
set so=7
" The commandbar is 2 high下部状态行高度,必须为正
set cmdheight=1
" Change buffer - without saving
set hid
" Ignore case when searching 搜索时忽略大小写,这个按个人需求吧,我这里不启用
" set ignorecase
" do incremental searching
set incsearch
" Set magic on 魔术匹配模式(默认打开)
set magic
" How many tenths of a second to blink (matchtime)
" 配对闪动时间,多少个十分之一秒
set mat=4
" Highlight search things
set hlsearch
" Turn backup off 两个都设置,完全关掉
" nobakcup
set nobackup
" nowritebackup
set nowb
" 缓冲区不使用交换文件,而使用内存.安全起见还是使用下为好
" set noswapfile
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" Use the arrows to something usefull
"map  :bn
"map  :bp
" 我这里的dawn2是由dawn转换的在term下使用的配色方案
" 不可否认, monaco 的确是一种非常好的编程字体
if has("gui_running")
	set guifont=Bitstream_Vera_Sans_Mono:h10:cANSI
	set gfw=幼圆:h10:cGB2312
	"color mydarkblue
	color zellner
else
	set guifont=Bitstream_Vera_Sans_Mono:h10:cANSI
	set gfw=幼圆:h10:cGB2312
	"color mydarkblue
	color zellner
endif
" 以下为 debian 特别优化的
" debian start
" Suffixes that get lower priority when doing tab completion for filenames.
" These are files we are not likely to want to edit or read.
set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc
" Set paper size from /etc/papersize if available (Debian-specific)
if filereadable("/etc/papersize")
	let s:papersize = matchstr(readfile('/etc/papersize', '', 1), '\p*')
	if strlen(s:papersize)
		exe "set printoptions+=paper:" . s:papersize
	endif
endif
" debian end
" csupport plugin
map   :cprevious
map   :cnext
" for taglist plugin
nnoremap   :TlistToggle





" Sets stardict for VIM
function! Mydict()
	let expl=system('sdcv -n ' .
				\  expand(""))
	windo if
				\ expand("%")=="diCt-tmp" |
				\ q!|endif
	25vsp diCt-tmp
	setlocal buftype=nofile bufhidden=hide noswapfile
	1s/^/\=expl/
	1
endfunction
nmap F :call Mydict()

""""""""""""""""""""""""""""""
" Tag list (ctags)
""""""""""""""""""""""""""""""
let Tlist_Ctags_Cmd = '/usr/bin/ctags' "设定linux系统中ctags程序的位置
let Tlist_Show_One_File = 1            "不同时显示多个文件的tag,只显示当前文件的
let Tlist_Exit_OnlyWindow = 1          "如果taglist窗口是最后一个窗口,则退出vim
let Tlist_Use_Right_Window = 1         "在右侧窗口中显示taglist窗口 
set tags=/home/ycg/Software/sandia/trilinos-12.12.1-Source/packages/tags,/home/ycg/Software/slepc-3.8.2/tags,/home/ycg/Software/petsc-3.8.3/tags,/home/ycg/Software/svnroot/jpsol/trunk/tags,/home/ycg/Software/svnroot/jxpamg/jxpamg/trunk/tags,/home/ycg/Software/svnroot/jaumin/trunk/tags,/home/ycg/Software/svnroot/jasmin/trunk/tags
"set tags=/home/ycg/Software/slepc-3.4.3/tags,/home/ycg/Software/petsc-3.4.3/tags,/home/ycg/Software/svnroot/jpsol/trunk/tags,/home/ycg/Software/svnroot/jxpamg/jxpamg/trunk/tags,/home/ycg/Software/svnroot/jaumin/trunk/tags,/home/ycg/Software/svnroot/jasmin/trunk/tags,/home/ycg/Software/hypre-2.11.1/src/examples/pase_ultimate/tags

"set foldenable              " 开始折叠
set nofoldenable              " 关闭折叠
set foldmethod=syntax       " 设置语法折叠
set foldcolumn=0            " 设置折叠区域的宽度
setlocal foldlevel=1        " 设置折叠层数为
"用空格键开关折叠
nnoremap  @=((foldclosed(line('.'))<0)?'zc':'zo')

"括号等的自动完成
function! OpenBrackets()
"	:inoremap ( ()i
"	:inoremap ) =ClosePair(')')
	:inoremap { {}O
	:inoremap } =ClosePair('}')
"	:inoremap [ []i
"	:inoremap ] =ClosePair(']')
"	:inoremap " ""i
"	:inoremap ' ''i
"	:inoremap $t <>i
"	:inoremap $b {}i
endfunction


function! CloseBrackets()
	inoremap ( (
	:inoremap { {
"	:inoremap { {}O
"	:inoremap } =ClosePair('}')
	inoremap [ [
	inoremap < <
	inoremap " "
	inoremap ' '
endfunction


"call OpenBrackets()

function! ClosePair(char)
	if getline('.')[col('.') - 1] == a:char
		return "\"
	else
		return a:char
	endif
endfunction

" Fast saving
nmap w  :w
nmap wq :wq
" Fast search
"map  /
" Fast no highlight
map   :noh
" No sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
" Set backspace config
set backspace=eol,start,indent
" Highlight the current line高亮显示当前行
"set cursorline


""""""""""""""""""""""""""""""
" => Statusline
""""""""""""""""""""""""""""""
" Always hide the statusline
set laststatus=2

" Format the statusline
"set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Line:\ %l/%L:%c

set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ Line:\ %l/%L:%c

function! CurDir()
    let curdir = substitute(getcwd(), '/Users/amir/', "~/", "g")
    return curdir
endfunction

function! HasPaste()
    if &paste
        return 'PASTE MODE  '
    else
			"将状态栏弄到右边
        return '                                   '
    endif
endfunction

"状态行颜色
"hi Statusline guifg=green guibg=red gui=None


""""""""""""""""""""""""""""""
" => Visual mode related
""""""""""""""""""""""""""""""
" Really useful!
"  In visual mode when you press * or # to search for the current selection
vnoremap  * :call VisualSearch('f')
vnoremap  # :call VisualSearch('b')

" When you press gv you vimgrep after the selected text
vnoremap  gv :call VisualSearch('gv')
map g :vimgrep // **/*.

function! CmdLine(str)
	exe "menu Foo.Bar :" . a:str
	emenu Foo.Bar
	unmenu Foo
endfunction 

" From an idea by Michael Naumann
function! VisualSearch(direction) range
	let l:saved_reg = @"
	execute "normal! vgvy"

	let l:pattern = escape(@", '\\/.*$^~[]')
	let l:pattern = substitute(l:pattern, "\n$", "", "")

	if a:direction == 'b'
		execute "normal ?" . l:pattern . "^M"
	elseif a:direction == 'gv'
		call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
	elseif a:direction == 'f'
		execute "normal /" . l:pattern . "^M"
	endif

	let @/ = l:pattern
	let @" = l:saved_reg
endfunction


" REQUIRED. This makes vim invoke Latex-Suite when you open a tex file.
filetype plugin on

" IMPORTANT: win32 users will need to have 'shellslash' set so that latex
" can be called correctly.
set shellslash

" IMPORTANT: grep will sometimes skip displaying the file name if you
" search in a singe file. This will confuse Latex-Suite. Set your grep
" program to always generate a file-name.
set grepprg=grep\ -nH\ $*

" OPTIONAL: This enables automatic indentation as you type.
filetype indent on

" OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
let g:tex_flavor='latex'

" Load automatically the menu of latex-suite
let g:tex_flavor="tex"

"c的编译和运行
"map :call CompileRunGcc() 
func! CompileRunGcc()
	exec "w"
	exec "!gcc % -o %<"
	exec "! ./%<"
endfunc

map  :wa:make:cw
map  :wa:!make
map  :wa:!make run
map  :wa:!make dist
nmap  
nmap  
imap  
imap  
imap  
imap  
nnoremap ; a
"set guicursor+=a:blinkon0

你可能感兴趣的:(linux)