" 查询快捷键 :verbose map <key>
" 基本设置----------------{{{
" 不兼容vi模式 必须放在第一行
set nocompatible
" 开启语法高亮
syntax on
" 高亮当前行
set cursorline
" 开启搜索高亮
set incsearch
" 设定历史记录数
set history =50
" 设定为系统剪贴板
set clipboard=unnamedplus
" 消除~后缀备份文件
set nobackup
" 消除un后缀备份文件
set noundofile
" 显示行号
set number
" 高亮搜索项
set hlsearch
" 用空格代替tab键
" 设置tab宽度,为了符合google c++标准将4空格换位2空格节省横向空间
set tabstop=2
" 设置缩进宽度
set shiftwidth=2
" 用空格代替tab,问题:用空格代替tab会导致一些快捷键无法使用
" 可以尝试用 c-j/k 来选择
set expandtab
" 设置mapleader为逗号
let mapleader=","
" 设置编码
set encoding=utf-8
language messages zh_CN.utf-8
" 侧边栏常显示
set signcolumn=yes
"}}}" 全局变量------------------{{{
let g:author="yszc"
" }}}" 映射-------------------{{{
" 取消默认的删除剪切操作,此映射会导致删除卡顿
" nnoremap x "_x
" nnoremap X "_X
" nnoremap d "_d
" nnoremap dd "_dd
" nnoremap D "_D
" vnoremap d "_d
" vnoremap dd "_dd" 将c-p映射为复制寄存器粘贴(用于特定的粘贴任务),默认粘贴为无名寄存器
nnoremap <c-p> "0p " tab切换
" C-W +j/k/l/h可以移动窗口光标,不用按多次w
" CTRL-A 是全选
nnoremap <c-a> ggvG
" 高亮开关
nnoremap <leader>hl :set hlsearch!<cr>
" 定义快速打开加载.vimrc和.vimrc.vundle文件
nnoremap <leader>ev :split $MYVIMRC<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>
nnoremap <leader>ep :split $HOME/.vimrc.vundle<cr>
" nnoremap <c-e> :echo "hi"<cr>
" insert 模式括号匹配
" inoremap < <><esc>i
" inoremap [ []<esc>i
" inoremap { {}<esc>i
" inoremap ( ()<esc>i
" inoremap ' ''<esc>i
" inoremap " ""<esc>i" c-j/k映射成翻页键
nnoremap <c-j> <c-d>
nnoremap <c-k> <c-u>
vnoremap <c-j> <c-d>
vnoremap <c-k> <c-u>" c-,/.映射为tab翻页键
nnoremap <c-h> :tabp<cr>
nnoremap <c-l> :tabn<cr>" H映射为0,L映射为$
nnoremap 0 <nop>
nnoremap $ <nop>
nnoremap H 0
nnoremap L $
vnoremap H 0
vnoremap L $
" 操作符号重映射
onoremap H 0
onoremap L $
" J/K向上/下移动一段?一页?还是easymotion
" insert模式下方向键
inoremap <c-h> <Left>
inoremap <c-l> <Right>
inoremap <c-j> <Down>
inoremap <c-k> <Up>
" 方向键习惯改掉
" nnoremap <Left> <nop>
" nnoremap <Up> <nop>
" nnoremap <Right> <nop>
" nnoremap <Down> <nop>
" inoremap <Left> <nop>
" inoremap <Up> <nop>
" inoremap <Right> <nop>
" inoremap <Down> <nop>
" 替换中文标点为英文标点
inoremap 。 .
inoremap , ,
inoremap ? ?
inoremap ! !
inoremap ‘ '
inoremap “ "
inoremap ” "
inoremap : :
inoremap ; ;
inoremap ( (
inoremap ) )
inoremap ¥ $
" insert模式jk代替<esc>
" 将inoremap模式下的<esc>映射为空导致了方向键和翻页键乱码的情况
nnoremap j gj
nnoremap k gkinoremap jk <esc>
" cnoremap jk <c-c> " inoremap <esc> <nop>
" 快速保存,退出
nnoremap <c-s> :w<cr>
nnoremap <c-q> :q<cr>
" 不能映射normal模式下的esc键,因为方向键和翻页键的前缀是esc
" 这会导致在键入方向键或翻页键时退出,并且失灵
" nnoremap <esc> :q
"}}}" 自动命令组----------------{{{
" 光标切换
augroup cursor_switchautocmd!au InsertLeave * silent exec "! echo -ne '\e[1 q'"au InsertEnter * silent exec "! echo -ne '\e[5 q'"au VimLeave * silent exec "! echo -ne '\e[5 q'"au VimEnter * silent exec "! echo -ne '\e[1 q'"
augroup ENDaugroup set_titleautocmd!au BufNewFile *.py silent exec ":call SetTitle()"
augroup ENDfunction! SetTitle()echo 'im here!'if &filetype=='python'call setline(1,"#!/usr/bin/env python3")call setline(2,"# -*- coding: utf-8 -*-")call setline(3,"# Author: yszc-wy@foxmail.com")call setline(4,"# Description: ")call setline(5,"")endif
endfunctionaugroup cxx_exec" make\ \-C\ build\ &&\ ./build/main |au Filetype cpp set makeprg=cd\ build\ &&\ cmake\ ..\ &&\ make\ &&\ ./main |noremap <F4> :call CXXCompile()<cr>
augroup ENDfunction! CXXCompile()echom "CXX Compile"w Make!
endfunctionaugroup python_exec" 不能使用VimEnter事件,不然使用vim .后无法对后续打开的.py文件使用F4au Filetype python set makeprg=python\ % |noremap <F4> :call PythonExec()<cr> |augroup ENDfunction! PythonExec()echo "PythonExec"wMake!" 清屏" silent !clear" 执行python" execute '!python '.expand('%:p')" execute 'AsyncRun python %'" noremap后面的字符会被vim严格执行,一个按键映射两个命令可以使用两次命令行" silent exec nnoremap <F4> :w<cr> :!python .expand('%')."<cr>"
endfunctionfunction! MemoryProfile()echo "MemoryProfile"set makeprg=python\ -m\ memory_profile\ %Make!set makeprg=python\ %
endfunction" }}}
" 定义leader
let mapleader=","" 插件配置---------------{{{" vundle------------------{{{
"加载vundle配置文件
source $HOME/.vimrc.vundle" set autoindent
"}}}" 主题字体----------------------------{{{
colorscheme gruvbox
set guifont=DejaVu\ Sans\ Mono:h13
set background=dark
" }}}" airline----------------------{{{
set laststatus=2
" 使用powerline打过补丁的字体
let g:airline_powerline_fonts=1
if !exists('g:airline_symbols')let g:airline_symbols = {}
endif
let g:airline_symbols.space = "\ua0"
" }}}" youcompleteme---------------{{{
" C语义补全
let g:ycm_global_ycm_extra_conf = '/home/yszc/.ycm_extra_conf.py'
" python语义补全
let g:ycm_python_binary_path = '/usr/bin/python3'
" ycmserver所使用的python解释器指定
" let g:ycm_server_python_interpreter = '/usr/bin/python'
" 停止提示是否载入本地ycm_extra_conf文件
let g:ycm_confirm_extra_conf = 0
" 语法关键字补全
let g:ycm_seed_identifiers_with_syntax = 1
" 开启 YCM 基于标签引擎
let g:ycm_collect_identifiers_from_tags_files = 1
" 从第2个键入字符就开始罗列匹配项
let g:ycm_min_num_of_chars_for_completion=2
" 在注释输入中也能补全
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_error_symbol = 'N'
let g:ycm_warning_symbol = 'N'
" 关闭gutter框提示
set signcolumn=no
" 补全后自动关闭预览窗口
let g:ycm_autoclose_preview_window_after_completion=1
" 打开错误和警告表
noremap <F3> : YcmDiags<CR>
" GoTo映射
nnoremap <leader>g :YcmCompleter GoToDefinitionElseDeclaration<cr>
" 选择和补全
let g:ycm_key_list_select_completion = ['<tab>']
let g:ycm_key_list_previous_completion = ['<s-tab>']
" 关闭ycm语法检查,改用ale进行语法检查
let g:ycm_enable_diagnostic_signs = 0
let g:ycm_enable_diagnostic_highlighting=0
"}}}" ale-------------{{{
"始终开启标志列
let g:ale_sig_column_always = 0
let g:ale_set_highlights = 1let g:ale_sign_error = "✘"
let g:ale_sign_warning = "►""只有保存时才进行语法检测
let g:ale_lint_on_text_changed = "never"
let g:ale_lint_on_insert_leave = 0
let g:ale_lint_on_enter = 1let g:ale_linters = {\'c':['clang'],\'c++':['clang'],\'Python':['flake8'],\}
" 关闭补全交给ycm
let g:ale_completion_enabled=0"显示linter名称,出错或警告等相关信息
let g:ale_echo_msg_error_str = "✘"
let g:ale_echo_msg_warning_str = "►"
let g:ale_echo_msg_format = '[%linter%] %s [%serverity%]'
" Set this. Airline will handle the rest.
let g:airline#extensions#ale#enabled = 1
" 错误跳转
nnoremap <c-m> :ALEPreviousWrap<cr>
nnoremap <c-n> :ALENextWrap<cr>
" }}}" nerdtree_tabs_git-------------------{{{
" q是退出
" F1触发
nnoremap <F1> :NERDTreeTabsToggle<cr>
inoremap <F1> <esc>:NERDTreeTabsToggle<cr>
" 设置nerdtree git符号
let g:NERDTreeIndicatorMapCustom = {\ "Modified" : "✹",\ "Staged" : "✚",\ "Untracked" : "✭",\ "Renamed" : "➜",\ "Unmerged" : "═",\ "Deleted" : "✖",\ "Dirty" : "✗",\ "Clean" : "✔︎",\ 'Ignored' : '☒',\ "Unknown" : "?"\ }
" 打开文件时退出
" let g:NERDTreeQuitOnOpen = 1
" }}}" tagbar-----------------------{{{
" tagbar的q是退出
" 设置触发按键
noremap <F2> : TagbarToggle<cr>
" 设置tagbar要使用的ctags路径
let g:tarbar_ctags_bin = '/usr/bin/ctags'
" 设置窗口宽度
let g:tarbar_width = 30
" 显示在窗口右边
let g:tarbar_right = 1
" 开启自动预览
let g:tagbar_autopreview = 1
" 光标自动切换到tagbar中
let g:tagbar_autoclose = 1
" }}}" easymotion---------------{{{
" 将原本默认的双leader前缀换为单leader前缀
map <Leader> <Plug>(easymotion-prefix)
" 不能使用nnoremap代替nmap,映射会失效
nmap J <Plug>(easymotion-j)
nmap K <plug>(easymotion-k)
nmap W <Plug>(easymotion-w)
nmap B <Plug>(easymotion-b)vmap J <Plug>(easymotion-j)
vmap K <plug>(easymotion-k)
vmap W <Plug>(easymotion-w)
vmap B <Plug>(easymotion-b)
" 该搜索有奇效
nmap F <Plug>(easymotion-f)
" }}}" fzf-----------------------{{{
" esc是退出
" 要先保存再搜索
"双<Leader>f在当前目录搜索文件
nnoremap <silent> f :w<CR>:Files<CR>
"双<Leader>b切换Buffer中的文件
nnoremap <silent> <Leader><Leader>b :w<CR>Buffers<CR>
"双<Leader>p在当前所有加载的Buffer中搜索包含目标词的所有行,:BLines只在当前Buffer中搜索
nnoremap <silent> <Leader><Leader>l :w<CR>Lines<CR>
"双<Leader>h在Vim打开的历史文件中搜索,相当于是在MRU中搜索,:History:命令历史查找
nnoremap <silent> <Leader><Leader>h :w<CR>History<CR>
"双<Leader>r利用ripgrep搜索当前文档中的行
nnoremap <silent> <Leader>r :w<CR>Rg<CR>
"调用Rg进行搜索,包含隐藏文件
command! -bang -nargs=* Rg\ call fzf#vim#grep(\ 'rg --column --line-number --no-heading --color=always --smart-case --hidden '.shellescape(<q-args>), 1,\ <bang>0 ? fzf#vim#with_preview('up:60%')\ : fzf#vim#with_preview('right:50%:hidden', '?'),\ <bang>0)let g:fzf_action = {\ 'ctrl-l': 'tab split',\ 'ctrl-x': 'split',\ 'ctrl-v': 'vsplit' }" }}}" tmux-------------------------{{{
" tmux中vim主题错误
" set term=screen-256color
" }}}" ultisnips-----------------{{{
" 指定snipper存储文件夹
let g:UltiSnipsSnippetDirectories=['UltiSnips']
" 此键默认为tab,会导致ycm混乱,一定要改,在insert模式下触发扩展操作
let g:UltiSnipsExpandTrigger="<c-e>"
" 展开可用snips表
" let g:UltiSnipsListSnippet="<c-i>"
" 只会在打开时映射下面的跳转键,应该不会影响之前的映射
let g:UltiSnipsJumpForwardTrigger="<c-j>"
let g:UltiSnipsJumpBackwardTrigger="<c-k>"
" 指定python版本,py2.7 或者 py3.6
let g:UltiSnipsUsePythonVersion = 3
" 编辑snips窗口以分割窗口打开,此操作会在当前目录创建UltiSnips文件夹并新建all....
let g:UltiSnipsEditSplit="vertical"" 配置所需函数
fun! Vim_snippets_filename(...)let template = get(a:000, 0, "$1")let arg2 = get(a:000, 1, "")let basename = expand('%:t:r')if basename == ''return arg2elsereturn substitute(template, '$1', basename, 'g')endif
endf" }}}" nerdcommenter-------------------{{{
" <leader>cc 紧贴当前行添加注释
" <leader>cb 紧贴左侧行添加注释
" <leader>cu 取消注释
" nmap <silent><leader>cc <plug>NERDComAlignedComment
" vmap <silent><leader>cc <plug>NERDComAlignedComment" nmap <silent><leader>cc <plug>NERDComToggleComment
" vmap <silent><leader>cc <plug>NERDComToggleComment" 注释自动添加空格
let g:NERDSpaceDelims=1
" python有特例
let g:NERDCustomDelimiters = {\ 'python': { 'left': '#', 'right': '' }\ }
" }}}" vim-autoformat-------------------{{{
" 定义astyle c++代码格式化风格
" 对指定后缀的文件名,使用指定的格式化工具,设置c++代码风格为google,缩进设为2空格
let g:formatdef_my_cpp = '"astyle --style=google --indent=spaces=2"'
let g:formatters_cpp = ['my_cpp']
" F12触发自动格式化
noremap <F12> :Autoformat<cr>" augroup autoformat
" autocmd!
" " 不能将所有文件都进行保存格式化,比如.snippets不能格式化
" au BufWrite *.h,*.cpp,*.cc,*.cxx,*.py :Autoformat
" augroup END
" }}}" indentLine-----------------{{{
let g:indentLine_fileTypeExclude = ["tex","markdown"]
" 这个颜色正好
let g:indentLine_color_term = 239
let g:indentLine_char = '┊'
" let g:indentLine_char_list = ['|', '¦', '┆', '┊']
" }}}" auto-pairs------------------------{{{
" 关闭映射<C-h>
let g:AutoPairsMapCh = 0
" 对markdown文件中的一些特殊字符进行处理" }}}
"}}}" AsyncRun------------------------{{{
" 自动打开quickfix窗口
" let g:asyncrun_open=6
" 开启或关闭quickfix窗口
" nnoremap <F5> :call asyncrun#quickfix_toggle(6)<cr>
" }}}" vimtex----------------{{{
" 设置格式缺省值
let g:tex_flavor='latex'
let g:vimtex_view_method='general'
" quickfix会在有错误时自动打开
let g:vimtex_quickfix_mode=1
" 隐藏非当前行的Latex代码
set conceallevel=2
" 设置隐藏模式
set concealcursor=c
" 防止不正常的报错高亮
let g:tex_no_error=1
" 隐藏文件
let g:tex_conceal='abdmgs'
" 开启ycm自动补全
if !exists('g:ycm_semantic_triggers')let g:ycm_semantic_triggers = {}
endif
au VimEnter * let g:ycm_semantic_triggers.tex=g:vimtex#re#youcompleteme
" 开启okular viewer
let g:vimtex_view_general_viewer = 'okular'
let g:vimtex_view_general_options = '--unique file:@pdf\#src:@line@tex'
let g:vimtex_view_general_options_latexmk = '--unique'
" }}}
"
" vim-markdown-----------------{{{
let g:vim_markdown_folding_style_pythonic = 1
let g:instant_markdown_slow = 1
" markdown编辑
let g:vim_markdown_math=1
" instant browser
let g:instant_markdown_allow_unsafe_content = 1
let g:instant_markdown_mathjax = 1
let g:instant_markdown_autoscroll = 0
let g:instant_markdown_logfile = '/tmp/instant_markdown.log'
" 设置markdown映射
augroup markdown_setautocmd!au Filetype markdown inoremap ' \
augroup END
" }}}" vim-dispatch----------------{{{
nnoremap <F5> :Copen!<cr>"}}}" vim-slime---------------------{{{
let g:slime_target="tmux"
let g:slime_paste_file = "$HOME/.slime_paste"
let g:slime_default_config={"socket_name":get(split($TMUX,","),0),"target_pane":"{down-of}"}
xmap <c-a><c-a> <Plug>SlimeRegionSend
nmap <c-a><c-a> <Plug>SlimeParagraphSend
nmap <c-a> <nop>let g:slime_python_ipython = 1
" }}}