Created
January 20, 2017 04:19
-
-
Save zhangnew/b925e630e5fd8ee72bed8d2358973aaf to your computer and use it in GitHub Desktop.
.vimrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set ts=4 | |
set expandtab | |
autocmd BufWritePost $MYVIMRC source $MYVIMRC | |
set nocompatible "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限 | |
"""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" set theme | |
syntax enable | |
set background=dark | |
"colorscheme solarized | |
"colorscheme molokai | |
set t_Co=256 | |
colorscheme desert | |
"""""""""""""""""""""""""""""""""""""""""""""""""""" | |
set cul "高亮光标所在行 | |
autocmd InsertLeave * se cul " 用浅色高亮当前行 | |
autocmd InsertEnter * se nocul " 用浅色高亮当前行 | |
set cuc | |
autocmd InsertLeave * se cuc " 用浅色高亮当前列 | |
autocmd InsertEnter * se nocuc " 用浅色高亮当前列 | |
" 设置标记一列的背景颜色和数字一行颜色一致 | |
hi! link SignColumn LineNr | |
hi! link ShowMarksHLl DiffAdd | |
hi! link ShowMarksHLu DiffChange | |
"""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" 相对行号: 行号变成相对,可以用 nj/nk 进行跳转 | |
set relativenumber number | |
au FocusLost * :set norelativenumber number | |
au FocusGained * :set relativenumber | |
" 插入模式下用绝对行号, 普通模式下用相对 | |
autocmd InsertEnter * :set norelativenumber number | |
autocmd InsertLeave * :set relativenumber | |
function! NumberToggle() | |
if(&relativenumber == 1) | |
set norelativenumber number | |
else | |
set relativenumber | |
endif | |
endfunc | |
nnoremap <C-n> :call NumberToggle()<cr> | |
""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
"显示行数,设置软回车和缩进还有语法 | |
set shiftwidth=4 | |
set softtabstop=4 | |
nnoremap ; : | |
" 检测文件类型 | |
filetype on | |
" 针对不同的文件类型采用不同的缩进格式 | |
filetype indent on | |
" 允许插件 | |
filetype plugin on | |
" 启动自动补全 | |
filetype plugin indent on | |
set smartindent | |
set autoindent | |
set smarttab | |
"syntax on | |
"""""""""""""""""""""""""""""""""""""""""""""""""""" | |
"这个是我喜欢的,一旦一行的字符超出80个的话就把那些字符的背景设为红色 | |
"highlight OverLength ctermbg=red ctermfg=white guibg=#592929 | |
"match OverLength /\%81v.\+/ | |
"""""""""""""""""""""""""""""""""""""""""""""""""""" | |
"<F5>自动运行python | |
nnoremap <buffer> <F5> :exec '!python' shellescape(@%, 1)<cr> | |
"""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" 设置 退出vim后,内容显示在终端屏幕, 可以用于查看和复制, 不需要可以去掉 | |
" 好处:误删什么的,如果以前屏幕打开,可以找回 | |
set t_ti= t_te= | |
"""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" change the terminal's title | |
set title | |
"""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" 设置文内智能搜索提示 | |
" 高亮search命中的文本 | |
set hlsearch | |
" 打开增量搜索模式,随着键入即时搜索 | |
set incsearch | |
" 搜索时忽略大小写 | |
set ignorecase | |
" 有一个或以上大写字母时仍大小写敏感 | |
set smartcase | |
"""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" 显示当前的行号列号 | |
set ruler | |
" 在状态栏显示正在输入的命令 | |
set showcmd | |
" 左下角显示当前vim模式 | |
set showmode | |
" 在上下移动光标时,光标的上方或下方至少会保留显示的行数 | |
set scrolloff=7 | |
" set winwidth=79 | |
" 命令行(在状态行下)的高度,默认为1,这里是2 | |
" set statusline=%<%f%h%m%r%=%k[%{(&fenc==\"\")?&enc:&fenc}%{(&bomb?\",BOM\":\"\")}]%-14.(%l,%c%V%)\ %P | |
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%y/%m/%d\ -\ %H:%M\")} "状态行显示的内容 | |
" Always show the status line - use 2 lines for the status bar | |
set laststatus=2 | |
"""""""""""""""""""""""""""""""""""""""""""""""""""" | |
set pastetoggle=<F7> " when in insert mode, press <F7> to go to | |
" paste mode, where you can paste mass data | |
" that won't be autoindented | |
" disbale paste mode when leaving insert mode | |
au InsertLeave * set nopaste | |
" F7 set paste问题已解决, 粘贴代码前不需要按F7了 | |
" F7 粘贴模式paste_mode开关,用于有格式的代码粘贴 | |
" Automatically set paste mode in Vim when pasting in insert mode | |
function! XTermPasteBegin() | |
set pastetoggle=<Esc>[201~ | |
set paste | |
return "" | |
endfunction | |
inoremap <special> <expr> <Esc>[200~ XTermPasteBegin() | |
"""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" F1 废弃这个键,防止调出系统帮助 | |
" I can type :help on my own, thanks. Protect your fat fingers from the evils of <F1> | |
noremap <F1> <Esc>" | |
" F2 行号开关,用于鼠标复制代码用 | |
" 为方便复制,用<F2>开启/关闭行号显示: | |
function! HideNumber() | |
if(&relativenumber == &number) | |
set relativenumber! number! | |
elseif(&number) | |
set number! | |
else | |
set relativenumber! | |
endif | |
set number? | |
endfunc | |
nnoremap <F2> :call HideNumber()<CR> | |
" F3 显示可打印字符开关 | |
nnoremap <F3> :set list! list?<CR> | |
" F4 换行开关 | |
nnoremap <F4> :set wrap! wrap?<CR> | |
" F6 语法开关,关闭语法可以加快大文件的展示 | |
nnoremap <F6> :exec exists('syntax_on') ? 'syn off' : 'syn on'<CR> | |
"""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" 定义函数AutoSetFileHead,自动插入文件头 | |
autocmd BufNewFile *.sh,*.py exec ":call AutoSetFileHead()" | |
function! AutoSetFileHead() | |
"如果文件类型为.sh文件 | |
if &filetype == 'sh' | |
call setline(1, "\#!/bin/bash") | |
endif | |
"如果文件类型为python | |
if &filetype == 'python' | |
call setline(1, "\#!/usr/bin/env python") | |
call append(1, "\# encoding: utf-8") | |
endif | |
normal G | |
normal o | |
normal o | |
endfunc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment