第一次的文章,就贴个我的Vim配置文件吧

     Vim的配置其实很简单,要是你能把Vim的脚本语言学会了,那么大可写出一些脚本出来,自定义出自己的一些插件出来。随便说下在Windows下Vimrc的位置在$HOME或者$VIM下,在Linux下为你的主文件下。在Linux中你也可以修改 /etc/下的Vimrc文件,但我建议你不要那么做。

    还有涉及到Windows和Linux下的编码格式问题,在Windows下是换行符加回车符,Linux/Unix下是<LF>,所以Vim中的编码格式有dos,unix,mac。把文件放置于不同的平台呢,需要转换一下编码格式,命令如下:

     :set fileformat=unix[dos][mac]

   想知道当前文件的编码格式呢,可以这样:

    :set fileformat=?

 

    下面是我几年前的一个配置文件了,现在放出来,共享下。

 

" vimrc
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 一般设定
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""'
" 启动的时候不显示那个援助索马里儿童的提示
set shortmess-=atI

" 不让vim发出讨厌的滴滴声
set noerrorbells

" 设定光标离窗口上下边界 5 行时窗口自动滚动
"set scrolloff=5

" 默认区分大小写
"set noignorecase

" 去除工具栏
set guioptions-=T
"去除菜单栏
set guioptions-=m
" 去除右边滚动条
"set guioptions-=r
"set guioptions-=R

"set guioptions-=l
"set guioptions-=L

" 使用配色方案
if has("gui_running")
  set guioptions-=T
  let psc_style='cool'
  colorscheme ps_color
else
  set background=dark
  colorscheme zellner
endif

" when start vim, make it maximim
"autocmd GUIEnter * simalt ~x

" 设置不兼容VI模式,在增强模式下运行
set nocompatible

" browsedir设置
set browsedir=buffer
" history文件中需要记录的行数

set history=400

" 载入文件类型插件
filetype plugin on

" 为特定文件类型载入相关缩进文件
filetype indent on

" 文件被其他程序修改时自动载入
set autoread

" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
set mouse=a
set selection=exclusive
set selectmode=mouse,key

" fast saving
nmap <leader>w :w!<cr>
nmap <leader>f :find<cr>

" fast reloading of the .vimrc
map <leader>s :source ~/vim_local/vimrc<cr>
" fast editing of .vimrc
map <leader>e :e! ~/vim_local/vimrc<cr>
" when .vimrc is edited,reload it
autocmd! bufwritepost vimrc source ~/vim_local/vimrc

" 在处理未保存或只读文件的时候,弹出确认
set confirm

" 共享外部剪贴板
set clipboard+=unnamed

" 显示未完成命令
set showcmd

" 侦测文件类型
filetype on


" 设置文件编码检测类型及支持格式
set fencs=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936

" 指定菜单语言
"set langmenu=zh_CN.utf-8
"source $VIMRUNTIME/delmenu.vim
"source $VIMRUNTIME/menu.vim

 

" 保存全局变量
set viminfo+=!

" 带有如下符号的单词不要被换行分割
set iskeyword+=_,$,@,%,#,-

" 语法高亮
syntax on


" 高亮字符,让其不受100列限制
":highlight OverLength ctermbg=red ctermfg=white guibg=red guifg=white
":match OverLength '/%101v.*'

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General Autocommands
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Switch to current dir
map <leader>cd :cd %:p:h<cr>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 颜色和字体
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""'

" some nice mapping to switch syntax (useful if one mixes different language in
" one file)
map <leader>1 :set syntax=cheetah<cr>
map <leader>2 :set syntax=xhtml<cr>
map <leader>3 :set syntax=python<cr>
map <leader>4 :set ft=javascript<cr>
map <leader>$ :syntax sync fromstart<cr>

autocmd BufEnter * :syntax sync fromstart

" Highlight current
"if has("gui_running")
 "set cursorline
  "hi cursorline guibg=#333333
  "hi CursorColumn guibg=#333333
"endif

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""'
" 用户界面
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" set 7 lines to the curors - when movine vertical
set so=7

" turn on wild menu
set wildmenu

" set magic on
set magic

" show line number
"set nu

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

" 在被分割的窗口间显示空白,便于阅读
set fillchars=vert:/ ,stl:/ ,stlnc:/

" 使回格键(backspace)正常处理indent, eol, start等
set backspace=eol,start,indent

" 允许backspace和光标键跨越行边界
set whichwrap+=<,>,h,l

" 命令行(在状态行下)的高度,默认为1,这里是2
set cmdheight=2

" 增强模式中的命令行自动完成操作
set wildmenu


