我的vim配置文件vimrc

有一个笑话大致是这样说的,一群程序员捡到一箱子钱,怎么才能得到他们手中的这箱钱。办法就是告诉他们,记事本比vim和emacs好。虽然是个笑话,其实还是有它的道理,那就是对所有码农或频繁使用文本编辑器的人来说,他们习惯和认可的编辑器在他们的心里有着重要的位置,一般来说不喜欢被别人否认。我在windows下面用的最多的是记事本,因为只用来记录文字的话我觉得它够快就行。在linux下用的是vim,emacs我没有用过,所以一点儿也不了解。

我分享一下我的vim配置文件vimrc。一般来说vimrc文件在/etc/vim/目录下,它是vim的配置文件。vim的界面和一些编辑习惯是可以在这里根据自己的需求设置的。下面这是我的vim的风格界面,凡是和编辑风格有关的内容都可以在这里设置,网上有很多关于vimrc的资料可查,也可以到vim看帮助。一个配置的很好的vim编辑器是可以让你更加事半功倍,当然还有一些vim的插件也是可以用的比如vim-rails、fuzzyfinder、ctags等等,可以在你写代码的时候更快更灵活。所以说当你爱上vim就不会再放下它。

vim配置

再来看看我的vimrc文件,当然这个文件也可以放在自己注册的代码托管平台上。和我一样的新手朋友可以先用这个,以后再根据自己的需要折腾你的vim。双引号相当于是注释作用,可以多写一些属性进去,把需要的属性前去掉双引号,不需要的属性可以再用双引号注释掉,很有意思,也许从这里可以看到我们所说的“自由”吧。

" 在处理未保存或只读文件的时候,弹出确认
set confirm
" 带有如下符号的单词不要被换行分割
set iskeyword+=_,$,@,%,#,-
" 不使用vi默认键盘布局
set nocompatible
"设置编码
set encoding=utf-8
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
set fileencodings=utf-8,ucs-bom,chinese

"语言设置
set langmenu=zh_CN.UTF-8

" 显示行号
set number
" 智能对齐
set smartindent
" 括号匹配模式
set showmatch
" 显示状态行
set ruler

"设置配色方案
colorscheme torte

"可以在buffer的任何地方使用鼠标
set mouse=a
set selection=exclusive
set selectmode=mouse,key

set incsearch
" tab键为4个空格
set tabstop=4
set shiftwidth=4
set softtabstop=4
" 自动对齐
set autoindent
if &term=="xterm"
set t_Co=8
set t_Sb=^[[4%dm
set t_Sf=^[[3%dm
endif

" C语言格式对齐
set cindent
" 不要备份文件
set nobackup
" 与windows共享剪贴板
set clipboard+=unnamed

syntax on
"打开文件类型自动检测功能
filetype on

"设置taglist
"显示多个文件的tags
let Tlist_Show_One_File=0
"非当前文件,函数列表折叠隐藏
let Tlist_File_Fold_Auto_Close=1
"在taglist是最后一个窗口时退出vim
let Tlist_Exit_OnlyWindow=1
"单击时跳转
let Tlist_Use_SingleClick=1
"打开taglist时获得输入焦点
let Tlist_GainFocus_On_ToggleOpen=1
"不管taglist窗口是否打开,始终解析文件中的tag
let Tlist_Process_File_Always=1
nmap :TlistToggle

" 配置cvim
filetype plugin on

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

" C++的编译和运行
map :call CompileRunGpp()
func! CompileRunGpp()
exec "w"
exec "!g++ % -o % exec "! ./% endfunc

" =====================================================
" PHP
" =====================================================
" The php doc plugin
" source ~/.vim/php-doc.vim
inoremap :call PhpDocSingle()i
nnoremap :call PhpDocSingle()
vnoremap :call PhpDocRange()

" run file with PHP CLI (CTRL-M)
:autocmd FileType php noremap :w!:!/usr/bin/php %

" PHP parser check (CTRL-L)
:autocmd FileType php noremap :!/usr/bin/php -l %

" Do use the currently active spell checking for completion though!
" (I love this feature :-)
set complete+=kspell

" disable tabs
set expandtab
set shiftwidth=4
set softtabstop=4

" highlt matches
set hlsearch

" Taken from http://peterodding.com/code/vim/profile/vimrc
" Make Vim open and close folded text as needed because I can't be bothered to
" do so myself and wouldn't use text folding at all if it wasn't automatic.
set foldmethod=marker foldopen=all,insert foldclose=all

" Enable enhanced command line completion.
set wildmenu wildmode=list:full

" Ignore these filenames during enhanced command line completion.
set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
set wildignore+=*.jpg,*.bmp,*.gif " binary images
set wildignore+=*.luac " Lua byte code
set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
set wildignore+=*.pyc " Python byte code
set wildignore+=*.spl " compiled spelling word lists
set wildignore+=*.sw? " Vim swap files

" Enable completion dictionaries for PHP buffers.
autocmd FileType php set complete+=k~/.vim/dict/PHP.dict

" PHP Autocomplete
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
set ofu=syntaxcomplete#Complete

" You might also find this useful
" PHP Generated Code Highlights (HTML & SQL)
let php_sql_query=1
let php_htmlInStrings=1
let g:php_folding=2
set foldmethod=syntax

" --------------------
" Project
" --------------------
map :Project
map :Project:redraw/
nmap ToggleProject
"let g:proj_window_width = 30
"let g:proj_window_increment = 150

nnoremap :TlistToggle
let Tlist_Exit_OnlyWindow = 1 " exit if taglist is last window open
let Tlist_Show_One_File = 1 " Only show tags for current buffer
let Tlist_Enable_Fold_Column = 0 " no fold column (only showing one file)
let tlist_sql_settings = 'sql;P:package;t:table'
let tlist_ant_settings = 'ant;p:Project;r:Property;t:Target'

" auto change directory from: http://vim.wikia.com/wiki/Set_working_directory_to_the_current_file
autocmd BufEnter * if expand("%:p:h") !~ '^/tmp' | lcd %:p:h | endif

" when we reload, tell vim to restore the cursor to the saved position
augroup JumpCursorOnEdit
au!
autocmd BufReadPost *
\ if expand(":p:h") !=? $TEMP |
\ if line("'\"") > 1 && line("'\"") foldlevel(JumpCursorOnEdit_foo - 1)) |
\ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
\ let b:doopenfold = 2 |
\ endif |
\ exe JumpCursorOnEdit_foo |
\ endif |
\ endif
" Need to postpone using "zv" until after reading the modelines.
autocmd BufWinEnter *
\ if exists("b:doopenfold") |
\ exe "normal zv" |
\ if(b:doopenfold > 1) |
\ exe "+".1 |
\ endif |
\ unlet b:doopenfold |
\ endif
augroup END

" PHP code sniffer
" If code sniffer is installed you can run it on current php file by running
" :Phpcs
function! RunPhpcs()
let l:filename=@%
let l:phpcs_output=system('phpcs --report=csv --standard=YMC '.l:filename)
" echo l:phpcs_output
let l:phpcs_list=split(l:phpcs_output, "\n")
unlet l:phpcs_list[0]
cexpr l:phpcs_list
cwindow
endfunction

set errorformat+=\"%f\"\\,%l\\,%c\\,%t%*[a-zA-Z]\\,\"%m\"
command! Phpcs execute RunPhpcs()

在学习和工作的过程中,我们的工具是很重要的,也许你会说这个配置起来很麻烦啊,还要写这些东西进去。可是“磨刀不误砍柴功”,打造一个利器工作才是明智的。

您可以选择一种方式赞助本站

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: