vim配置文件


set tabstop=4
set shiftwidth=4
" 搜索高亮
set hlsearch
" 设置C/C++方式自动对齐
set autoindent
set cindent
" 开启语法高亮
syntax enable
" 高亮当前行
set cursorline
hi CursorLine cterm=NONE ctermbg=black
" 指定不折行
set nowrap
" 显示行号
set number
" 设置取消备份,禁止临时文件生成
set nobackup
set noswapfile
" 检测文件类型
filetype on
" 针对不同文件,采用不同的缩进
filetype indent on
" 允许插件
filetype plugin on
" 自动保存
set autowrite
" 不使用vi键盘模式,而是vim自己的
set nocompatible
" 去掉有关vi的一致性模式,避免以前版本的一些bug和局限
set nocompatible

" 设置当文件被改动时自动载入
set autoread
"自动补全
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {<CR>}<ESC>O
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
function! ClosePair(char)
  if getline('.')[col('.') - 1] == a:char
    return "\<Right>"
  else
    return a:char
  endif
endfunction
filetype plugin indent on
"打开文件类型检测, 加了这句才可以用智能补全
set completeopt=longest,menu

nmap <leader>w :w!<cr>

nmap <leader>f :find<cr>
"共享剪贴板
set clipboard+=unnamed
" 映射全选+复制 ctrl+a
map <C-A> ggVGY
map! <C-A> <Esc>ggVGY
map <F12> gg=G
" 选中状态下 Ctrl+c 复制
vmap <C-c> "+y
"代码补全
set completeopt=preview,menuset scrolloff=3 " 光标移动到buffeset novisualbell " 不要闪烁 

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

"""""新文件标题""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"新建.c,.h,.sh,.java文件,自动插入文件头

autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()"

""定义函数SetTitle,自动插入文件头

func SetTitle()

  "如果文件类型为.sh文件

  if &filetype == 'sh'

    call setline(1,"\#########################################################################")

    call append(line("."), "\# File Name: ".expand("%"))

    call append(line(".")+1, "\# Author: weigang")

    call append(line(".")+2, "\# mail: w_wg@qq.com")

    call append(line(".")+3, "\# Created Time: ".strftime("%c"))

      call append(line(".")+4, "\############################################") 

    call append(line(".")+5, "\#!/bin/bash")

    call append(line(".")+6, "")

  else

    call setline(1, "/*************************************************************")

    call append(line("."), " * > File Name: ".expand("%"))

    call append(line(".")+1, " * > Author: weigang")

    call append(line(".")+2, " * > Mail: w_wg@qq.com ")

    call append(line(".")+3, " * > Created Time: ".strftime("%c"))

    call append(line(".")+4, " *************************************************************/")

    call append(line(".")+5, "")

  endif

  if &filetype == 'cpp'

    call append(line(".")+6, "#include<iostream>")

    call append(line(".")+7, "using namespace std;")

    call append(line(".")+8, "")

  endif

  if &filetype == 'c'

    call append(line(".")+6, "#include<stdio.h>")

    call append(line(".")+7, "")

  endif

  "新建文件后,自动定位到文件末尾

  autocmd BufNewFile * normal G

endfunc

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

posted @ 2018-09-16 20:49  凉菜花生小酒  阅读(106)  评论(0)    收藏  举报