Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- " ----------------------
- " | PART ONE: 原版命令 |
- " ----------------------
- " ======== 外 观 ========
- " 行号
- set number
- set relativenumber
- " 状态栏,0 不显示,1 只在多窗口时显示,2 一直显示
- set laststatus=2
- " 显示命令
- set showcmd
- " 空白字符
- set list
- set listchars=eol:$,tab:>-,trail:X
- " colorscheme
- syntax on
- " set t_Co=256
- set termguicolors
- " ======== 显 示 ========
- " 用于 coc.nvim
- " update
- set updatetime=300
- " lazyredraw
- set lazyredraw
- " ======== 格 式 ========
- " 编码
- set encoding=utf-8
- " wrap
- set wrap
- " 缩进
- set smartindent
- set tabstop=4
- " 使得缩进大小是 shiftwidth 的倍数
- set shiftround
- set shiftwidth=4
- " ======== 搜 索 ========
- set hlsearch
- set incsearch
- " 搜索到结尾时不回头
- set nowrapscan
- " set ignorecase
- set smartcase
- " S : do not use [x/x] when search
- set shortmess-=S
- " ======== 文 件 ========
- " 不创建备份文件和交换文件,理解原理后再设置回来
- set nobackup
- set swapfile
- set noundofile
- " 多窗口下光标移动到其他窗口时自动切换工作目录
- set autochdir
- " 文件自动检测外部更改
- set autoread
- " ======== 命 令 ========
- " 命令行模式
- set wildmenu
- set wildmode=longest,full
- " ======== 其 他 ========
- " 鼠标
- set mouse=a
- " 输入括号时,会暂时跳转到匹配的括号
- " set showmatch
- " set matchtime=5
- " 滚动
- set scrolloff=0
- " 窗口
- " 新建的窗口会位于左下方
- set splitbelow
- set nosplitright
- " 响铃
- set vb t_vb=
- au GuiEnter * set t_vb=
- " 剪贴板
- set clipboard+=unnamed
- " viewdir
- " set viewdir=
- " ------------------
- " | PART TWO: 变量 |
- " ------------------
- " ------------------------
- " | PART THREE: 按键映射 |
- " ------------------------
- " ======== Leader ========
- let mapleader="\<space>"
- let maplocalleader="\\"
- " <leader> e? edit file
- " nnoremap <leader>en :vsplit ~/.vim/note<cr>
- nnoremap <leader>ev :vsplit $MYVIMRC<cr>
- " <leader> s? source file
- nnoremap <leader>sv :source $MYVIMRC<cr>
- " <leader> t? to workspace/project/folder
- " nnoremap <leader>tn :Vexplore /mnt/e/Note<cr>
- " nnoremap <leader>tn :Vexplore D:/Note<cr>
- " buffer
- nnoremap <leader>bb :buffers<cr>:b<space>
- nnoremap <leader>bs :buffers<cr>:sb<space>
- " window
- nnoremap <leader>w <c-w>
- " highlight
- nnoremap <leader>h :set hlsearch!<cr>
- " recent file
- nnoremap <leader>r :browse oldfiles<cr>
- vnoremap <leader>c :w<space>!clip.exe<cr><cr>
- " ======== 移 动 ========
- noremap H 0
- noremap L $
- noremap gH g0
- noremap gL g$
- " ======== 其 他 ========
- " ESC 绑定
- inoremap jk <esc>
- " 禁用, 练习 jk 绑定
- inoremap <esc> <nop>
- inoremap <c-[> <nop>
- " 终端
- tnoremap jk <c-\><c-n>
- " 括号自动补全
- " inoremap { {}<left>
- " inoremap { {<CR>}<Up><Enter>
- " noremap ( ()<Left>
- " noremap [ []<Left>
- " noremap " ""<Left>
- " noremap ' ''<Left>
- " -------------------------
- " | PART FOUR: 自定义命令 |
- " -------------------------
- " ======== Build with gcc ========
- command -nargs=? Bgcc :terminal ++rows=10 ++shell gcc % -o %:r <args>
- command -nargs=? Bgpp :terminal ++rows=10 ++shell g++ % -o %:r <args>
- " 原版: 不使用 terminal, 运行完成后才能返回编辑
- " command -nargs=? Bgcc :!clear; gcc % -o %:r <args>
- command -nargs=? Bclang :terminal ++rows=10 ++shell clang % -o %:r <args>
- command -nargs=? Bclangpp :terminal ++rows=10 ++shell clang++ % -o %:r <args>
- " ======== Run current file ========
- " Can use "<test.in" to redirect input file
- " % 表示当前文件名, 修饰参数 :r 表示 root (移除一个扩展名). 可以 :h expand 查询具体用法
- " <args> 表示参数. 如果参数中带有特殊字符 (如 "), 用 <q-args> 可以在特殊字符前加反斜杠
- command -nargs=? R :terminal ++rows=10 ++shell ./%:r <args>
- " 原版: 不使用 terminal
- " command -nargs=? R :!clear; ./%:r <args>
- " ======== markdown ========
- " TODO 移动到专门用于处理 markdown 的脚本文件
- " command MarkdownOutline :global/^#/#
- " 定义一个函数,用于生成Markdown大纲
- function! MarkdownOutline(...)
- " 检查参数的数量
- if a:0 == 0
- " 如果没有参数,显示所有层级的大纲
- let l:minlevel = 1
- let l:maxlevel = 6
- elseif a:0 == 1
- " 如果有一个参数,显示 1 到指定层级的大纲
- let l:minlevel = 1
- let l:maxlevel = a:1
- elseif a:0 == 2
- " 如果有两个参数,显示指定层级的大纲
- let l:minlevel = a:1
- let l:maxlevel = a:2
- else
- " 如果参数的数量不正确,显示错误消息
- echoerr 'Invalid number of arguments'
- return
- endif
- " 使用正则表达式匹配指定层级的标题
- " TODO '\v' 是垂直制表符
- let l:pattern = '\v^' . repeat('#', l:minlevel) . '[#]{0,' . (l:maxlevel - l:minlevel) . '} '
- " 使用:global命令查找匹配的行
- execute 'g/' . l:pattern
- endfunction
- " 定义一个命令,用于显示Markdown大纲
- command! -nargs=* MarkdownOutline call MarkdownOutline(<f-args>)
- command DiffWithSaved :w !diff --color % -
- " -----------------------
- " | PART FIVE: 自动命令 |
- " -----------------------
- " ======== filetype ========
- if has("autocmd")
- autocmd BufNewFile,Bufread *.g4 set filetype=pccts
- autocmd BufNewFile,Bufread *.p8 set filetype=lua
- endif
- " ----------------------
- " | PART SIX: 内置插件 |
- " ----------------------
- " ======== netrw tree ========
- let g:netrw_banner=0 " 禁用没用的横幅
- " let g:netrw_winsize=25 " 初始窗口大小为25%
- " let g:netrw_liststyle=3 " 使用树状模式
- " let g:netrw_altv=1 " 分割窗口时默认在右边
- " let g:netrw_browse_split=4 " enter时在上一个窗口打开
- " ======== markdown ========
- set foldmethod=manual
- set foldcolumn=0
- " TODO highlight 选项的含义
- highlight Folded ctermbg = NONE
- highlight FoldColumn ctermbg = NONE
- let g:markdown_folding = 1
- let g:markdown_enable_folding = 1
- let g:markdown_fenced_languages = ['c', 'cpp', 'cmake', 'lua', 'bash']
- " --------------------
- " | PART END: source |
- " --------------------
- " execute project related configuration in current directory
- if filereadable(".vimrc.workspace")
- source .vimrc.workspace
- endif
- " other file to source (differs by each specific machine)
- source $HOME/.vim/.vimrc.tosource
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement