Advertisement
JulyRabbit

my vimrc

Jun 27th, 2024
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 6.34 KB | Source Code | 0 0
  1. " ----------------------
  2. " | PART ONE: 原版命令 |
  3. " ----------------------
  4.  
  5. " ======== 外 观 ========
  6. " 行号
  7. set number
  8. set relativenumber
  9.  
  10. " 状态栏,0 不显示,1 只在多窗口时显示,2 一直显示
  11. set laststatus=2
  12.  
  13. " 显示命令
  14. set showcmd
  15.  
  16. " 空白字符
  17. set list
  18. set listchars=eol:$,tab:>-,trail:X
  19.  
  20. " colorscheme
  21. syntax on
  22. " set t_Co=256
  23. set termguicolors
  24.  
  25. " ======== 显 示 ========
  26.  
  27. " 用于 coc.nvim
  28. " update
  29. set updatetime=300
  30. " lazyredraw
  31. set lazyredraw
  32.  
  33. " ======== 格 式 ========
  34.  
  35. " 编码
  36. set encoding=utf-8
  37.  
  38. " wrap
  39. set wrap
  40.  
  41. " 缩进
  42. set smartindent
  43. set tabstop=4
  44. " 使得缩进大小是 shiftwidth 的倍数
  45. set shiftround
  46. set shiftwidth=4
  47.  
  48. " ======== 搜 索 ========
  49.  
  50. set hlsearch
  51. set incsearch
  52. " 搜索到结尾时不回头
  53. set nowrapscan
  54. " set ignorecase
  55. set smartcase
  56. " S : do not use [x/x] when search
  57. set shortmess-=S
  58.  
  59. " ======== 文 件 ========
  60.  
  61. " 不创建备份文件和交换文件,理解原理后再设置回来
  62. set nobackup
  63. set swapfile
  64. set noundofile
  65.  
  66. " 多窗口下光标移动到其他窗口时自动切换工作目录
  67. set autochdir
  68.  
  69. " 文件自动检测外部更改
  70. set autoread
  71.  
  72. " ======== 命 令 ========
  73.  
  74. " 命令行模式
  75. set wildmenu
  76. set wildmode=longest,full
  77.  
  78. " ======== 其 他 ========
  79.  
  80. " 鼠标
  81. set mouse=a
  82.  
  83. " 输入括号时,会暂时跳转到匹配的括号
  84. " set showmatch
  85. " set matchtime=5
  86.  
  87. " 滚动
  88. set scrolloff=0
  89.  
  90. " 窗口
  91. " 新建的窗口会位于左下方
  92. set splitbelow
  93. set nosplitright
  94.  
  95. " 响铃
  96. set vb t_vb=
  97. au GuiEnter * set t_vb=
  98.  
  99. " 剪贴板
  100. set clipboard+=unnamed
  101.  
  102. " viewdir
  103. " set viewdir=
  104.  
  105. " ------------------
  106. " | PART TWO: 变量 |
  107. " ------------------
  108.  
  109. " ------------------------
  110. " | PART THREE: 按键映射 |
  111. " ------------------------
  112.  
  113. " ======== Leader ========
  114.  
  115. let mapleader="\<space>"
  116. let maplocalleader="\\"
  117.  
  118. " <leader> e? edit file
  119. " nnoremap <leader>en :vsplit ~/.vim/note<cr>
  120. nnoremap <leader>ev :vsplit $MYVIMRC<cr>
  121. " <leader> s? source file
  122. nnoremap <leader>sv :source $MYVIMRC<cr>
  123. " <leader> t? to workspace/project/folder
  124. " nnoremap <leader>tn :Vexplore /mnt/e/Note<cr>
  125. " nnoremap <leader>tn :Vexplore D:/Note<cr>
  126.  
  127. " buffer
  128. nnoremap <leader>bb :buffers<cr>:b<space>
  129. nnoremap <leader>bs :buffers<cr>:sb<space>
  130.  
  131. " window
  132. nnoremap <leader>w <c-w>
  133.  
  134. " highlight
  135. nnoremap <leader>h :set hlsearch!<cr>
  136.  
  137. " recent file
  138. nnoremap <leader>r :browse oldfiles<cr>
  139.  
  140. vnoremap <leader>c :w<space>!clip.exe<cr><cr>
  141.  
  142. " ======== 移 动 ========
  143.  
  144. noremap H 0
  145. noremap L $
  146. noremap gH g0
  147. noremap gL g$
  148.  
  149. " ======== 其 他 ========
  150.  
  151. " ESC 绑定
  152. inoremap jk <esc>
  153. " 禁用, 练习 jk 绑定
  154. inoremap <esc> <nop>
  155. inoremap <c-[> <nop>
  156. " 终端
  157. tnoremap jk <c-\><c-n>
  158.  
  159. " 括号自动补全
  160. " inoremap { {}<left>
  161. " inoremap { {<CR>}<Up><Enter>
  162. " noremap ( ()<Left>
  163. " noremap [ []<Left>
  164. " noremap " ""<Left>
  165. " noremap ' ''<Left>
  166.  
  167. " -------------------------
  168. " | PART FOUR: 自定义命令 |
  169. " -------------------------
  170.  
  171. " ======== Build with gcc ========
  172. command -nargs=? Bgcc :terminal ++rows=10 ++shell gcc % -o %:r <args>
  173. command -nargs=? Bgpp :terminal ++rows=10 ++shell g++ % -o %:r <args>
  174. " 原版: 不使用 terminal, 运行完成后才能返回编辑
  175. " command -nargs=? Bgcc :!clear; gcc % -o %:r <args>
  176. command -nargs=? Bclang :terminal ++rows=10 ++shell clang % -o %:r <args>
  177. command -nargs=? Bclangpp :terminal ++rows=10 ++shell clang++ % -o %:r <args>
  178.  
  179. " ======== Run current file ========
  180. " Can use "<test.in" to redirect input file
  181. " % 表示当前文件名, 修饰参数 :r 表示 root (移除一个扩展名). 可以 :h expand 查询具体用法
  182. " <args> 表示参数. 如果参数中带有特殊字符 (如 "), 用 <q-args> 可以在特殊字符前加反斜杠
  183. command -nargs=? R :terminal ++rows=10 ++shell ./%:r <args>
  184. " 原版: 不使用 terminal
  185. " command -nargs=? R :!clear; ./%:r <args>
  186.  
  187. " ======== markdown ========
  188. " TODO 移动到专门用于处理 markdown 的脚本文件
  189. " command MarkdownOutline :global/^#/#
  190.  
  191. " 定义一个函数,用于生成Markdown大纲
  192. function! MarkdownOutline(...)
  193.     " 检查参数的数量
  194.     if a:0 == 0
  195.         " 如果没有参数,显示所有层级的大纲
  196.         let l:minlevel = 1
  197.         let l:maxlevel = 6
  198.     elseif a:0 == 1
  199.         " 如果有一个参数,显示 1 到指定层级的大纲
  200.         let l:minlevel = 1
  201.         let l:maxlevel = a:1
  202.     elseif a:0 == 2
  203.         " 如果有两个参数,显示指定层级的大纲
  204.         let l:minlevel = a:1
  205.         let l:maxlevel = a:2
  206.     else
  207.         " 如果参数的数量不正确,显示错误消息
  208.         echoerr 'Invalid number of arguments'
  209.         return
  210.     endif
  211.  
  212.     " 使用正则表达式匹配指定层级的标题
  213.     " TODO '\v' 是垂直制表符
  214.     let l:pattern = '\v^' . repeat('#', l:minlevel) . '[#]{0,' . (l:maxlevel - l:minlevel) . '} '
  215.  
  216.     " 使用:global命令查找匹配的行
  217.     execute 'g/' . l:pattern
  218. endfunction
  219.  
  220. " 定义一个命令,用于显示Markdown大纲
  221. command! -nargs=* MarkdownOutline call MarkdownOutline(<f-args>)
  222.  
  223. command DiffWithSaved :w !diff --color % -
  224.  
  225. " -----------------------
  226. " | PART FIVE: 自动命令 |
  227. " -----------------------
  228.  
  229. " ======== filetype ========
  230. if has("autocmd")
  231.     autocmd  BufNewFile,Bufread *.g4 set filetype=pccts
  232.     autocmd  BufNewFile,Bufread *.p8 set filetype=lua
  233. endif
  234.  
  235. " ----------------------
  236. " | PART SIX: 内置插件 |
  237. " ----------------------
  238.  
  239. " ======== netrw tree ========
  240.  
  241. let g:netrw_banner=0 " 禁用没用的横幅
  242. " let g:netrw_winsize=25 " 初始窗口大小为25%
  243. " let g:netrw_liststyle=3 " 使用树状模式
  244. " let g:netrw_altv=1 " 分割窗口时默认在右边
  245. " let g:netrw_browse_split=4 " enter时在上一个窗口打开
  246.  
  247. " ======== markdown ========
  248.  
  249. set foldmethod=manual
  250. set foldcolumn=0
  251. " TODO highlight 选项的含义
  252. highlight Folded ctermbg = NONE
  253. highlight FoldColumn ctermbg = NONE
  254. let g:markdown_folding = 1
  255. let g:markdown_enable_folding = 1
  256. let g:markdown_fenced_languages = ['c', 'cpp', 'cmake', 'lua', 'bash']
  257.  
  258. " --------------------
  259. " | PART END: source |
  260. " --------------------
  261.  
  262. " execute project related configuration in current directory
  263. if filereadable(".vimrc.workspace")
  264.     source .vimrc.workspace
  265. endif
  266.  
  267. " other file to source (differs by each specific machine)
  268. source $HOME/.vim/.vimrc.tosource
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement