vimrc

on under vim
5 minute read

1>弃用spf13-vim

a)插件过多
b)不利于掌握vim

2>.vimrc


"下面这段是vundle要求的,加到vimrc的开头
""""""""""""""for vundle""""""""""""""""
set nocompatible              " be iMproved, required 
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins "call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
"下面用vundle安装incsearch插件
Plugin 'haya14busa/incsearch.vim'
"下面用vundle安装incsearch-fuzzy插件
Plugin 'haya14busa/incsearch-fuzzy.vim'
"下面用vundle安装easymotion插件
Plugin 'easymotion/vim-easymotion'
"下面用vundle安装incsearch-easymotion<space+/>,<z+/>
Plugin 'haya14busa/incsearch-easymotion.vim'
"下面用vundle安装autoformat代码自动对齐插件<f3>
Plugin 'Chiel92/vim-autoformat'
"下面用vundle安装auto-pairs括号自动配对插件
Plugin 'jiangmiao/auto-pairs'
"下面用vundle安装Valloric/YouCompleteMe插件
Plugin 'Valloric/YouCompleteMe'
"下面用vundle安装indentLine代码对齐线插件
Plugin 'Yggdroot/indentLine'
"下面用vundle安装vim中文文档
Plugin 'vimcn/vimcdoc'
"下面用vundle安装ctrlp快速打开文件插件,<c-p>
Plugin 'ctrlpvim/ctrlp.vim'
"下面用vundle安装配色插件
Plugin 'flazz/vim-colorschemes'
"下面这个插件用来快速切换配色<f8>
Plugin 'felixhummel/setcolors.vim'
"下面这个插件用来强制改变jjjjjjjjjjkkkkkkkkkkkllllllll的坏习惯
Plugin 'takac/vim-hardtime'
"下面这个插件利用vim8的时钟特性自动保存文件,默认第5分钟保存,后来发现这个插件是备份文件,不保存正在编辑的文件,于
"是弃用 
"Plugin 'chrisbra/vim-autosave'
"下面这个插件用来安装一个css配色方案插件,后来觉得没有什么作用,不如直接用evening配色方案
"Plugin 'ap/vim-css-color'
" plugin from http://vim-scripts.org/vim/scripts.html
"Plugin 'L9'

" Git plugin not hosted on GitHub
"Plugin 'git://git.wincent.com/command-t.git'

" git repos on your local machine (i.e. when working on your own plugin)
"Plugin 'file:///home/gmarik/path/to/plugin'

" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}

" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
Plugin 'ascenator/L9', {'name': 'newL9'}
"下面这个插件用来markdown实时预览
Plugin 'iamcco/markdown-preview.vim'
" All of your Plugins must be added before the following line
call vundle#end()            " required

"下面这行要注意,有可能以后要改
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

""""""""""""for vundle end""""""""""""




"set ruler|noruler"默认开启ruler
"设置leader键为,
let mapleader=","
set number"显示行号
syntax on"自动语法高亮,语法检验
set autoindent"自动缩进
set tabstop=4"tab键占4个字符


"方便操作
map ; :
map mm ZZ
map sy "+y
map sp "+p

"在光标处换行,不用再切换到insert模式再enter
nnoremap <enter> i<enter><esc>



"md文件中文符号换成英文
au BufRead *.md call Biaodian()
map <F2> :call Biaodian() <CR>
function Biaodian()
    silent! %s/“/"/g
    silent! %s/”/"/g
    silent! %s/,/,/g
    silent! %s/。/./g
    silent! %s/?/?/g
    silent! %s/〈/</g
    silent! %s/〉/>/g
    silent! %s/(/(/g
    silent! %s/)/)/g
    silent! %s/:/:/g
    silent! %s/;/;/g
    silent! %s/‘/'/g
    silent! %s/‘/'/g
    silent! %s/!/!/g
    endfunction

"设置缩进的空格数
set shiftwidth=4

"设置tab键为4个空格
set ts=4
set expandtab 

"111字符长度换行用来适配博客md编写
set textwidth=111

"textwidth用于中文换行
set formatoptions+=mM


"设置,w为保存
"nmap <leader>w :w<CR>


"下面4个插件最后浓缩成的两个典型使用方法:
"space+/:fuzz search+easymotion功能
"z/:fuzz search功能
"
"四个easymotion插件incsearch incsearch-fuzzy vim-easymotion incsearch-easymotion相关设置
"目前只能用incsearch和easymotion,并用如下配置

"111111incsearch插件设置
""""""""""start of incsearch"""""""""
map /  <Plug>(incsearch-forward)
map ?  <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)

set hlsearch
let g:incsearch#auto_nohlsearch = 1
map n  <Plug>(incsearch-nohl-n)
map N  <Plug>(incsearch-nohl-N)
map *  <Plug>(incsearch-nohl-*)
map #  <Plug>(incsearch-nohl-#)
map g* <Plug>(incsearch-nohl-g*)
map g# <Plug>(incsearch-nohl-g#)

