无插件定制web vim开发环境基本版

来源:互联网 发布:笑声音效软件 编辑:程序博客网 时间:2024/06/07 23:48
"本vimrc配置大部分参考了一位大神的vimrc,不过忘了他的地址了,希望大神见到不要见怪,废话不多说,直接上菜" See: http://vimdoc.sourceforge.net/htmldoc/options.html for details"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""=> General""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""设定 gvim 运行在增强模式下,不使用vi的键盘模式set nocompatible"设置支持多语言,解决乱码"设置内部编码为utf-8set encoding=utf-8set termencoding=utf-8set fileencodings=utf-8,gbk,default,latin1"解决consle输出乱码language messages zh_CN.utf-8"帮助菜单语言set helplang=cn" Sets how many lines of history VIM has to remember set history=700 " Enable filetype plugins filetype on 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> "启动时不显示援助提示 set shormess=atI"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => VIM user interface""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""Set 7 lines to the cursor - when moving vertically using j/k"光标离上下边界7行时开始滚屏set so=7" Turn on the Wild menuset wildmenu" Ignore compiled filesset wildignore=*.o,*~,*.pycif has("win16") || has("win32")  set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Storeelse  set wildignore+=.git\*,.hg\*,.svn\*endif " Height of the command bar set cmdheight=2 " Configure backspace so it acts as it should act set backspace=eol,start,indent set whichwrap+=<,>,h,l" Ignore case when searchingset ignorecase" When searching try to be smart about cases set smartcase" Highlight search resultsset hlsearch" Makes search act like search in modern browsersset incsearch" Following line clears the search highlights when pressing Lb nnoremap <leader>/ :nohlsearch<CR> "Don't redraw while executing macros (good performance config)set lazyredraw" For regular expressions turn magic onset magic" Show matching brackets when text indicator is over themset showmatch" How many tenths of a second to blink when matching bracketsset mat=2" No annoying sound on errorsset noerrorbellsset novisualbellset t_vb=set tm=500"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Colors and Fonts"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Enable syntax highlightingsyntax enabletry  colorscheme desertcatchendtryset background=dark" Set extra options when running in GUI modeif has("gui_running")set guioptions-=Tset guioptions+=eset t_Co=256set guitablabel=%M\ %tendif" Use Unix as the standard file typeset ffs=unix,dos,mac"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Files, backups and undo"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Turn backup off, since most stuff is in SVN, git et.c anyway...set nobackupset nowbset noswapfile"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Text, tab and indent related"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Use spaces instead of tabsset expandtab" Be smart when using tabs ;)set smarttab"对于不同类型的文件,进行自定义设置au FileType html,python,vim,javascript,css setl shiftwidth=2au FileType html,python,vim,javascript,css setl tabstop=2au FileType java,php setl shiftwidth=4au FileType java,php setl tabstop=4"设置每行的最大字符数,超过的话,将换行set textwidth=80" Linebreak on 500 charactersset lbrset tw=500set ai    "Auto indentset si    "Smart indentset wrap  "Wrap lines""""""""""""""""""""""""""""""" => Visual mode related""""""""""""""""""""""""""""""" Visual mode pressing * or # searches for the current selection" Super useful! From an idea by Michael Naumann"vnoremap <silent> * :call VisualSelection('f')<CR>"vnoremap <silent> # :call VisualSelection('b')<CR>"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Moving around, tabs, windows and buffers"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Treat long lines as break lines (useful when moving around in them)map j gjmap k gk" Moving Between Windowsnnoremap <Leader>h <C-w>hnnoremap <Leader>l <C-w>lnnoremap <Leader>j <C-w>jnnoremap <Leader>k <C-w>knnoremap <Leader>wo <C-w>onnoremap <Leader>wv <C-w>v<C-w>lnnoremap <Leader>ws <C-w>snnoremap <Leader>ww <C-w><C-w>""""""""""""""""""""""""""""""" => Status line""""""""""""""""""""""""""""""" Always show the status lineset laststatus=2" Format the status lineset statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ \ \ \ \line:\%-14.(%l,%c%V%)\ %P"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Editing mappings"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Remap VIM 0 to first non-blank charactermap 0 ^" type S, then type what you're looking for, a /, and what to replace it withnmap S :%s/<C-R><C-W>\>//g<LEFT><LEFT>vmap S :s/<C-R><C-W>\>//g<LEFT><LEFT>inoremap ( ()<ESC>iinoremap ) <c-r>=ClosePair(')')<CR>inoremap [ []<ESC>iinoremap ] <c-r>=ClosePair(']')<CR>imap { {}<ESC><LEFT>inoremap } <c-r>=ClosePair('}')"基本编辑器设置set number          "显示行号set laststatus=2    "显示状态栏 (默认值为 1, 无法显示状态栏)set cmdheight=1     "设定命令行的行数为 1set showtabline=2   "显示tab标签set tabline+=%f     "tab标签" Enable Code Foldingset foldenableset foldmethod=syntaxset mouse=a         "任何情况都可以使用鼠标)"工作目录随文件变autocmd BufEnter * cd %:p:h"不显示工具条set guioptions-=T" 配置文件.vimrc更改后自动重新载入使设置生效autocmd! bufwritepost .vimrc source ~/.vimrc "设置重新载入.vimrc快捷键map <silent> <leader>ss :source ~/.vimrc<cr>" 设置快速编辑.vimrc快捷键map <silent> <leader>ee :e ~/.vimrc<cr> """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" => Helper functions"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""function! ClosePair(char)    if getline('.')[col('.') - 1] == a:char      return "\<Right>"    else      return a:charendfunction  function! HasPaste()  if &paste    return 'PASTE MODE '  en  return ''endfunction""新建.html,.php文件自动插入文件头"autocmd BufNewFile *.html,*.php exec ":call MySetTitle()"""定义函数SetTitle,自动插入文件头"func MySetTitle()"  if &filetype == 'html'"    call setline(1,"<!DOCTYPE html>")"    call append(line("."),"<html>")"    call append(line(".")+1,"  <head>")"    call append(line(".")+2,"     ")"    call append(line(".")+3," </head>")"    call append(line(".")+4,"</html>")"    call append(line(".")+5,"")"  endif"  if &filetype == 'php'"    call setline(1,"<?php")"    call append(line("."),"")"  endif"endfunc"map <F5> :call CompileRun(  )  <CR>func! CompileRun()   exec "w"  if &filetype == 'c'    exec "!gcc % -o %<"    exec "!time ./%<"  elseif &filetype = 'cpp'    exec "!g++ % -o %<"    exec "!time ./%<"  elseif &filetype = 'sh'    :!time bash %  elseif &filetype = 'python'    exec "!time python2.7 %"  elseif &filetype = 'html'    exec "!firefox % &"  endifendfunc"C,C++的调试map <F8> :call Rungdb()<CR>func! Rungdb()  exec "w"  exec "!g++ % -g -o %<"  exec "!gdb ./%<"endfunc"function! CmdLine(str)"    exe "menu Foo.Bar :" . a:str"    emenu Foo.Bar"    unmenu Foo"endfunction""function! VisualSelection(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 == 'replace' "        call CmdLine("%s". '/'.l:pattern.'/')"    elseif a:direction == 'f' "        execute "normal /".l:pattern."^M""    endif""    let @/ = l:pattern"    let @" = l:saved_reg"endfunction" Returns true if paste mode is enabled


0 0
原创粉丝点击