"            基础设置            "
" 设置主题
colorscheme onedark
" 显示行号
set number
" 语法高亮 
set syntax=on
" Tab键的宽度为4
set tabstop=4
" 统一缩进为4
set softtabstop=4
" 自动缩进
set autoindent
" 代码补全
set completeopt=preview,menu
" 去掉输入错误的提示声音
set noeb
" 不需要备份
set nobackup
" 禁止生成临时文件
set noswapfile
" 关闭 vi 兼容模式
set nocompatible 
" 突出显示当前行
"set cursorline 
" 打开状态栏标尺
set ruler 
" 设定 << 和 >> 命令移动时的宽度为 4
set shiftwidth=4 
" 设置备份时的行为为覆盖
set backupcopy=yes 
" 搜索时忽略大小写,但在有一个或以上大写字母时仍保持对大小写敏感
set ignorecase smartcase 
" 禁止在搜索到文件两端时重新搜索
set nowrapscan 
" 输入搜索内容时就显示搜索结果
set incsearch
" 搜索时高亮显示被找到的文本
set hlsearch
" 关闭错误信息响铃
set noerrorbells 
" 关闭使用可视响铃代替呼叫
set novisualbell
" 置空错误铃声的终端代码
set t_vb=
" 设置魔术
set magic
" 允许在有未保存的修改时切换缓冲区,此时的修改由 vim 负责保存
set hidden
" 隐藏工具栏
set guioptions-=T 
" 隐藏菜单栏
set guioptions-=m 
" 开启新行时使用智能自动缩进
set smartindent 
" 不设定在插入状态无法用退格键和 Delete 键删除回车符
set backspace=indent,eol,start
" 设定命令行的行数为 1
set cmdheight=1 
" 显示状态栏
set laststatus=2
" 设置在状态行显示的信息
set statusline=%1*\%F
set statusline+=%=%2*\%y%m%r%h%w\ %*
set statusline+=%3*\%{&ff}\[%{&fenc}]\ %*
set statusline+=%4*\%3p%%\%*
" 允许插件
filetype plugin on
" 文件被修改自动载入
set autoread
" UTF-8 编码
set encoding=utf-8
set termencoding=utf-8
set formatoptions+=mM
set fencs=utf-8,gbk
" 关闭O延时
set noesckeys
" 打开鼠标
set mouse=a
" 支持方向键
set nocompatible

"            VimPlug插件管理                "
filetype off
call plug#begin('~/.vim/plugged')
Plug 'scrooloose/nerdtree'
Plug 'tpope/vim-commentary'
Plug 'Yggdroot/LeaderF', { 'do': './install.sh' }
Plug 'vim-scripts/AutoComplPop'
Plug 'octol/vim-cpp-enhanced-highlight'
Plug 'w0rp/ale'
Plug 'rhysd/vim-clang-format'
call plug#end()
filetype plugin indent on

"    Nerdtree
map <F2> :NERDTreeToggle<CR>
" 窗口大小
let NERDTreeWinSize=30

"设置树的显示图标
let g:NERDTreeDirArrowExpandable = '▸'
let g:NERDTreeDirArrowCollapsible = '▾'
let NERDTreeIgnore = ['\.pyc$','\.out','\.a','\.so','\lib']
let g:NERDTreeShowLineNumbers=1
let g:NERDTreeHidden=0  

"使用UI
let NERDTreeMinimalUI = 1
let NERDTreeDirArrows = 1

"   LeaderF
let $GTAGSLABEL = 'native-pygments'
let g:Lf_ShortcutF = '<C-P>'
let g:Lf_StlSeparator = { 'left': '', 'right': '', 'font': '' }
let g:Lf_RootMarkers = ['.project', '.root', '.svn', '.git']
let g:Lf_WorkingDirectoryMode = 'Ac'
let g:Lf_WindowHeight = 0.30
let g:Lf_ShowRelativePath = 0
let g:Lf_HideHelp = 1
let g:Lf_UseCache = 0
let g:Lf_UseVersionControlTool = 0
let g:Lf_IgnoreCurrentBufferName = 1
let g:Lf_PreviewResult = {'Function': 0, 'BufTag': 0 }
" let g:Lf_WindowPosition = 'popup'
" let g:Lf_PreviewInPopup = 1
noremap <leader>fb :<C-U><C-R>=printf("Leaderf buffer %s", "")<CR><CR>
noremap <leader>fm :<C-U><C-R>=printf("Leaderf mru %s", "")<CR><CR>
"noremap <leader>fl :<C-U><C-R>=printf("Leaderf line %s", "")<CR><CR>
noremap <leader>fl :LeaderfFunction!<cr>
noremap <leader>ft :<C-U><C-R>=printf("Leaderf bufTag %s", "")<CR><CR>