function! s:noregexp(pattern) abort
	return '\V' . escape(a:pattern, '\')
endfunction

function! s:config() abort
	return {'converters': [function('s:noregexp')]}
endfunction

noremap <silent><expr> z/ incsearch#go(<SID>config())
"""""""""end of incsearch""""""""""



"222222incsearch-fuzzy插件设置
"https://github.com/haya14busa/incsearch-fuzzy.vim
"暂时因为看上去没有什么效果而没用它,暂时认为222222和333333这两个插件无法正常工作是由于222222插件无法正常工作
"而222222不工作是由于没有找到incsearch#config#fuzzy#converter()函数(报这个错),于是vim-->:h
"incsearch-config-fuzzy,发现没有incsearch-config-fuzzy的说明,猜想有一点可能是incsearch-fuzzy插件没有装好,于是
":BundleInstall,居然可以安装,说明之前这个incsearch-fuzzy插件的确没有装好,然后发现安装完incsearch-fuzzy后就不会
"报没有找到incsearch#config#fuzzy#converter()函数的错误了,然后一切都好了,333333插件也可以用了
"""""""""start of incsearch-fuzzy"""""""""
"fuzzy
map z/ <Plug>(incsearch-fuzzy-/)
map z? <Plug>(incsearch-fuzzy-?)
map zg/ <Plug>(incsearch-fuzzy-stay)
"fuzzyspell
map z/ <Plug>(incsearch-fuzzyspell-/)
map z? <Plug>(incsearch-fuzzyspell-?)
map zg/ <Plug>(incsearch-fuzzyspell-stay)
"Use both fuzzy & fuzzyspell feature
function! s:config_fuzzyall(...) abort
		  return extend(copy({
		    \   'converters': [
		    \     incsearch#config#fuzzy#converter(),
		    \     incsearch#config#fuzzyspell#converter()
		    \   ],
		    \ }), get(a:, 1, {}))
endfunction

noremap <silent><expr> z/ incsearch#go(<SID>config_fuzzyall())
noremap <silent><expr> z? incsearch#go(<SID>config_fuzzyall({'command': '?'}))
noremap <silent><expr> zg? incsearch#go(<SID>config_fuzzyall({'is_stay': 1}))
"""""""""end of incsearch-fuzzy"""""""""


"333333incsearch-easymotion插件的设置
""""""""""start of incsearch-easymotion""""""""""
"https://github.com/haya14busa/incsearch-easymotion.vim
"暂时因为没有什么效果而没用它,可能是与什么插件不兼容或与系统不兼容
"后来可以用了,因为上面的incsearch-fuzzy插件第一次没有装好
"map z/ <Plug>(incsearch-easymotion-/)
"map z? <Plug>(incsearch-easymotion-?)
"map zg/ <Plug>(incsearch-easymotion-stay)
"上面这三行不能加,加了则不能通过z/来fuzz search了,如果加了上面这三行,没有什么特殊效果
"无论有没有加上面这三行,都可以通过space+/实现[fuzz search并easymotion的效果]

"""incsearch.vim x fuzzy x vim-easymotion
function! s:config_easyfuzzymotion(...) abort
		  return extend(copy({
		    \   'converters': [incsearch#config#fuzzy#converter()],
		    \   'modules': [incsearch#config#easymotion#module()],
		    \   'keymap': {"\<CR>": '<Over>(easymotion)'},
		    \   'is_expr': 0,
		    \   'is_stay': 1
		    \ }), get(a:, 1, {}))
endfunction
noremap <silent><expr> <Space>/ incsearch#go(<SID>config_easyfuzzymotion())
""""""""""end of incsearch-easymotion""""""""""


"444444下面是easymotion插件的相关设置
""""""""""""""""""start of easymotion""""""""""""""""""
"下面这句暂时不确定用意
let g:EasyMotion_do_mapping = 0 " Disable default mappings
 
"三键到任意地方
nmap s <Plug>(easymotion-overwin-f)
"四键到任意地方
"nmap s <Plug>(easymotion-overwin-f2)
"设置大小写不敏感
let g:EasyMotion_smartcase = 1
" JK motions: Line motions
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
"move to line 
map <Leader>l <Plug>(easymotion-bd-jk)
nmap <Leader>l <Plug>(easymotion-overwin-line)

"下面设置fuzzsearch,这个有点叼,结合incsearch,incsearch-fuzzy,easymotion,incsearch-easymotion四个插件
"但是目前并没有让4个插件都起作用
"目前只有incsearch+easymotion
"后来这四个插件完美运行了,因为incsearch-fuzzy插件之前没有装好
"incsearch-fuzzy和incsearch-easymotion这两个插件暂时没有用
" You can use other keymappings like <C-l> instead of <CR> if you want to
" use these mappings as default search and somtimes want to move cursor with
" EasyMotion.

function! s:incsearch_config(...) abort
		  return incsearch#util#deepextend(deepcopy({
		    \   'modules': [incsearch#config#easymotion#module({'overwin': 1})],
		    \   'keymap': {
		    \     "\<CR>": '<Over>(easymotion)'
		    \   },
		    \   'is_expr': 0
		    \ }), get(a:, 1, {}))
endfunction

noremap <silent><expr> /  incsearch#go(<SID>incsearch_config())
noremap <silent><expr> ?  incsearch#go(<SID>incsearch_config({'command': '?'}))
noremap <silent><expr> g/ incsearch#go(<SID>incsearch_config({'is_stay': 1}))
""""""""""""""""""end of easymotion""""""""""""""""""

"代码对齐插件相关设置
noremap <F3> :Autoformat<CR>


"""""""""start of YCM""""""""""
"YouCompleteMe相关设置
set runtimepath+=~/.vim/bundle/YouCompleteMe
autocmd InsertLeave * if pumvisible() == 0|pclose|endif	"离开插入模式后自动关闭预览窗口"
let g:ycm_collect_identifiers_from_tags_files = 1           " 开启 YCM 基于标签引擎
let g:ycm_collect_identifiers_from_comments_and_strings = 1 " 注释与字符串中的内容也用于补全
let g:syntastic_ignore_files=[".*\.py$"]
let g:ycm_seed_identifiers_with_syntax = 1                  " 语法关键字补全
let g:ycm_complete_in_comments = 1
let g:ycm_confirm_extra_conf = 0
let g:ycm_key_list_select_completion = ['<c-n>', '<Down>']  " 映射按键, 没有这个会拦截掉tab, 导致其他插件的tab不能用.
let g:ycm_key_list_previous_completion = ['<c-p>', '<Up>']
let g:ycm_complete_in_comments = 1                          " 在注释输入中也能补全
let g:ycm_complete_in_strings = 1                           " 在字符串输入中也能补全
let g:ycm_collect_identifiers_from_comments_and_strings = 1 " 注释和字符串中的文字也会被收入补全
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
let g:ycm_show_diagnostics_ui = 0                           " 禁用语法检查
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>" |            " 回车即选中当前项
nnoremap <c-j> :YcmCompleter GoToDefinitionElseDeclaration<CR>|     " 跳转到定义处
"let g:ycm_min_num_of_chars_for_completion=2                 " 从第2个键入字符就开始罗列匹配项
"""""""""end of YCM""""""""""
"vim-colorschemes插件配色
colorscheme evening 
"setcolors插件设置自动换配色,vim-colorschemes插件相当于配色库,setcolor插件用于变换其他配色,如果不安装
"vim-colorschemes插件只安装setcolor插件则没有好的效果
"考虑到对眼睛不好,暂时关闭下面的自动换色
"autocmd CursorHold * call NextColor(1)
"在setcolors.vim中将最开始的设置改成如下值
"let s:mycolors = ['Benokai','molokai','evening', 'feral', 'flatlandia', 'flattown', 'murphy', 'flatui', 'freya', 'fu','genericdc','1989','256-grayvim','256-jungle','CandyPaper','Chasing_Logic','ChocolateLiquor','ChocolatePapaya','openbsd','BlackSea','black_angus','0x7A69-dark']  " colorscheme names that we use to set color

"下面开启打开文件时自动跳转到上次编辑的地方,vim在/etc/vim/vimrc文件中默认设置关闭
if has("autocmd")
  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif

"vim-hardtime插件的设置
let g:hardtime_default_on = 1
let g:hardtime_maxcount = 3
let g:list_of_normal_keys = ["h", "j", "k", "l", "-", "+"]
let g:list_of_visual_keys = ["h", "j", "k", "l", "-", "+"]
let g:list_of_insert_keys = []

"下面是插入模式的3个字符内移动的快捷键,结合vim-hardtime在vim-hardtime中设置去除Left,Down,Up,Right的禁用
"超过当前光标所在位置的移动用f+j+s+字符+hint,或者f+j+w|b的方法移动(f+j为esc的map)
inoremap <A-h> <Left>
inoremap <A-j> <Down>
inoremap <A-k> <Up>
inoremap <A-l> <Right>

"每行超过111字符长度后用不同颜色显示
augroup vimrc_autocmds
  autocmd CursorHold * highlight OverLength ctermbg=darkgrey guibg=#592929
  autocmd CursorHold * match OverLength /\%112v.*/
augroup END

"vim-autosave插件的设置
":let g:autosave_timer= 1
"弃用上面的插件,用下面的自动保存命令
set updatetime=200
au CursorHold * silent! update

"下面是markdown预览插件的相关设置
"如果f5失效则先按f6再按f5
nmap <silent> <F5> <Plug>MarkdownPreview        " 普通模式
imap <silent> <F5> <Plug>MarkdownPreview        " 插入模式
nmap <silent> <F6> <Plug>StopMarkdownPreview    " 普通模式
imap <silent> <F6> <Plug>StopMarkdownPreview    " 插入模式

Install

https://github.com/3xp10it/.vimrc
vimrc
home
github
archive
category