source # 引用外部文件,即把命令拿出去写在其他文件中,但效果一样
:r # 将某个文件内容插入到当前文件中
:command! xxx :r xxx.txt # 第一个xxx首字母必须大写,xxx之后跟vim指令即可
坑点:wsl更新,root用户也需要加上sudo前缀!!
tabs
https://zhuanlan.zhihu.com/p/25946307
:tabxxx
:tabedit // 按下tab选择文件是,方向下键选择下一目录下的,上键选择上级目录
Coc配置
https://github.com/Kicamon/nvim
- 安装vim-plug
- :plug-install
- 更新vim,nodejs,npm
- 安装clangd,clang-format
- coc安装
:CocInstall coc-clangd
:CocInstall coc-pairs
:CocInstall coc-snippets
安装其他语言补全
https://github.com/neoclide/coc.nvim/wiki/Language-servers
CocInstall xxx/CocUninstall
CocList extensions # 查看安装了哪些插件
python第三方库补全
CocInstall pyright
# 切到你的python环境下,就可以完成当前环境下第三方库的补全了
snippet
https://github.com/SirVer/ultisnips/blob/master/doc/UltiSnips.txt
date 指令:https://www.runoob.com/linux/linux-comm-date.html
时间
/*
* author: mikezheng
* created: `date +"%d.%m.%Y %H:%M:%S"`
*/
文件名
snippet acm "acm" b
/*
* author: mikezheng
* created: `date +"%d.%m.%Y %H:%M:%S"`
*/
import java.io.*;
import java.util.*;
import java.math.*;
public class ${2:`!p snip.rv = snip.basename`} {
public static void main(String[] args) {
${1}
}
}
endsnippet
vimrc添加注释头
:command! Time exec ":call SetTitle()" | exec "call cursor(5, 1)"
autocmd BufNewFile *.* exec ":call SetTitle()"
func! SetTitle()
call setline(1, "/*")
call append(line("."), " * author: mikezheng")
call append(line(".")+1, " * created: ".strftime("%d-%m-%Y %H:%M:%S"))
call append(line(".")+2, " */")
call append(line(".")+3, "")
endfunc
autocmd VimEnter * call cursor(5, 1)
vimrc大乱炖模板(精简模板就不放了,自行删减)
" All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
" the call to :runtime you can find below. If you wish to change any of those
" settings, you should do it in this file (/etc/vim/vimrc), since debian.vim
" will be overwritten everytime an upgrade of the vim packages is performed.
" It is recommended to make changes after sourcing debian.vim since it alters
" the value of the 'compatible' option.
" runtime! debian.vim
" Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc.
" This happens after /etc/vim/vimrc(.local) are loaded, so it will override
" any settings in these files.
" If you don't want that to happen, uncomment the below line to prevent
" defaults.vim from being loaded.
" let g:skip_defaults_vim = 1
" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
" set nocompatible
" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
" if has("syntax")
" syntax on
" endif
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark
" Uncomment the following to have Vim jump to the last position when
" reopening a file
"au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"filetype plugin indent on
" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd " Show (partial) command in status line.
"set showmatch " Show matching brackets.
"set ignorecase " Do case insensitive matching
"set smartcase " Do smart case matching
"set incsearch " Incremental search
"set autowrite " Automatically save before commands like :next and :make
"set hidden " Hide buffers when they are abandoned
"set mouse=a " Enable mouse usage (all modes)
" Source a global configuration file if available
"if filereadable("/etc/vim/vimrc.local")
" source /etc/vim/vimrc.local
"endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 显示相关
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set shortmess=atI " 启动的时候不显示那个援助乌干达儿童的提示
winpos 5 5 " 设定窗口位置
set nu " 显示行号
set go= " 不要图形按钮
"autocmd InsertLeave * se nocul " 用浅色高亮当前行
"autocmd InsertEnter * se cul " 用浅色高亮当前行
autocmd BufNewFile CMakeLists.txt exec ":call CmakeFill()"
func! CmakeFill()
call setline(1, "# cmake version")
call append(".", "cmake_minimum_required(VERSION )")
call append(line(".")+1, "")
call append(line(".")+2, "# project name")
call append(line(".")+3, "# project()")
call append(line(".")+4, "")
call append(line(".")+5, "# add_subdirectory()")
call append(line(".")+6, "")
call append(line(".")+7, "# Only c,cpp")
call append(line(".")+8, "# aux_source_directory()")
call append(line(".")+9, "")
call append(line(".")+10, "# include_directories()")
call append(line(".")+11, "")
call append(line(".")+12, "# my_libraries")
call append(line(".")+13, "# link_libraries (")
call append(line(".")+14, "# \"\"")
call append(line(".")+15, "# )")
call append(line(".")+16, "")
call append(line(".")+17, "# set(LIBRARY_SRC )")
call append(line(".")+18, "# add_library(_static STATIC ${LIBRARY_SRC})")
call append(line(".")+19, "# SET_TARGET_PROPERTIES(_static PROPERTIES OUTPUT_NAME \"\")")
call append(line(".")+20, "# SET_TARGET_PROPERTIES(_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)")
call append(line(".")+21, "# add_library( SHARED ${LIBRARY_SRC})")
call append(line(".")+22, "# SET_TARGET_PROPERTIES( PROPERTIES OUTPUT_NAME \"\")")
call append(line(".")+23, "# SET_TARGET_PROPERTIES( PROPERTIES CLEAN_DIRECT_OUTPUT 1)")
call append(line(".")+24, "")
call append(line(".")+25, "# add_executable()")
call append(line(".")+26, "")
call append(line(".")+27, "# sys_libraries")
call append(line(".")+28, "# set (")
call append(line(".")+29, "# # val_name")
call append(line(".")+30, "# # -pthread -ljsoncpp ...")
call append(line(".")+31, "# )")
call append(line(".")+32, "# TARGET_LINK_LIBRARIES( ${val_name})")
call append(line(".")+33, "")
call append(line(".")+34, "# install()")
call append(line(".")+35, "")
call append(line(".")+36, "# set(EXECUTABLE_OUTPUT_PATH )")
call append(line(".")+37, "")
endfunc
"autocmd BufNewFile *.cpp,*.c,*.h,*.sh,*.java exec ":call SetTitle()"
func! SetTitle()
"如果文件类型为.sh文件
if &filetype == 'sh'
call setline(1,"\#########################################################################")
call append(line("."), "\# File Name : ".expand("%"))
call append(line(".")+1, "\# Author : mikezheng")
call append(line(".")+2, "\# mail : csmikezheng@gmail.com")
call append(line(".")+3, "\# Created Time : ".strftime("%c"))
call append(line(".")+4, "\#########################################################################")
call append(line(".")+5, "")
call append(line(".")+6, "\#!/bin/bash")
call append(line(".")+7, "")
call append(line(".")+8, "")
else
call setline(1, "/**")
call append(line("."), " * author: mikezheng")
call append(line(".")+1, " * created: ".strftime("%d-%m-%Y %H:%M:%S"))
call append(line(".")+2, "**/")
call append(line(".")+3, "")
endif
if expand("%:e")=='cpp'
call append(line(".")+4, "#include <csapp.h>")
call append(line(".")+5, "")
call append(line(".")+6, "using namespace std;")
call append(line(".")+7, "")
call append(line(".")+8, "signed main(int argc, char *argv[]) {")
call append(line(".")+9, " ")
call append(line(".")+10, " return 0;")
call append(line(".")+11, "}")
endif
if expand("%:e")=='c'
call append(line(".")+4, "#include <stdio.h>")
call append(line(".")+5, "")
call append(line(".")+6, "signed main(int argc, char *argv[]) {")
call append(line(".")+7, " ")
call append(line(".")+8, " return 0;")
call append(line(".")+9, "}")
endif
if expand("%:e") == 'h'
call append(line(".")+4, "#pragma once")
call append(line(".")+5, "#include <csapp.h>")
endif
if expand("%:e") == 'java'
call append(line(".")+4, "import java.io.*;")
call append(line(".")+5, "import java.util.*;")
call append(line(".")+6, "import java.math.*;")
call append(line(".")+7, "")
call append(line(".")+8, "public class ".expand("%:r")." {")
call append(line(".")+9, " public static void main(String[] args) {")
call append(line(".")+10, " ")
call append(line(".")+11, " }")
call append(line(".")+12, "}")
endif
endfunc
"color asmanian2 " 设置背景主题
set guifont=Courier_New:h10:cANSI " 设置字体
set ruler " 显示标尺
set showcmd " 输入的命令显示出来,看的清楚些
set cmdheight=1 " 命令行(在状态行下)的高度,设置为1
"set whichwrap+=<,>,h,l " 允许backspace和光标键跨越行边界(不建议)
set scrolloff=3 " 光标移动到buffer的顶部和底部时保持3行距离
set novisualbell " 不要闪烁(不明白)
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} "状态行显示的内容
"set laststatus=1 " 启动显示状态行(1),总是显示状态行(2)
set foldenable " 允许折叠
set foldmethod=manual " 手动折叠
set background=dark "背景使用黑色
set nocompatible "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
" 显示中文帮助
if version >= 603
set helplang=cn
set encoding=utf-8
endif
" 设置配色方案
"colorscheme murphy
"字体
"if (has("gui_running"))
" set guifont=Bitstream\ Vera\ Sans\ Mono\ 10
"endif
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936
set fileencoding=utf-8
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"键盘命令
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"C,C++ 按enter编译运行
"这里的<是去掉文件的后缀
map <silent> <Enter> :call CompileRunGcc() <CR><CR>
func! CompileRunGcc()
silent exec "w"
if &filetype == 'c'
silent exec "!gcc % -pthread -lleveldb -lsnappy -std=gnu11 $(mysql_config --libs) $(mysql_config --cflags) -lcjson -o %< && ./%<"
silent exec ":q"
elseif &filetype == 'cpp'
silent exec "!g++ % -pthread -lleveldb -lsnappy -std=c++14 $(mysql_config --libs) $(mysql_config --cflags) -ljsoncpp -o %< && ./%<"
silent exec ":q"
elseif &filetype == 'java'
silent exec "!javac % && java %<"
silent exec ":q"
elseif &filetype == 'python'
silent exec "!python %"
silent exec ":q"
elseif &filetype == 'go'
silent exec "!go build % && ./%<"
silent exec ":q"
endif
endfunc
"C,C++的调试
map <silent> <F12> :call Rungdb() <CR><CR>
func! Rungdb()
exec "w"
if &filetype == 'c'
silent exec "!gcc % -pthread -g -o %<"
silent exec "!gdb -tui ./%<"
silent exec ":q"
elseif &filetype == 'cpp'
silent exec "!g++ % -pthread -g -o %<"
silent exec "!gdb -tui ./%<"
silent exec ":q"
endif
endfunc
" ---------neoclide/coc.nvim--------
set pumheight=10
set updatetime=100
set signcolumn=no
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1) :
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
autocmd CursorHold * silent call CocActionAsync('highlight')
"-----vim-autoformat/vim-autoformat-----
let g:formatdef_clangformat_google = '"clang-format -style google -"'
let g:formatters_cpp = ['clangformat_google']
let g:formatters_c = ['clangformat_google']
let g:autoformat_autoindent = 0
let g:autoformat_retab = 0
let g:autoformat_remove_trailing_spaces = 0
let g:autoformat_verbosemode=1
"ctrl+i
"noremap <C-i> :Autoformat<CR>
noremap <C-i> :call AutoFormat()<CR>
func! AutoFormat()
if &filetype == "markdown"
:TableModeEnable
else
:Autoformat
endif
endfunction
call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'vim-autoformat/vim-autoformat'
call plug#end()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""实用设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 设置当文件被改动时自动载入
set autoread
" quickfix模式
" autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr>
"代码补全
set completeopt=preview,menu
"允许插件
filetype plugin on
"共享剪贴板
set clipboard+=unnamed
"从不备份
set nobackup
"自动保存
set autowrite
set ruler " 打开状态栏标尺
" set cursorline " 突出显示当前行
set magic " 设置魔术
set guioptions-=T " 隐藏工具栏
set guioptions-=m " 隐藏菜单栏
set foldcolumn=0
set foldmethod=indent
set foldlevel=3
set foldenable " 开始折叠
" 不要使用vi的键盘模式,而是vim自己的
set nocompatible
" 语法高亮
set syntax=on
" 去掉输入错误的提示声音
set noeb
" 在处理未保存或只读文件的时候,弹出确认
set confirm
" 自动缩进
set autoindent
set cindent
" Tab键的宽度
set tabstop=2
" 统一缩进为4
set softtabstop=2
set shiftwidth=2
"禁止生成临时文件
set nobackup
set noswapfile
"搜索忽略大小写
set ignorecase
"搜索逐字符高亮
set hlsearch
set incsearch
"行内替换
set gdefault
"编码设置
set enc=utf-8
set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
"语言设置
set langmenu=zh_CN.UTF-8
set helplang=cn
" 我的状态行显示的内容(包括文件类型和解码)
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
"set statusline=[%F]%y%r%m%*%=[Line:%l/%L,Column:%c][%p%%]
"set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)\
" 总是显示状态行
set laststatus=2
" 命令行(在状态行下)的高度,默认为1,这里是2
set cmdheight=2
" 侦测文件类型
filetype on
" 载入文件类型插件
filetype plugin on
" 为特定文件类型载入相关缩进文件
filetype indent on
" 保存全局变量
set viminfo+=!
" 在被分割的窗口间显示空白,便于阅读
set fillchars=vert:\ ,stl:\ ,stlnc:\
" 高亮显示匹配的括号
set showmatch
" 匹配括号高亮的时间(单位是十分之一秒)
set matchtime=1
" 光标移动到buffer的顶部和底部时保持3行距离
set scrolloff=3
" 为C程序提供自动缩进
set smartindent
" 高亮显示普通txt文件(需要txt.vim脚本)
au BufRead,BufNewFile * setfiletype txt
"自动补全
":inoremap ( ()<ESC>i
":inoremap ) <c-r>=ClosePair(')')<CR>
":inoremap { {<CR>}<ESC>O
":inoremap } <c-r>=ClosePair('}')<CR>
":inoremap [ []<ESC>i
":inoremap ] <c-r>=ClosePair(']')<CR>
":inoremap " ""<ESC>i
":inoremap ' ''<ESC>i
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endfunction
filetype plugin indent on
"打开文件类型检测, 加了这句才可以用智能补全
set completeopt=longest,menu
"重命名文件
:command! -nargs=1 Rename let tpname = expand('%:t') | saveas <args> | edit <args> | call delete(expand(tpname))