" 模糊匹配当前buff
noremap <leader>gs :<C-U><C-R>=printf("Leaderf! rg --current-buffer -e %s ", expand("<cword>"))<CR><CR>
" 模糊匹配当前目录下所有
noremap <leader>gg :<C-U><C-R>=printf("Leaderf! rg -e %s ", expand("<cword>"))<CR><CR>

" search visually selected text literally
xnoremap gf :<C-U><C-R>=printf("Leaderf! rg -F -e %s ", leaderf#Rg#visual())<CR>
noremap go :<C-U>Leaderf! rg --recall<CR>
let g:Lf_WildIgnore = {
            \ 'dir': ["build", "software", "bin"],
            \ 'file': ["*.a", "*.lib", "*.so", "*.pb", "log_*", "*.out", "*.o"]
            \}

" should use `Leaderf gtags --update` first
let g:Lf_GtagsAutoGenerate = 1
let g:Lf_Gtagslabel = 'native-pygments'
noremap <leader>fr :<C-U><C-R>=printf("Leaderf! gtags -r %s --auto-jump", expand("<cword>"))<CR><CR>
noremap <leader>fd :<C-U><C-R>=printf("Leaderf! gtags -d %s --auto-jump", expand("<cword>"))<CR><CR>
noremap <leader>fo :<C-U><C-R>=printf("Leaderf! gtags --recall %s", "")<CR><CR>
noremap <leader>fn :<C-U><C-R>=printf("Leaderf gtags --next %s", "")<CR><CR>
noremap <leader>fp :<C-U><C-R>=printf("Leaderf gtags --previous %s", "")<CR><CR>

" Ale
let g:ale_completion_delay = 500
let g:ale_echo_delay = 20
let g:ale_lint_delay = 500
let g:ale_echo_msg_format = '[%linter%] %code: %%s'
let g:ale_lint_on_text_changed = 'normal'
let g:ale_lint_on_insert_leave = 1
let g:airline#extensions#ale#enabled = 1

let g:ale_c_gcc_options = '-Wall -O2 -std=c99'
let g:ale_cpp_gcc_options = '-Wall -O2 -std=c++14'
let g:ale_c_cppcheck_options = ''
let g:ale_cpp_cppcheck_options = ''

let g:ale_sign_error = 'X'
let g:ale_sign_warning = '?'
nmap <Leader>d :ALEDetail<CR>

" clang-format
"退出插入模式时自动格式化
let g:clang_format#auto_format_on_insert_leave=1
# 插件的安装
sudo apt install clang-format
vim ~/.clang-format
clang-format 配置文件
https://www.jiangpenghui.cn/linux/282.html

Gtags
wget http://tamacom.com/global/global-6.6.3.tar.gz
sudo apt-get build-dep global
sudo apt-get install libncurses5-dev libncursesw5-dev
./configure
make
sudo make install

Ripgrep
git clone https://github.com/BurntSushi/ripgrep
cd ripgrep
sudo apt install cargo
#使用国内镜像
vim ~/.cargo/config

[registry]
index = "https://mirrors.ustc.edu.cn/crates.io-index/"
[source.crates-io]
replace-with = 'ustc'
[source.ustc]
registry = "https://mirrors.ustc.edu.cn/crates.io-index/"

cargo build --release
sudo cp ./target/release/rg /usr/local/bin/

YCM
git clone https://github.com/Valloric/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe
cd ~/.vim/bundle/YouCompleteMe
git submodule update --init --recursive
./install.py --clang-completer --clang-completer