" 时间:2024年7月26日
" vim 的配置,用标记折叠的方式组织起来,感觉很好
"--------------------------------------------------------------------------------
"# 1. Plug {{{
"## 1.1 plug-vim{{{
"--------------------------------------------------------------------------------
"安装插件 :PlugInstall
"itchyny/lightline.vim 对应的 github 仓库 https://github.com/itchyny/lightline.vim
call plug#begin('~/.vim/plugged')
Plug 'itchyny/lightline.vim'
Plug 'easymotion/vim-easymotion'
Plug 'junegunn/goyo.vim'
Plug 'junegunn/limelight.vim'
Plug 'junegunn/vim-easy-align'
Plug 'luochen1990/rainbow'
"Plug 'neoclide/coc.nvim', {'tag': '*', 'branch': 'release'}
"Plug 'preservim/nerdcommenter'
"Plug 'preservim/nerdtree'
"Plug 'preservim/tagbar'
"Plug 'simnalamburt/vim-mundo'
Plug 'tpope/vim-surround'
Plug 'morhetz/gruvbox'
Plug 'vim-scripts/DoxygenToolkit.vim'
"Plug 'scrooloose/syntastic'
"Plug 'tpope/vim-fugitive'
"Plug 'kien/ctrlp.vim'
"Plug 'honza/vim-snippets'
"Plug 'SirVer/ultisnips'
"Plug 'shougo/vimproc.vim'
Plug 'elzr/vim-json'
"Plug 'tomtom/tlib_vim'
"Plug 'kana/vim-textobj-user'
"Plug 'tpope/vim-vinegar'
"Plug 'rafi/awesome-vim-colorschemes'
call plug#end()
"}}}
"## 1.2 plugins : limelight, rainbow, EasyAlign {{{
"--------------------------------------------------------------------------------
vnoremap <Enter> <Plug>(EasyAlign)
xnoremap <Leader>g :Goyo<CR>
xnoremap ga <Plug>(EasyAlign)
nnoremap ga <Plug>(EasyAlign)
let mapleader = "\\"
let g:limelight_priority = -1
let g:limelight_eop = '\ze\n^\s'
let g:limelight_bop = '^\s'
let g:limelight_paragraph_span = 1
let g:limelight_default_coefficient = 0.7
let g:limelight_conceal_guifg = '#777777'
let g:limelight_conceal_guifg = 'DarkGray'
let g:limelight_conceal_ctermfg = 240
let g:limelight_conceal_ctermfg = 'gray'
let g:rainbow_active=1
"### limelight
""----------------------------------------
" 问题: unsupported color scheme. g:limelight_conceal_ctermfg required
" " 解决:https://github.com/junegunn/limelight.vim#options
" " Color name (:help cterm-colors) or ANSI code
"
" " Color name (:help gui-colors) or RGB color
"
" " Default: 0.5
"
" " Number of preceding/following paragraphs to include (default: 0)
"
" " Beginning/end of paragraph
" " When there's no empty line between the paragraphs
" " and each paragraph starts with indentation
"
" " Highlighting priority (default: 10)
" " Set it to -1 not to overrule hlsearch
"
"### Goyo
" "----------------------------------------
" "Goyo与Limelight聚和
"inoremap <silent><expr> <Tab> coc#pum#confirm()
"inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
"inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
"}}} plugins
"## 1.3 EasyMotion {{{
map <Leader> <Plug>(easymotion-prefix)
nnoremap <c-j> <Plug>(easymotion-w)
nnoremap <c-k> <Plug>(easymotion-b)
"nnoremap <c-;> <Plug>(easymotion-bd-f)
""inoremap <c-;> <Esc><Plug>(easymotion-bd-f)
"}}}
" ## 1.4 DoxygenToolkit {{{
"--------------------------------------------------------------------------------
"Use:
":Dox
":DoxLic
":DoxAuthor
":DoxUndoc(DEBUG)
":DoxBlock
nnoremap <c-c> :Dox<cr>
let g:DoxygenToolkit_commentType = "C++"
let g:DoxygenToolkit_briefTag_pre = "\\brief "
let g:DoxygenToolkit_templateParamTag_pre = "\\tparam "
let g:DoxygenToolkit_paramTag_pre = "\\param "
let g:DoxygenToolkit_returnTag = "\\return "
let g:DoxygenToolkit_throwTag_pre = "\\throw " " \\exception is also valid
let g:DoxygenToolkit_fileTag = "\\file "
let g:DoxygenToolkit_authorTag = "\\author "
let g:DoxygenToolkit_dateTag = "\\date "
let g:DoxygenToolkit_versionTag = "\\version "
let g:DoxygenToolkit_blockTag = "\\name "
let g:DoxygenToolkit_classTag = "\\class "
"let g:DoxygenToolkit_blockHeader = "-------------------------------------------------------------------------------- "
"let g:DoxygenToolkit_blockFooter = "-------------------------------------------------------------------------------- "
let g:DoxygenToolkit_authorName = "linlin"
let g:DoxygenToolkit_licenseTag = "My onw license"
" }}}
" }}} Plug
"--------------------------------------------------------------------------------
"# 2. 对 Vim 自带设置的更改 {{{
"## 2.1 option : set {{{
"--------------------------------------------------------------------------------
"set softtabstop=4
"set backspace=2 " 修正终端上的退格键 Backspace 的行为
set backspace=3
set shiftwidth=4 " 用于自动缩进的空格数量
set expandtab " 将制表符 Tab 展开为空格,这对于 Python 尤其有用
set tabstop=4 " tab 的空格数量
" 使用vimscript进行插入的时候,tab会成为8个空格的,所以不要开启的好
" 自动跟紧上一行的缩进
" autoload-plugin
"packloadall " 加载所有插件
"silent! helptags ALL " 为所有插件加载帮助文档
"noh "清楚高亮显示
filetype on
filetype plugin on
filetype indent on " 根据文件类型自动缩进
"set showtabline=1
"set guioptions-=T
"set guioptions-=m
"set guifont=Lucida_Console:h18
"set guifont=Courier_New:b:h16
"set completeopt=menu,menuone,noselect
"##自定义状态栏 {{{
"set statusline=[%n]%1*%F%=%0*%2*%l,%c\ %p%%%0*\|ascii=%b,hex=%B%{((&fenc==\"\")?\"\":\"\ \|\ \\".&fenc)}\ \|\ \%{$USER}\ @\ %{hostname()}\
"set statusline=[%n]\ %#HIComment%F%=\ \|\ %l,%c\ %p%%\ \|\ ascii=%b,hex=%B%{((&fenc==\"\")?\"\":\"\ \|\ \\".&fenc)}\ \|\ \%{$USER}\ @\ %{hostname()}\ " 没有效果
"set statusline=[%n]\ %f%m%r%h\ \|\ \ \ \|%=\|\ %l,%c\ %p%%\ \|\ ascii=%b,hex=%b%{((&fenc==\"\")?\"\":\"\ \|\\".&fenc)}\ \|\ \%{$USER}\ @\ %{hostname()}\
"set statusline=[%n]\ %f%m%r%h\ \|\ \ pwd:\ %{CurrentDir()}\ \|%=\|\ %l,%c\ %p%%\ \|\ ascii=%b,hex=%b%{((&fenc==\"\")?\"\":\"\ \|\\".&fenc)}\ \|\ \%{$USER}\ @\ %{hostname()}\
"}}}
"set textwidth=80 " 限制一行的长度,不错的功能
"set relativenumber "相对行号
"set paste " 开启这个选项,复制进来的文本的换行符就不会乱
"set cindent " C 语言的缩进
""setlocal nomodifiable
"setlocal nobuflisted
"setlocal noswapfile
"setlocal bufhidden=hide
"setlocal buftype=nofile
"setlocal noreadonly
set noswapfile
set nobackup
set noundofile
set virtualedit=all "详细信息去看帮助文档
set runtimepath+=~\\.vim\UltiSnips
set runtimepath+=~\\.vim
set scrolloff=5 " vertical scrolling the cursor distance with bottom
set t_Co=256 " 开启 256 色
set fileencodings=utf-8,gbk
set foldlevel=3
set foldmethod=marker
set laststatus=2
set nowrap
set sidescroll=10 " 自动的滚动文本,当移动的文本没有显示时
set hlsearch "高亮‘/’搜索到的匹配项
set number " 显示行号
set mouse=a " 开启鼠标,默认是不能使用鼠标的
set autoindent " 开启自动缩进
set syntax=on " 开启语法高亮
"}}} option
"## 2.2 mapping : map {{{
"--------------------------------------------------------------------------------
nnoremap <F2> :NERDTreeToggle<CR>
"nnoremap <F2> :Vexplore<CR>
nnoremap <F3> :tabnew<CR>
nnoremap <F7> :w<CR>
nnoremap <F6> :call me#Compile()<CR>
nnoremap <F8> :wa<CR>
inoremap <F8> <C-R>=ListMonths()<CR>
nnoremap <F8> :w<CR>
nnoremap <F9> :Tagbar<CR>
nnoremap <F10> :wqa<CR>
nnoremap gs :call me#SwitchToSource()<CR>
" 要求保持光标位置不变 # 自定义函数
""--------------------------------------------------------------------------------
noremap cx :call CopyLine()<CR>
nnoremap <Space> <C-d>
nnoremap <LEADER>z ZZ
nnoremap <LEADER>v :Goyo<CR>
nnoremap <LEADER>t <c-w>T
nnoremap <LEADER>sc :!start cmd<CR>
nnoremap <LEADER>o :tabnew $MYVIMRC<CR>
nnoremap <LEADER>mo :browse oldfiles<CR>
nnoremap <LEADER>i :call me#CreateImplement()<CR>
nnoremap <LEADER>e :call me#GenerateDefine()<CR>
nnoremap <c-q> :
"nnoremap <c-v> <c-q> "与终端中的快捷键冲突
nnoremap <C-n> :bel vnew<cr>
nnoremap <C-b> :call me#Compile()<CR>
"nnoremap <c-s> :w<cr>
inoremap <c-q> <Esc>:
"nnoremap <LEADER>d :call append(line('.'), strftime('%c'))<CR>
" }}} map
"## 2.3 autocmd : au {{{
"--------------------------------------------------------------------------------
"au! BufNewFile *.cpp,*.h,*.hpp setlocal foldmethod=syntax
"au! BufRead *.cpp,*.h,*.hpp setlocal foldmethod=syntax
"au! BufRead *.ixx set filetype=cpp
" }}} autocmd
"## 2.4 filetype : cpp {{{
"--------------------------------------------------------------------------------
"}}}
"## 2.5 abbreviations {{{
" --------------------------------------------------------------------------------
"iab ce std::cout << << std::endl;<Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left>
"iab ff for(int i = 0; i < n; ++i)<CR>{<CR><SPACE><SPACE><SPACE><SPACE>
"iab rr std::random_device rd;<CR>std::uniform_int_distribution dist(0, 10);
"}}} abbr
"## 2.6 python {{{
"--------------------------------------------------------------------------------
if &filetype == "python"
set foldmethod=indent
endif
"}}} python
"## 2.7 依操作系统版本来进行相应的设置 {{{
""--------------------------------------------------------------------------------
" python 根据安装位置来选择
" windows11
if windowsversion() == "10.0"
set runtimepath+="D:\\Programs\\Python\\Python311\python311.dll"
set guifont=AnonymicePro_Nerd_Font_Mono:h16
"windows7
elseif windowsversion() == "6.1"
"set runtimepath+="D:\\Users\\Programs\\Python\\Python38\\python38.dll"
set pythonthreedll=D:\\Users\\Programs\\Python\\Python38\\python38.dll
colorscheme gruvbox
endif
"}}}
" }}} 对 Vim 自带设置的更改
"--------------------------------------------------------------------------------
"# 3. 自定义的设置、函数 {{{
"## 3.1 重复行而保持光标位置不变 {{{
""--------------------------------------------------------------------------------
function! CopyLine()
let l:old_cursor = getcursorcharpos()
execute "normal vYp"
call setcursorcharpos(l:old_cursor[1]+1, l:old_cursor[2])
endfunction
"}}}
"## 3.2 补全 complete {{{
"### thesaurus 辞典补全,将一个指定的文件作为数据来源
""--------------------------------------------------------------------------------
"### dictionary
""--------------------------------------------------------------------------------
"将单词放入一个txt文件,以空格分隔或以行分隔,将文件放入dictionary变量中,在插入模式下 Ctrl-X Ctrl-K 触发
"补全
" set dictionary+=$linp/vim/dict/c.txt
" set dict+=~\\vimfiles\\complete\\cpp-keyword.txt
" set dict+=~\\vimfiles\complete\\cpp-std-header.txt
" set dict+=~\\vimfiles\complete\\frq.txt
" set dict+=~/vimfiles/tmp/CMakeLists.txt
" set dict+=~/vimfiles/complete/cmake_command.txt
"### tags
""--------------------------------------------------------------------------------
"需要使用 ctags 程序(请先下载)
"插入模式下 Ctrl-N 触发
"set tags+=D:/Qt/6.5.0/Src/tags
"set tags+=~/vimfiles/tags/tags
"set tags+=D:/user/code/practice/qt/tdesktop/tags
set tags+=D:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/tags,$lin/libraries/jsoncpp/tags,$lin/libraries/include/lin/tags
"}}}
"## 3.3 my plugin {{{
"--------------------------------------------------------------------------------
"### 使窗口位于中间,并打开顶部打开一个预览窗口
function! PlaceholderWindow()
"wincmd T
let winid = win_getid()
vnew
vertical resize 55
call win_gotoid(winid)
split
resize 5
call win_gotoid(winid)
endfunction
command -nargs=0 PWin call PlaceholderWindow()
"if has('gui_running')
"set imactivatekey=C-space
"inoremap <ESC> <ESC>:set iminsert=2<CR>
"endif
""" C++ 插入预防宏
"function! Ifndef()
" let name = input("请输入宏名:")
" if empty(name) == 1
" return
" endif
" let macro_name = toupper(name) .. "_H_"
" let content = [
" \ "#ifndef " .. macro_name,
" \ "#define " .. macro_name,
" \]
" call append(line("0"), content)
" call append(line("$"), "#endif // " .. macro_name)
"endfunction
""" 查看中文月份
"func! ListMonths()
" "call complete(col('.'), ['January', 'February', 'March',
" "\ 'April', 'May', 'June', 'July', 'August', 'September',
" "\ 'October', 'November', 'December'])
" let cpp_complete = [
" \ "std::cout << << std::endl;",
" \ "int main() { f(); }",
" \]
" call complete(col('.'), cpp_complete)
" "实现光标的移动,在补全使用特殊的参数,在选择后,解析结果,然后移动光标
" return ''
"endfunc
"}}} plugin
"## 3.4 Register Record {{{
" 清空寄存器
"let @a =""
"宏与复制用的是相同的寄存器
"大写宏名是追加进寄存器
"}}}
"## 3.5 Self Custom Symbol {{{
"--------------------------------------------------------------------------------
"┌─────────────┐
"│ │
"└─────────────┘
"/zbf": [ "┌─────────────┐", "│ │", "├─────────────┤", "└─────────────┘", "┌", "┬", "┐", "┌", "─", "┐", "┍", "┯", "┑", "╔", "╦", "╗", "├", "┼", "┤", "│", "┼", "│", "┝", "┿", "┥", "╠", "╬", "╣", "└", "┴", "┘", "└", "─", "┘", "┕", "┷", "┙", "╚", "╩", "╝", "┏", "┳", "┓", "┏", "━", "┓", "┎", "┰", "┒", "╔", "═", "╗", "┣", "╋", "┫", "┃", "╋", "┃", "┠", "╂", "┨", "║", "╬", "║", "┗", "┻", "┛", "┗", "━", "┛", "┖", "┸", "┚", "╚", "═", "╝", "╓", "╥", "╖", "╒", "╤", "╕", "┏", "┱", "┐", "┌", "┲", "┓", "╟", "╫", "╢", "╞", "╪", "╡", "┡", "╃", "┤", "├", "╄", "┩", "╙", "╨", "╜", "╘", "╧", "╛", "└", "┴", "┘", "└", "┴", "┘", "┌", "┬", "┐", "┏", "┳", "┓", "╭", "─", "╮", "╱", "─", "╲", "┟", "╁", "┧", "┞", "╀", "┦", "│", "╳", "│", "│", "┼", "│", "┗", "┻", "┛", "└", "┴", "┘", "╰", "─", "╯", "╲", "─", "╱", "┄", "┈", "┉", "┅", "┇", "┋", "┊", "┆" ]
"}}}
"## 3.6 note {{{
"--------------------------------------------------------------------------------
"### platform
""--------------------------------------------------------------------------------
"if has('win32')
"echo "win32"
"elseif has('unix')
"echo "unix"
"elseif has ('mac')
"echo "mac"
"else
"echo "else"
"endif
"对操作系统版本的判断
"使用 windowsversion() 函数:
"版本:win11 ,结果 10.0
"### 得到当前时间
""--------------------------------------------------------------------------------
"nnoremap <LEADER>d :call append(line('.'), strftime('%c'))<CR>
"### vim 时间相关的函数
""--------------------------------------------------------------------------------
"使用: `:h strftime` 查看相应的介绍
"- strftime
"- localtime
" - 从 1970 年 1 月开始的秒数
"- getftime
" - 得到指定文件的最后修改时间,从 1970 年 1 月开始的秒数
"- strptime
" - 将指定格的字符串时间转换为 Unix 时间戳
"2024-7-27
"我安装了两个插件:
"Plug 'SirVer/ultisnips' 这个插件依赖于 python3
"Plug 'honza/vim-snippets'
"UltiSnips 提供了更方便的获取时间的方法——在编辑的时候
"### { { { } } }
""--------------------------------------------------------------------------------
"这是 vim 的折叠标记
"}}} note
"## 3.7 包含网址的一行,变为 markdown 超链接格式 {{{
function! MDLink()
execute "normal I[](\<Esc>A)\<Esc>0a"
endfunction
command -nargs=0 MDLink call MDLink()
"}}}
"## 3.8 my variable {{{
"if has('win32')
" let $mycfg="~/vimfiles/pack/MyVim/start"
" let $mytmp="~/vimfiles/tmp"
" let $myinclude="D:\\user\\code\\libraries\\include"
" let $myhome="D\\user\\code"
"else
" let $mycfg="~/.vim/pack/MyVim/start"
" let $mytmp="~/.vim/tmp"
"endif
"}}}
"## 3.9 中文输入法问题 {{{
"https://blog.51cto.com/u_15273875/3858820
":help iminsert
"if has('multi_byte_ime')
""没有开启 IME 时的光标背景色
"hi Cursor guifg=bg guibg=Orange gui=NONE
""开启 IME 时的光标背景色
"hi CursorIM guifg=NONE guibg=Skyblue gui=NONE
""关闭 vim 的自动切换 IME 输入法(插入模式和正常模式)
"inoremap <silent> <ESC> <ESC>:set iminsert=0<CR>
""set imi=2
"endif
"if has('gui_running')
"set imactivatekey=C-space
"inoremap <ESC> <ESC>:set iminsert=2<CR>
"endif
"}}}
"## 3.10 menu : menu, toolbar {{{
" --------------------------------------------------------------------------------
" 在 vim 中,菜单是一个很强大的功能,但是需要自定义
"amenu ToolBar.BuiltIn21 :call me#Compile()<CR>
"amenu ToolBar.BuiltIn22 :!start subl.exe %<CR>
set runtimepath+=C:/Users/16207/vimfiles/bitmaps
amenu icon=~/vimfiles/bitmaps/main_icon.xpm ToolBar.Test :echo "test"<CR>
"
"gvim toolbar 图标
"2024-07-28 01:19
"https://superuser.com/questions/11289/how-do-i-customize-the-gvim-toolbar
":tmenu ToolBar.taglist Toggle display of the Taglis
":amenu ToolBar.taglist :TlistToggle>
"tmenu 的作用是:工具提示,在鼠标悬停是显示信息
"amenu 决定图标被点击时会发生什么
"
"加上图标
":amenu icon=~/vimfiles/bitmaps/main_icon.bmp ToolBar.taglist :TlistToggle>
"在 windows 图标的格式是 bmp,在 linux 是 xpm ,图标的大小要是 18x18 的。
" ### term_start
"term_start({cmd} [, {options}]) *term_start()*
":call term_start(['sh', '-c', 'echo hello'])
"### pop_menu
" }}} menu
" }}} 自定义的设置、函数
"--------------------------------------------------------------------------------
"# 4. 使用方法 {{{
"2024-07-28 01:40
"## 4.1 折叠的使用方法 "{{{
"本文件使用标记折叠方法组织内容
"{{{ 折叠中的内容 }}}
":set foldmethod
"查看折叠方法
"
":set foldmethod=marker
"
"有关折叠的快捷键:
":h z
"
"作者常用的(在 normal 模式下使用):
"zM 递归的折叠所有部分
"zR 展开所有折叠的部分(包括递归)
"zm 增加一层(:h foldlevel)折叠
"zr 减去一层折叠
"zc 打开光标下的折叠
"za 打开/关闭光标下的折叠
"zj 去到下一个折叠上
"zk 去到上一个折叠上
"}}}
"## 查找替换 : substitute, find, replace {{{
"2024-07-28 01:16
""--------------------------------------------------------------------------------
" 被替换者: test_123
" 替换者: new_123
" 在同一个目录<dir>中的所有 h 文件中
" :cd <dir>
" :args *.h
" :argdo %s/test_123/new_123/ge | update
" 上面一行命令的解释:
" argdo 对所有在 args 中的文件执行后面的命令
" %s/被替换者/替换者/ge
" g 整个文件的所有符合条件者都被替换
" e 没有找到的情况,不报错
" | 用于执行多个命令
" update 保存对文件执行的操作(只对已经修改的缓冲有效)
"### 查找空行
"/^$
":%s/\<s\>/\r/g
"将单词 s 替换为换行符(注意,这里的文件格式是 dos, set fileformat)
"}}}
"}}} 使用方法
标签:Plug,---------------------------------------------------------------------------
From: https://www.cnblogs.com/lin-hui/p/18328428