Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1014331
  • 博文数量: 327
  • 博客积分: 9995
  • 博客等级: 中将
  • 技术积分: 4319
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-25 11:21
文章存档

2011年(31)

2010年(139)

2009年(157)

我的朋友

分类: LINUX

2010-06-15 14:27:58

1、配置文档的位置
    在目录 /etc/ 下面,有个名为vimrc的文档,这是系统中公共的vim配置文档,对任何用户都有效。而在每个用户的主目录下,都能够自己建立私有的配置文档,命名为:“.vimrc”。例如,/root目录下,通常已存在一个.vimrc文档。
 
2、配置语法高亮显示
1) 打开vimrc,添加以下语句来使得语法高亮显示:
    syntax on
2) 假如此时语法还是没有高亮显示,那么在/etc目录下的profile文档中添加以下语句:
    export TERM=xterm-color
3、配置Windows风格的C/C++自动缩进(添加以下set语句到vimrc中)
   1)不讨论制表符为8还是为4较好,这里配置(软)制表符宽度为4:
     set tabstop=4
     set softtabstop=4
   2)配置缩进的空格数为4
     set shiftwidth=4
   3)配置自动缩进:即每行的缩进值和上一行相等;使用 noautoindent 取消配置:
     set autoindent
   4)配置使用 C/C++ 语言的自动缩进方式:
     set cindent
   5)配置C/C++语言的具体缩进方式(以我的windows风格为例):
     set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s
   6)假如想在左侧显示文本的行号,能够用以下语句:
     set nu
   7)最后,假如没有下列语句,就加上吧:
