最终配置图
下面的操作建立在已经装好vim下:(如果没装好,可使用apt install vim 或者yum install vim进行安装)
使用配色文件monokai.vim(https://git.oschina.net/nanxun/vim.git)
下载后,将此文件移动到/usr/share/vim/vim74/colors/ 目录下,因为我电脑里是vim7.4,所以这里是vim74
接下来使用这个配色
打开.vimrc:
vim ~/.vimrc
colorscheme monokai #引用刚刚放的配色
接下来是一些基础的配置
set shortmess=atI " 启动的时候不显示那个援助乌干达儿童的提示
set scrolloff=3 " 光标移动到buffer的顶部和底部时保持3行距离
autocmd InsertLeave * se nocul " 用浅色高亮当前行
set cursorline " 突出显示当前行
set magic " 设置魔术
set syntax=on ''设置语法高亮
set autoindent ''设置自动缩进
set tabstop=4 ''设置tab格式
set softtabstop=4
set history=1000 ''设置历史记录1000条
set langmenu=zh_CN.UTF-8 ''设置支持utf-8
设置文件头
func SetTitle()
"如果文件类型为.sh文件
if &filetype == 'python'
call setline(1,"\#!/usr/bin/python3")
call setline(2, "\#coding=utf8")
call setline(3, "\"\"\"")
call setline(4, "\# Author: cb")
call setline(5, "\# Created Time : ".strftime("%c"))
call setline(6, "")
call setline(7, "\# File Name: ".expand("%"))
call setline(8, "\# Description: Life is too short,Python as a song!")
call setline(9, "")
call setline(10, "\"\"\"")
call setline(11,"")
endif
if &filetype == 'java'
call setline(1, "//coding=utf8")
call setline(2, "/*************************************************************************")
call setline(3, "\ @Author: cb")
call setline(4, "\ @Created Time : ".strftime("%c"))
call setline(5, "")
call setline(6, "\ @File Name: ".expand("%"))
call setline(7, "\ @Description:")
call setline(8, "")
call setline(9, " ************************************************************************/")
call setline(10,"")
endif
if &filetype == 'sh'
call setline(1, "#!/bin/bash")
call setline(2, "#/*************************************************************************")
call setline(3, "\# @Author: cb")
call setline(4, "\# @Created Time : ".strftime("%c"))
call setline(5, "")
call setline(6, "\# @File Name: ".expand("%"))
call setline(7, "\# @Description: Life is too short!")
call setline(8, "")
call setline(9, "#************************************************************************/")
call setline(10,"")
endif
endfunc" modify the last modified time of a file
function SetLastModifiedTime(lineno)
let modif_time = strftime("%c")
if a:lineno == "-1"
let line = getline(6)
else
let line = getline(a:lineno)
endif
if line =~ '^////\sLast Modified'
let line = substitute( line,':\s\+.*\d\{4\}', ':'.modif_time, "" )
else
let line = ' Last Modified: '.modif_time
endif
if a:lineno == "-1"
call setline(5, line)
else
call append(a:lineno, line)
endif
endfunction效果如下
安装插件
我们这里使用Vundle 来安装插件
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
将下面的Vundle配置加到.vimrc文件中
set nocompatible " required filetype off " required set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() Plugin 'gmarik/Vundle.vim' call vundle#end() " required filetype plugin indent on " required
自动缩进插件:
Plugin 'vim-scripts/indentpython.vim'
自动补全插件:https://github.com/Valloric/YouCompleteMe#mac-os-x-super-quick-installation
Bundle 'Valloric/YouCompleteMe'
语法检查/高亮:
Plugin 'scrooloose/syntastic'
将上面的Plugin '***'都加入到.vimrc 进入vim 切换到命令模式,运行PluginInstall ,vim自动会将插件装好
相关配置文件放在码云了https://git.oschina.net/nanxun/vim.git