我的 vimrc

简介:


tabBar.vim

这个插件实现了类似UltraEdit中的标签页的功能,而且能通过Alt-<n>来切换, 
安装:
拷贝文件到[你的gvim的安装目录]"vimfiles"plugin"中即可!
下载:
http://www.vim.org/scripts/script.php?script_id=1338

C:/Program Files/Vim/_vimrc

let $LANG="zh_CN.UTF-8"
set fileencodings=utf-8,chinese,latin-1
set termencoding=utf8
set encoding=utf-8
set tabstop=4
set softtabstop=4
set shiftwidth=4
set nocompatible
set incsearch
set autoindent
set smartindent
syntax on
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
  let eq  =   ' '
   if  $VIMRUNTIME  = '  '
     if   & sh  = ' \<cmd'
      let cmd  =   ' ""' . $VIMRUNTIME . '\diff"'
      let eq  =   ' "'
     else
      let cmd 
=  substitute($VIMRUNTIME,  '  ', '" ', '') . '\diff"'
    endif
  
else
    let cmd 
=  $VIMRUNTIME .  ' \diff'
  endif
  silent execute 
' !' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction






" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
 => 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 <leader>w saves the current file
let mapleader  =   " , "
let g:mapleader 
=   " , "

"  Fast saving
nmap  < leader > w :w! < cr >

"  Fast editing of the .vimrc
map  < leader > e :e! ~ / .vim_runtime / vimrc < cr >

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



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



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

"  When you press gv you vimgrep after the selected text
vnoremap  < silent >  gv : call  VisualSearch( ' gv')<CR>
map  < leader > g :vimgrep  //   **/* . < left >< left >< left >< left >< left >< left >< left >


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 
< C -\> eCurrentFileDir( " e " ) < cr >

"  $q is super useful when browsing on the command line
cno $q  < C -\> eDeleteTillSlash() < cr >

"  Bash like keys for the command line
cnoremap  < C - A >        < Home >
cnoremap 
< C - E >        < End >
cnoremap 
< C - K >        < C - U >

cnoremap 
< C - P >   < Up >
cnoremap 
< C - N >   < Down >

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


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



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

"  Smart way to move btw. windows
map  < C - j >   < C - W > j
map 
< C - k >   < C - W > k
map 
< C - h >   < C - W > h
map 
< C - l >   < C - W > l

"  Close the current buffer
map  < leader > bd :Bclose < cr >

"  Close all the buffers
map  < leader > ba : 1 , 300  bd! < cr >

"  Use the arrows to something usefull
map  < right >  :bn < cr >
map 
< left >  :bp < cr >

"  Tab configuration
map  < leader > tn :tabnew % < cr >
map 
< leader > te :tabedit
map 
< leader > tc :tabclose < cr >
map 
< leader > tm :tabmove

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


command ! Bclose  call   < SID > BufcloseCloseIt()
function < SID > 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   < esc > ` > a) < esc > ` < i( < esc >
vnoremap $
2   < esc > ` > a] < esc > ` < i[ < esc >
vnoremap $
3   < esc > ` > a} < esc > ` < i{ < esc >
vnoremap $$ 
< esc > ` > a " <esc>`<i " < esc >
vnoremap $q 
< esc > ` > a ' <esc>`<i'<esc>
vnoremap $e  < esc > ` > a " <esc>`<i " < esc >

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


" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
 => General Abbrevs
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
iab xdate  < c - r >= 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  < M - j >  mz:m +< cr > `z
nmap 
< M - k >  mz:m - 2 < cr > `z
vmap 
< M - j >  :m ' >+<cr>`<my`>mzgv`yo`z
vmap  < M - k >  :m ' <-2<cr>`>my`<mzgv`yo`z


" 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  < leader > cc :botright cope < cr >
map 
< leader > n :cn < cr >
map 
< leader > p :cp < cr >


" """""""""""""""""""""""""""" "
"  => 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 
< leader > u :TMiniBufExplorer < cr > :TMiniBufExplorer < cr >


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


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

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


" """""""""""""""""""""""""""" "
"  => Python section
"
"""""""""""""""""""""""""""" "
au FileType python 
set  nocindent
syn keyword pythonConstant 
True  None  False  self
au BufNewFile,BufRead 
* .jinja  set  syntax = htmljinja

au FileType python inoremap 
< buffer >  $r  return
au FileType python inoremap 
< buffer >  $i import
au FileType python inoremap 
< buffer >  $p  print
au FileType python inoremap 
< buffer >  $f # ---  PH  ----------------------------------------------< esc > FP2xi
au FileType python map 
< buffer >   < leader > C ? class
au FileType python map 
< buffer >   < leader > D ?def


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

au FileType javascript imap 
< c - t >  AJS.log(); < esc > hi
au FileType javascript imap 
< c - a >  alert(); < esc > hi

au FileType javascript inoremap 
< buffer >  $r  return
au FileType javascript inoremap 
< buffer >  $f  //---  PH  ----------------------------------------------< esc > 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  < leader > t :FufCWD  **/< CR >
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  < Leader > m mmHmt:%s /< C - V >< cr >// ge < cr > ' tzt'm

" Quickly open a buffer for scripbble
map  < leader > q :e ~ / buffer < cr >

本文转自博客园刘凯毅的博客,原文链接:我的 vimrc,如需转载请自行联系原博主。
目录
相关文章
|
11月前
|
开发工具
常用的vim配置,_vimrc文件
常用的vim配置,_vimrc文件
|
11月前
|
缓存 Java Shell
|
11月前
|
XML 编译器 程序员
|
11月前
|
IDE 开发工具 Windows
|
Shell 开发工具
5.10 Vim显示行号
在使用 Vim 进行编辑的过程中,经常会遇到需要同时对连续几行进行操作的情况,这时如果每行都有行号提示,就会非常方便。
194 0
5.10 Vim显示行号
|
缓存 开发工具
5.11 Vim配置文件(.vimrc)详解
Vim 启动时,会根据配置文件(.vimrc)来设置 Vim,因此我们可以通过此文件来定制适合自己的 Vim。
1050 0
5.11 Vim配置文件(.vimrc)详解
|
C++
.vimrc的配置
set nocompatible set encoding=utf-8 set fileencodings=utf-8,chinese set tabstop=4 set cindent shiftwidth=4 set backspace=indent,eol,start autocmd File...
806 0
|
开发工具
Vim使用笔记之.vimrc配置
之前陆陆续续有用过一点vim,但基本上都没有详细地去了解这个强大的编辑器,最近开始重新学习一下Vim。刚开始使用Vim的感觉就是好简洁,可以说是什么东西都没有,无从下手。
1932 0