" 通过使用: commands命令,告诉我们文件的哪一行被改变过
set report=0


  """""""""""""""""""""""""""""""""""""""""
  " 状态行设置
  """"""""""""""""""""""""""""""""""""
  " 不显示状态行
  set laststatus=1

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

  " 状态行颜色
  highlight StatusLine guifg=SlateBlue guibg=Yellow
  highlight StatusLineNC guifg=Gray guibg=White


  " 在状态行上显示光标所在位置的行号和列号
  set ruler
  set rulerformat=%20(%2*%<%f%=/ %m%r/ %3l/ %c/ %p%%%)

  " 设置用于GUI图形用户界面的字体列表。
  "set guifont=SimSun/ 10

  " 状态行显示的内容(包括文件类型和解码)
  " %F 当前文件名
  " %m 当前文件修改状态
  " %r 当前文件是否只读
  " %Y 当前文件类型
  " %{&fileformat}当前文件编码
  " %b 当前光标处字符的ASCII码值
  " %B 当前光标处字符的十六进制值
  " %l 当前光标行号
  " %c 当前光标列号
  " %V 当前光标虚拟列号(根据字符所占字节数计算)
  " %p 当前行占总行号的百分比
  " %% 百分号
  " %L 当前文件总行数
  set statusline=%F%m%r%h%w/ [FORMAT=%{&ff}]/ [TYPE=%Y]/ [POS=%l,%v][%p%%]/ %{strftime(/"%d/%m/%y/ -/ %H:%M/")}
  " 更改Leader为","
  "let g:C_MapLeader = ','

"""""""""""""""""""""""""""""""""""'
  " 标签页设置
  """""""""""""""""""""""""""""""""
  if has("gui_running")
      set showtabline=2
      map! tn tabnew
      nmap <C-c> :tabclose<CR>
  endif

  " 标签页只显示文件名
  function ShortTabLabel ()
      let bufnrlist = tabpagebuflist (v:lnum)
      let label = bufname (bufnrlist[tabpagewinnr (v:lnum) -1])
      let filename = fnamemodify (label, ':t')
      return filename
  endfunction

  set guitablabel=%{ShortTabLabel()}

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Moving around and tabs
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Map space to / and c-space to ?
"map <space> /
"map <c-space> ?

"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

"Actually, the tab does not switch buffers, but my arrows
"Bclose function ca be found in "Buffer related" section
map <leader>bd :Bclose<cr>
map <down> <leader>bd
"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
try
  set switchbuf=usetab
  set stal=2
catch
endtry

"Moving fast to front, back and 2 sides ;)
imap <m-$> <esc>$a
imap <m-0> <esc>0i
imap <D-$> <esc>$a
imap <D-0> <esc>0i

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 文件设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""'
" 不要备份文件(根据自己需要取舍)
set nobackup
set nowb

" 不要生成swap文件,当buffer被丢弃的时候隐藏它
setlocal noswapfile
set bufhidden=hide

" 字符间插入的像素行数目
set linespace=0

" 设置GVIM默认目录
"lcd e:/cmdp
" 设定文件浏览器目录为当前目录
set bsdir=buffer
" 自动切换目录
set autochdir

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Folding
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""'
" Enable folding, I find it very useful
set nofen
set fdl=0


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""'
" 搜索和匹配
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""'
" 高亮显示匹配的括号
set showmatch

" 匹配括号高亮的时间(单位是十分之一秒)
set matchtime=3

" 在搜索的时候忽略大小写
"set ignorecase

" 不要高亮被搜索的句子(phrases)
"set nohlsearch

" highlight search things
set hlsearch


" 在搜索时,输入的词句的逐字符高亮(类似firefox的搜索)
set incsearch

" 输入:set list命令是应该显示些啥?
set listchars=tab:/|/ ,trail:.,extends:>,precedes:<,eol:$
" tab补全时忽略这些忽略这些
set wildignore=*.o,*.obj,*.bak,*.exe
" 光标移动到buffer的顶部和底部时保持3行距离
set scrolloff=3

" 不要闪烁
set novisualbell

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Command-line config
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""'
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

" Smart mappings on the command line
cno $h e ~/
cno $d e ~/Desktop/
cno $j e ./

cno $q <C-/>eDeleteTillSlash()<cr>

cno $c e <C-/>eCurrentFileDir("e")<cr>

cno $tc <C-/>eCurrentFileDir("tabnew")<cr>
cno $th tabnew ~/
cno $td tabnew ~/Desktop/

" Bash like
cnoremap <C-A>    <Home>
cnoremap <C-E>    <End>
cnoremap <C-K>    <C-U>


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Buffer realted
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Fast open a buffer by search for a name
map <c-q> :sb

" Open a dummy buffer for paste
map <leader>q :e ~/buffer<cr>

" Restore cursor to file position in previous editing session
set viminfo='10,/"100,:20,%,n~/.viminfo
au BufReadPost * if line("'/"") > 0|if line("'/"") <= line("$")|exe("norm '/"")|else|exe "norm $"|endif|endif

" Buffer - reverse everything ... :)
map <F9> ggVGg?

" Don't close window, when deleting a buffer
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


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 文本格式和排版
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""'


" 自动格式化
set formatoptions=tcrqn

" 继承前一行的缩进方式,特别适用于多行注释
set autoindent

" 为C程序提供自动缩进
set smartindent

" 移除末尾空格 C/C++ and Vim files
"au BufWritePre * call RemoveTrailingSpace()

" 不要用空格代替制表符
set noexpandtab

" 不要换行
set nowrap

" 在行和段开始处使用制表符
set smarttab

" 使得注释换行时自动加上前导的空格和星号
set formatoptions=tcqro

" ambiwidth 默认值为 single。在其值为 single 时,若 encoding 为 utf-8,gvim 显示全角符号时就会出问题,会当作半角显示。
set ambiwidth=double

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值