if &term=="xterm"
    set t_Co=8
    set t_Sb=^[[4%dm
    set t_Sf=^[[3%dm
endif
PS:
自动缩进有两个选项:  
代码:
    set autoindent
    set cindent
  
autoindent 就是自动缩进的意思,当您在输入状态用回车键插入一个新行,或在 normal 状态用 o 或 O
插入一个新行时,autoindent会自动地将当前行的缩进拷贝到新行,也就是"自动对齐”,当然了,假如您在新行没有输入任何字符,那么这个缩进将自动删除。
 
cindent 就不同了,他会按照 C 语言的语法,自动地调整缩进的长度,比如,当您输入了半条语句然后回车时,缩进会自动增加一个 TABSTOP 值,当您键入了一个右花括号时,会自动减少一个TABSTOP 值。
 
史上最强的vimrc文件,据说有800行,还是作者精简后的结果.我在尽可能保留原作者的创意的前提下做了些小的修正,主要的修改如下:
增加了对win32系统的兼容,原来的vimrc文件只兼容linux和mac
修正了一些快捷键,例如ctr-q被原作者用来搜索buffer,用过win32版本vim的都知道ctrl-q被用来作为块编辑的快捷键,所以ctrl-q是万万不能被移做他用的.
去掉了colorscheme,原作者的colorscheme对我来说实在是太geeky,我想软件默认的colorscheme就该是最适合大多数人的.
启用了swap文件,因为我的机器配置太低,而且我经常要编辑大文件
取消了所有和python有关的plugin,因为一些路径问题,也因为我觉得vim对python的支持够强大了(事实是,我缺乏用python写大项目的经验).
增加了对中文编码的支持,参考了吴咏炜的一篇文章
兼容低版本vi,目前我在vim5.8.9, vim6.1,vim6.3, vim6.4,vim7.0, 上测试过。
其他一些通用性,兼容性的修正
去掉了输入([{时的自动填入右括号的功能,在我修改代码时增加很多麻烦.
 
我强烈建议你通读这个vimrc文件,一定会很有收获的,至少我是如此.

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" _
" __ |
" / | /
" __ |
" by Amix -
"
" Maintainer: Amir Salihefendic
" Version: 2.0
" Last Change: 12/08/06 13:39:28
" Fixed (win32 compatible) by: redguardtoo
" This vimrc file is tested on platforms like win32,linux, cygwin,mingw
" and vim7.0, vim6.4, vim6.1, vim5.8.9 by redguardtoo
"
" Tip:
" If you find anything that you can't understand than do this:
" help keyword OR helpgrep keyword
" Example:
" Go into command-line mode and type helpgrep nocompatible, ie.
" :helpgrep nocompatible
" then press c to see the results, or :botright cw
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Get out of VI's compatible mode..
set nocompatible

function! MySys()
if has("win32")
return "win32"
elseif has("unix")
return "unix"
else
return "mac"
endif
endfunction
"Set shell to be bash
if MySys() == "unix" || MySys() == "mac"
set shell=bash
else
"I have to run win32 python without cygwin
"set shell=E:cygwin insh
endif

"Sets how many lines of history VIM har to remember
set history=400

"Enable filetype plugin
filetype on
if has("eval") && v:version>=600
filetype plugin on
filetype indent on
endif

"Set to auto read when a file is changed from the outside
if exists("&autoread")
set autoread
endif

"Have the mouse enabled all the time:
set mouse=a

"Set mapleader
let mapleader = ","
let g:mapleader = ","

"Fast saving
nmap w :w!


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Font
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Enable syntax hl
if MySys()=="unix"
if v:version<600
if filereadable(expand("$VIM/syntax/syntax.vim"))
syntax on
endif
else
syntax on
endif
else
syntax on
endif

"internationalization
"I only work in Win2k Chinese version
if has("multi_byte")
set termencoding=chinese
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,chinese
endif

"if you use vim in tty,
"'uxterm -cjk' or putty with option 'Treat CJK ambiguous characters as wide' on
if exists("&ambiwidth")
set ambiwidth=double
endif

if has("gui_running")
set guioptions-=m
set guioptions-=T
set guioptions-=l
set guioptions-=L
set guioptions-=r
set guioptions-=R

if MySys()=="win32"
"start gvim maximized
if has("autocmd")
au GUIEnter * simalt ~x
endif
endif
"let psc_style='cool'
"colorscheme ps_color
"colorscheme default
else
"set background=dark
"colorscheme default
endif

"Some nice mapping to switch syntax (useful if one mixes different languages in one file)
map 1 :set syntax=cheetah
map 2 :set syntax=xhtml
map 3 :set syntax=python
map 4 :set ft=javascript
map $ :syntax sync fromstart

"Highlight current
if has("gui_running")
if exists("&cursorline")
set cursorline
endif
endif

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Fileformat
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Favorite filetype
set ffs=unix,dos,mac

nmap fd :se ff=dos
nmap fu :se ff=unix



"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM userinterface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Set 7 lines to the curors - when moving vertical..
set so=7

"Turn on WiLd menu
set wildmenu

"Always show current position
set ruler

"The commandbar is 2 high
set cmdheight=2

"Show line number
set nu

"Do not redraw, when running macros.. lazyredraw
set lz

"Change buffer - without saving
set hid

"Set backspace
set backspace=eol,start,indent

"Bbackspace and cursor keys wrap to
set whichwrap+=<,>,h,l

"Ignore case when searching
"set ignorecase
set incsearch

"Set magic on
set magic

"No sound on errors.
set noerrorbells
set novisualbell
set t_vb=

"show matching bracet
set showmatch

"How many tenths of a second to blink
set mat=4

"Highlight search thing
set hlsearch

""""""""""""""""""""""""""""""
" => Statusline
""""""""""""""""""""""""""""""
"Format the statusline
" Nice statusbar
set laststatus=2
set statusline=
set statusline+=%2*%-3.3n%0*\ " buffer number
set statusline+=%f\ " file name
set statusline+=%h%1*%m%r%w%0* " flag
set statusline+=[
if v:version >= 600
set statusline+=%{strlen(&ft)?&ft:'none'}, " filetype
set statusline+=%{&encoding}, " encoding
endif
set statusline+=%{&fileformat}] " file format
if filereadable(expand("$VIM/vimfiles/plugin/vimbuddy.vim"))
set statusline+=\ %{VimBuddy()} " vim buddy
endif
set statusline+=%= " right align
set statusline+=%2*0x%-8B\ " current char
set statusline+=%-14.(%l,%c%V%)\ %<%P " offset

" special statusbar for special window
if has("autocmd")
au FileType qf
\ if &buftype == "quickfix" |
\ setlocal statusline=%2*%-3.3n%0* |
\ setlocal statusline+=\ \[Compiler\ Messages\] |
\ setlocal statusline+=%=%2*\ %<%P |
\ endif

fun! FixMiniBufExplorerTitle()
if "-MiniBufExplorer-" == bufname("%")
setlocal statusline=%2*%-3.3n%0*
setlocal statusline+=\[Buffers\]
setlocal statusline+=%=%2*\ %<%P
endif
endfun

if v:version>=600
au BufWinEnter *
\ let oldwinnr=winnr() |
\ windo call FixMiniBufExplorerTitle() |
\ exec oldwinnr . " wincmd w"
endif
endif

" Nice window title
if has('title') && (has('gui_running') || &title)
set titlestring=
set titlestring+=%f\ " file name
set titlestring+=%h%m%r%w " flag
set titlestring+=\ -\ %{v:progname} " program name
endif



"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around and tab
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Map space to / and c-space to ?
map /

"Smart way to move btw. window
map j
map k
map h
map l

"Actually, the tab does not switch buffers, but my arrow
"Bclose function ca be found in "Buffer related" section
map bd :Bclose
map bd
"Use the arrows to something usefull
map :bn
map :bp

"Tab configuration
map tn :tabnew %
map tc :tabclose
map tm :tabmove

if v:version>=700
set switchbuf=usetab
endif

if exists("&showtabline")
set stal=2
endif

"Moving fast to front, back and 2 sides ;)
imap $a
imap 0i
imap $a
imap 0i


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General Autocommand
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Switch to current dir
map cd :cd %:p:h


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Parenthesis/bracket expanding
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
vnoremap $1 `>a)`
")
vnoremap $2 `>a]`
vnoremap $3 `>a}`
vnoremap $$ `>a"`
vnoremap $q `>a'`
vnoremap $w `>a"`
imap la
imap ha

"Map auto complete of (, ", ', [
"
"

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General Abbrev
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Comment for C like language
if has("autocmd")
au BufNewFile,BufRead *.js,*.htc,*.c,*.tmpl,*.css ino $c /** **/O
endif

"My information
ia xdate =strftime("%d/%m/%y %H:%M:%S")
"iab xname Amir Salihefendic

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Editing mappings etc.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Remap VIM 0
map 0 ^

"Move a line of text using control
nmap mz:m+`z
nmap mz:m-2`z
vmap :m'>+`mzgv`yo`z
vmap :m'<-2`>my`
if MySys() == "mac"
nmap
nmap
vmap
vmap
endif


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Command-line config
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
func! Cwd()
let cwd = getcwd()
return "e " . cwd
endfunc

func! DeleteTillSlash()
let g:cmd = getcmdline()
if MySys() == "unix" || MySys() == "mac"
let g:cmd_edited = substitute(g:cmd, "(.*[/]).*", " ", "")
else
let g:cmd_edited = substitute(g:cmd, "(.*[\]).*", " ", "")
endif
if g:cmd == g:cmd_edited
if MySys() == "unix" || MySys() == "mac"
let g:cmd_edited = substitute(g:cmd, "(.*[/]).*/", " ", "")
else
let g:cmd_edited = substitute(g:cmd, "(.*[\]).*[\]", " ", "")
endif
endif
return g:cmd_edited
endfunc

func! CurrentFileDir(cmd)
return a:cmd . " " . expand("%:p:h") . "/"
endfunc

"cno $q eDeleteTillSlash()
"cno $c e eCurrentFileDir("e")
"cno $tc eCurrentFileDir("tabnew")
cno $th tabnew ~/
cno $td tabnew ~/Desktop/

"Bash like
cno
cno
cno


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Buffer realted
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Fast open a buffer by search for a name
"map :sb

"Open a dummy buffer for paste
map q :e ~/buffer

"Restore cursor to file position in previous editing session
set viminfo='10,"100,:20,%,n~/.viminfo

" Buffer - reverse everything ... :)
map ggVGg?

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files and backup
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Turn backup off
set nobackup
set nowb
"set noswapfile

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Folding
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Enable folding, I find it very useful
if exists("&foldenable")
set fen
endif

if exists("&foldlevel")
set fdl=0
endif

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text option
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" python script
"set expandtab
set shiftwidth=2
set softtabstop=2
set tabstop=2
set backspace=2
set smarttab
set lbr
"set tw=500

""""""""""""""""""""""""""""""
" => Indent
""""""""""""""""""""""""""""""
"Auto indent
set ai

"Smart indet
set si

"C-style indenting
set cindent

"Wrap line
set wrap


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Spell checking
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map sn ]
map sp [
map sa zg
map s? z=


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin configuration
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""
" => Yank Ring
""""""""""""""""""""""""""""""
map y :YRShow

""""""""""""""""""""""""""""""
" => File explorer
""""""""""""""""""""""""""""""
"Split vertically
let g:explVertical=1

"Window size
let g:explWinSize=35

let g:explSplitLeft=1
let g:explSplitBelow=1

"Hide some file
let g:explHideFiles='^.,.*.class$,.*.swp$,.*.pyc$,.*.swo$,.DS_Store$'

"Hide the help thing..
let g:explDetailedHelp=0


""""""""""""""""""""""""""""""
" => Minibuffer
""""""""""""""""""""""""""""""
let g:miniBufExplModSelTarget = 1
let g:miniBufExplorerMoreThanOne = 0
let g:miniBufExplModSelTarget = 0
let g:miniBufExplUseSingleClick = 1
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplVSplit = 25
let g:miniBufExplSplitBelow=1

"WindowZ
map :WMToggle

let g:bufExplorerSortBy = "name"


""""""""""""""""""""""""""""""
" => Tag list (ctags) - not used
""""""""""""""""""""""""""""""
"let Tlist_Ctags_Cmd = "/sw/bin/ctags-exuberant"
"let Tlist_Sort_Type = "name"
"let Tlist_Show_Menu = 1
"map t :Tlist
map :Tlist


""""""""""""""""""""""""""""""
" => LaTeX Suite thing
""""""""""""""""""""""""""""""
"set grepprg=grep -r -s -n
let g:Tex_DefaultTargetFormat="pdf"
let g:Tex_ViewRule_pdf='xpdf'

if has("autocmd")
"Binding
au BufRead *.tex map :w! :silent! call Tex_RunLaTeX()

"Auto complete some things ;)
au BufRead *.tex ino $i indent
au BufRead *.tex ino $* cdot
au BufRead *.tex ino $i item
au BufRead *.tex ino $m []O
endif

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Filetype generic
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Todo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"au BufNewFile,BufRead *.todo so ~/vim_local/syntax/amido.vim

""""""""""""""""""""""""""""""
" => VIM
""""""""""""""""""""""""""""""
if has("autocmd") && v:version>600
au BufRead,BufNew *.vim map :w!:source %
endif

""""""""""""""""""""""""""""""
" => HTML related
""""""""""""""""""""""""""""""
" HTML entities - used by xml edit plugin
let xml_use_xhtml = 1
"let xml_no_auto_nesting = 1

"To HTML
let html_use_css = 0
let html_number_lines = 0
let use_xhtml = 1


""""""""""""""""""""""""""""""
" => Ruby & PHP section
""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""
" => Python section
""""""""""""""""""""""""""""""
""Run the current buffer in python - ie. on leader+space
"au BufNewFile,BufRead *.py so ~/vim_local/syntax/python.vim
"au BufNewFile,BufRead *.py map :w!:!python %
"au BufNewFile,BufRead *.py so ~/vim_local/plugin/python_fold.vim

""Set some bindings up for 'compile' of python
"au BufNewFile,BufRead *.py set makeprg=python -c "import py_compile,sys; sys.stderr=sys.stdout; py_compile.compile(r'%')"
"au BufNewFile,BufRead *.py set efm=%C %.%#,%A File "%f", line %l%.%#,%Z%[%^ ]%@=%m
"au BufNewFile,BufRead *.py nmap :w!:make

""Python iMap
"au BufNewFile,BufRead *.py set cindent
"au BufNewFile,BufRead *.py ino $r return
"au BufNewFile,BufRead *.py ino $s self
"au BufNewFile,BufRead *.py ino $c ####kla
"au BufNewFile,BufRead *.py ino $i import
"au BufNewFile,BufRead *.py ino $p print
"au BufNewFile,BufRead *.py ino $d """"""O

""Run in the Python interpreter
"function! Python_Eval_VSplit() range
" let src = tempname()
" let dst = tempname()
" execute ": " . a:firstline . "," . a:lastline . "w " . src
" execute ":!python " . src . " > " . dst
" execute ":pedit! " . dst
"endfunction
"au BufNewFile,BufRead *.py vmap :call Python_Eval_VSplit()


""""""""""""""""""""""""""""""
" => Cheetah section
"""""""""""""""""""""""""""""""

"""""""""""""""""""""""""""""""
" => Java section
"""""""""""""""""""""""""""""""

""""""""""""""""""""""""""""""
" => JavaScript section
"""""""""""""""""""""""""""""""
"au BufNewFile,BufRead *.js so ~/vim_local/syntax/javascript.vim
"function! JavaScriptFold()
" set foldmethod=marker
" set foldmarker={,}
" set foldtext=getline(v:foldstart)
"endfunction
"au BufNewFile,BufRead *.js call JavaScriptFold()
"au BufNewFile,BufRead *.js imap console.log();hi
"au BufNewFile,BufRead *.js imap alert();hi
"au BufNewFile,BufRead *.js set nocindent
"au BufNewFile,BufRead *.js ino $r return

"au BufNewFile,BufRead *.js ino $d //////ka
"au BufNewFile,BufRead *.js ino $c /****/ka


if has("eval") && has("autocmd")
"vim 5.8.9 on mingw donot know what is , so I avoid to use function
"c/cpp
fun! Abbrev_cpp()
ia cci const_iterator
ia ccl cla
ia cco const
ia cdb bug
ia cde throw
ia cdf /** file/
ia cdg ingroup
ia cdn /** Namespace /
ia cdp param
ia cdt test
ia cdx /**/
ia cit iterator
ia cns Namespace ianamespace
ia cpr protected
ia cpu public
ia cpv private
ia csl std::list
ia csm std::map
ia css std::string
ia csv std::vector
ia cty typedef
ia cun using Namespace ianamespace
ia cvi virtual
ia #i #include
ia #d #define
endfunction

fun! Abbrev_java()
ia #i import
ia #p System.out.println
ia #m public static void main(String[] args)
endfunction

fun! Abbrev_python()
ia #i import
ia #p print
ia #m if __name__=="__main":
endfunction
augroup abbreviation
au!
au FileType cpp,c :call Abbrev_cpp()
au FileType java :call Abbrev_java()
au FileType python :call Abbrev_python()
augroup END
endif

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => MISC
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Remove the Windows ^M
noremap m :%s/r//g

"Paste toggle - when pasting something in, don't indent.
"set pastetoggle=

"Remove indenting on empty line
map :%s/\s*$//g:noh''

"Super paste
ino :set pastemui+mv'uV'v=:set nopaste

附原链接如下:

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
Maintainer: amix the lucky stiff
" - amix@amix.dk
"

" Version: 3.3 - 21/01/10 01:05:46
"

" Blog_post:
"
blog/post/19486#The-ultimate-vim-configuration-vimrc
" Syntax_highlighted:
"
vim/vimrc.html
" Raw_version:
"
vim/vimrc.txt
"
"
How_to_Install:
" $ mkdir ~/.vim_runtime
"
$ svn co svn://orangoo.com/vim ~/.vim_runtime
" $ cat ~/.vim_runtime/install.sh
"
$ sh ~/.vim_runtime/install.sh
" can be `mac`, `linux` or `windows`
"

" How_to_Upgrade:
"
$ svn update ~/.vim_runtime
"
"
Sections:
" -> General
"
-> VIM user interface
" -> Colors and Fonts
"
-> Files and backups
" -> Text, tab and indent related
"
-> Visual mode related
" -> Command mode related
"
-> Moving around, tabs and buffers
" -> Statusline
"
-> Parenthesis/bracket expanding
" -> General Abbrevs
"
-> Editing mappings
"
"
-> Cope
" -> Minibuffer plugin
"
-> Omni complete functions
" -> Python section
"
-> JavaScript section
"
"
Plugins_Included:
" > minibufexpl.vim -
"
Makes it easy to get an overview of buffers:
" info -> :e ~/.vim_runtime/plugin/minibufexpl.vim
"

" > bufexplorer -
"
Makes it easy to switch between buffers:
" info -> :help bufExplorer
"

" > yankring.vim -
"
Emacs's killring, useful when using the clipboard:
" info -> :help yankring
"

" > surround.vim -
"
Makes it easy to work with surrounding text:
" info -> :help surround
"

" > snipMate.vim -
"
Snippets for many languages (similar to TextMate's):
" info -> :help snipMate
"

" > fuzzyfinder -
"
Find files fast (similar to TextMate's feature):
" info -> :help fuzzyfinder@en
"

" Revisions:
"
> 3.3: Added syntax highlighting for Mako mako.vim
" > 3.2: Turned on python_highlight_all for better syntax
"
highlighting for Python
" > 3.1: Added revisions ;) and bufexplorer.vim
"

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"


"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
set history=300

"
Enable filetype plugin
filetype plugin on
filetype indent on

" Set to auto read when a file is changed from the outside
set autoread

"
With a map leader it's possible to do extra key combinations
" like w saves the current file
let mapleader = "
,
"
let g:mapleader = "
,
"

"
Fast saving
nmap w :w!

" Fast editing of the .vimrc
map e :e! ~/.vim_runtime/vimrc

"
When vimrc is edited, reload it
autocmd! bufwritepost vimrc source ~/.vim_runtime/vimrc


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"
=> VIM user interface
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"
Set 7 lines to the curors - when moving vertical..
set so=7

set wildmenu
"Turn on WiLd menu

set ruler "
Always show current position

set cmdheight=2
"The commandbar height

set hid "
Change buffer - without saving

" Set backspace config
set backspace=eol,start,indent
set whichwrap+=<,>,h,l

set ignorecase "
Ignore case when searching

set hlsearch
"Highlight search things

set incsearch "
Make search act like search in modern browsers

set magic
"Set magic on, for regular expressions

set showmatch "
Show matching bracets when text indicator is over them
set mat=2
"How many tenths of a second to blink

"
No sound on errors
set noerrorbells
set novisualbell
set t_vb=


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"
=> Colors and Fonts
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
syntax enable "
Enable syntax hl

" Set font according to system
if MySys() == "
mac
"
  set gfn=Bitstream\ Vera\ Sans\ Mono:h13
  set shell=/bin/bash
elseif MySys() == "
windows
"
  set gfn=Bitstream\ Vera\ Sans\ Mono:h10
elseif MySys() == "
linux
"
  set gfn=Monospace\ 10
  set shell=/bin/bash
endif

if has("
gui_running
")
  set guioptions-=T
  set background=dark
  set t_Co=256
  set background=dark
  colorscheme peaksea

  set nu
else
  colorscheme zellner
  set background=dark
  
  set nonu
endif

set encoding=utf8
try
    lang en_US
catch
endtry

set ffs=unix,dos,mac "
Default file types


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"
=> Files and backups
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"
Turn backup off, since most stuff is in SVN, git anyway...
set nobackup
set nowb
set noswapfile


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"
=> Text, tab and indent related
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
set expandtab
set shiftwidth=4
set tabstop=4
set smarttab

set lbr
set tw=500

set ai "
Auto indent
set si
"Smart indet
set wrap "
Wrap lines

map t2 :setlocal shiftwidth=2
map t4 :setlocal shiftwidth=4
map t8 :setlocal shiftwidth=4


""""""""""""""""""""""""""""""
" => 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



""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"
=> Command mode related
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"
Smart mappings on the command line
cno $h e ~/
cno $d e ~/Desktop/
cno $j e ./
cno $c e eCurrentFileDir("e")<cr>

" $q is super useful when browsing on the command line
cno $q eDeleteTillSlash()

"
Bash like keys for the command line
cnoremap
cnoremap
cnoremap

cnoremap
cnoremap

" Useful on some European keyboards
map ½ $
imap ½ $
vmap ½ $
cmap ½ $


func! Cwd()
  let cwd = getcwd()
  return "
e
" . cwd
endfunc

func! DeleteTillSlash()
  let g:cmd = getcmdline()
  if MySys() == "
linux" || MySys() == "mac
"
    let g:cmd_edited = substitute(g:cmd, "
\\(.*\[/\]\\).*", "\\1", "
")
  else
    let g:cmd_edited = substitute(g:cmd, "
\\(.*\[\\\\]\\).*", "\\1", "
")
  endif
  if g:cmd == g:cmd_edited
    if MySys() == "
linux" || MySys() == "mac
"
      let g:cmd_edited = substitute(g:cmd, "
\\(.*\[/\]\\).*/", "\\1", "
")
    else
      let g:cmd_edited = substitute(g:cmd, "
\\(.*\[\\\\\]\\).*\[\\\\\]", "\\1", "
")
    endif
  endif
  return g:cmd_edited
endfunc

func! CurrentFileDir(cmd)
  return a:cmd . "
" . expand("%:p:h") . "/
"
endfunc


"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around, tabs and buffers
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Map space to / (search) and c-space to ? (backgwards search)
map /
map ?
map :noh

"
Smart way to move btw. windows
map j
map k
map h
map l

" Close the current buffer
map bd :Bclose

"
Close all the buffers
map ba :1,300 bd!

" Use the arrows to something usefull
map :bn
map :bp

"
Tab configuration
map tn :tabnew %
map te :tabedit
map tc :tabclose
map tm :tabmove

" When pressing cd switch to the directory of the open buffer
map cd :cd %:p:h


command! Bclose call BufcloseCloseIt()
function! BufcloseCloseIt()
   let l:currentBufNum = bufnr("
%
")
   let l:alternateBufNum = bufnr("
#
")

   if buflisted(l:alternateBufNum)
     buffer #
   else
     bnext
   endif

   if bufnr("
%
") == l:currentBufNum
     new
   endif

   if buflisted(l:currentBufNum)
     execute("
bdelete!
".l:currentBufNum)
   endif
endfunction

"
Specify the behavior when switching between buffers
try
  set switchbuf=usetab
  set stal=2
catch
endtry


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

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


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


"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Parenthesis/bracket expanding
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
vnoremap $1 `>a)`
vnoremap $2 `>a]`
vnoremap $3 `>a}`
vnoremap $$ `>a"
<esc>`"
vnoremap $q `>a'`
vnoremap $e `>a"
<esc>`"

" Map auto complete of (,
", ', [
inoremap $1 ()i
inoremap $2 []i
inoremap $3 {}i
inoremap $4 {o}O
inoremap $q ''i
inoremap $e "
"i


"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General Abbrevs
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
iab xdate =strftime("%d/%m/%y %H:%M:%S")<cr>


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"
=> Editing mappings
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"
Remap VIM 0
map 0 ^

"Move a line of text using ALT+[jk] or Comamnd+[jk] on mac
nmap mz:m+`z
nmap mz:m-2`z
vmap :m'>+`mzgv`yo`z
vmap :m'<-2`>my`
if MySys() == "
mac
"
  nmap
  nmap
  vmap
  vmap
endif

"
Delete trailing white space, useful for Python ;)
func! DeleteTrailingWS()
  exe "normal mz"
  %s/\s\+$//ge
  exe "normal `z"
endfunc
autocmd BufWrite *.py :call DeleteTrailingWS()


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"
=> Cope
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"
Do :help cope if you are unsure what cope is. It's super useful!
map cc :botright cope
map n :cn
map p :cp


""""""""""""""""""""""""""""""
" => bufExplorer plugin
"
""""""""""""""""""""""""""""
"
let g:bufExplorerDefaultHelp=0
let g:bufExplorerShowRelativePath=1


"
""""""""""""""""""""""""""""
"
"
=> Minibuffer plugin
""""""""""""""""""""""""""""""
let g:miniBufExplModSelTarget = 1
let g:miniBufExplorerMoreThanOne = 2
let g:miniBufExplModSelTarget = 0
let g:miniBufExplUseSingleClick = 1
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplVSplit = 25
let g:miniBufExplSplitBelow=1

let g:bufExplorerSortBy = "name"

autocmd BufRead,BufNew :call UMiniBufExplorer

map u :TMiniBufExplorer:TMiniBufExplorer


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
"
=> Omni complete functions
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
autocmd FileType css set omnifunc=csscomplete#CompleteCSS


"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Spell checking
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Pressing ,ss will toggle and untoggle spell checking
map ss :setlocal spell!

"
Shortcuts using
map sn ]s
map sp [s
map sa zg
map s? z=


""""""""""""""""""""""""""""""
" => Python section
"
""""""""""""""""""""""""""""
"
au FileType python set nocindent
let python_highlight_all = 1
au FileType python syn keyword pythonDecorator True None False self

au BufNewFile,BufRead *.jinja set syntax=htmljinja
au BufNewFile,BufRead *.mako set ft=mako

au FileType python inoremap $r return
au FileType python inoremap $i import
au FileType python inoremap $p print
au FileType python inoremap $f #--- PH ----------------------------------------------FP2xi
au FileType python map 1 /class
au FileType python map 2 /def
au FileType python map C ?class
au FileType python map D ?def


"
""""""""""""""""""""""""""""
"
"
=> JavaScript section
""""""""""""""""""""""""""""""
"
au FileType javascript call JavaScriptFold()
au FileType javascript setl fen
au FileType javascript setl nocindent

au FileType javascript imap AJS.log();hi
au FileType javascript imap alert();hi

au FileType javascript inoremap $r return
au FileType javascript inoremap $f //--- PH ----------------------------------------------FP2xi

function! JavaScriptFold()
    setl foldmethod=syntax
    setl foldlevelstart=1
    syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend

    function! FoldText()
    return substitute(getline(v:foldstart), '{.*', '{...}', '')
    endfunction
    setl foldtext=FoldText()
endfunction


"
""""""""""""""""""""""""""""
"
"
=> Fuzzy finder
""""""""""""""""""""""""""""""
try
    call fuf#defineLaunchCommand('FufCWD', 'file', 'fnamemodify(getcwd(), ''%:p:h'')')
    map t :FufCWD **/
catch
endtry


""""""""""""""""""""""""""""""
" => Vim grep
"
""""""""""""""""""""""""""""
"
let Grep_Skip_Dirs = 'RCS CVS SCCS .svn generated'
set grepprg=/bin/grep\ -nH


"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => MISC
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remove the Windows ^M - when the encodings gets messed up
noremap m mmHmt:%s///ge'tzt'm

"
Quickly open a buffer for scripbble
map q :e ~/buffer

 
阅读(2797) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~