Initial commit

This commit is contained in:
2025-06-05 13:35:52 +08:00
commit 9a8e04f76c
5 changed files with 607 additions and 0 deletions

344
vimrc Normal file
View File

@ -0,0 +1,344 @@
colorscheme vim
highlight Normal guifg=1 guibg=0
syntax on
set bg=dark
set termguicolors
set nocp
set ttyfast
set guifont=ConsolasDengXianSemiBold\ 14
set backspace=2
set showmatch
set ruler
set mouse=a
set ts=4
set sw=4
set cindent
set cinoptions=:0,l1,g0
set nohlsearch
set ignorecase
set smartcase
set autochdir
set timeout timeoutlen=1000 ttimeoutlen=15
set title
set scroll=8
set guicursor=a:blinkon0-Cursor
let g:netrw_mousemaps=0
set nu
set signcolumn=no
set updatetime=1000
"""""""""" Plugins """"""""""
set nocp
filetype plugin on
call plug#begin('~/.vim/plugged')
let g:plug_url_format='git@github.com:%s.git'
Plug 'tpope/vim-repeat'
Plug 'Chiel92/vim-autoformat'
Plug 'tpope/vim-surround'
Plug 'elkowar/yuck.vim'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'vim-airline/vim-airline'
call plug#end()
"""""""""" Syntax highlighting overrides """"""""""
highlight LineNr ctermfg=lightgrey guifg=#7f7f7f gui=NONE
"highlight PmenuSel ctermbg=242 ctermfg=white guibg=#6f6f6f guifg=#ffffff
highlight! Pmenu ctermbg=252 ctermfg=black guibg=#d7d7d7 guifg=#000000 gui=NONE
highlight! PmenuSel guibg=#d7d7d7 guifg=#000000 gui=NONE
highlight! Pmenu guibg=#7f002f guifg=#ffffff gui=NONE
highlight Comment ctermfg=87 guifg=#00ffff gui=NONE
highlight Constant ctermfg=213 guifg=#ffcfff gui=NONE
highlight String ctermfg=207 guifg=#ff5fff gui=NONE
highlight Character ctermfg=213 guifg=#ff9fff gui=NONE
highlight Number ctermfg=123 guifg=#87ffff gui=NONE
highlight! link Boolean Number
highlight Identifier ctermfg=49 guifg=#cfffff gui=NONE
highlight Function ctermfg=49 guifg=#00ffaf
highlight Statement ctermfg=227 guifg=#ffff8f gui=NONE
highlight! link Repeat Statement
highlight! link Label Statement
highlight! link Operator Statement
highlight! link Keyword Statement
highlight! link Exception Statement
highlight Type ctermfg=121 guifg=#87ffaf gui=NONE
highlight! link StorageClass Type
highlight! link Structure Type
highlight! link Typedef Type
highlight Special guifg=#ffd7d7 gui=NONE
highlight! link SpecialChar Special
highlight! link Tag Special
highlight! link Delimiter Special
highlight! link SpecialComment Special
highlight! link Debug Special
highlight MatchParen guibg=#00ffff guifg=#000000
highlight Underlined guifg=#5fd7ff
highlight TabLineFill cterm=None gui=None guibg=White guifg=Black
highlight TabLine cterm=None gui=None guibg=White guifg=Black
highlight TabLineSel cterm=None gui=None guibg=Black guifg=White
highlight glslBuiltinFunction guifg=#ffc7c7 gui=NONE
highlight Cursor gui=NONE guibg=White guifg=Black
highlight CocInlayHint guibg=#3f3f3f guifg=White gui=NONE
highlight Conceal guibg=#3f3f3f guifg=white gui=NONE
highlight StatusLine cterm=NONE gui=NONE
highlight StatusLineNC cterm=NONE gui=NONE
highlight StatusLineTerm cterm=NONE gui=NONE
highlight StatusLineTermNC cterm=NONE gui=NONE
"""""""""" Tabline """"""""""
" https://stackoverflow.com/a/20235008
function MyTabLine()
let s = ''
for i in range(tabpagenr('$'))
" select the highlighting
if i + 1 == tabpagenr()
let s .= '%#TabLineSel#'
else
let s .= '%#TabLine#'
endif
" set the tab page number (for mouse clicks)
let s .= '%' . (i + 1) . 'T'
" the label is made by MyTabLabel()
let s .= ' %{MyTabLabel(' . (i + 1) . ')} '
endfor
" after the last tab fill with TabLineFill and reset tab page nr
let s .= '%#TabLineFill#%T'
" right-align the label to close the current tab page
if tabpagenr('$') > 1
let s .= '%=%#TabLine#%999XClose'
endif
return s
endfunction
function MyTabLabel(n)
let buflist = tabpagebuflist(a:n)
let winnr = tabpagewinnr(a:n)
let name = bufname(buflist[winnr - 1])
if name == ""
return "[未命名]"
else
let pathparts = split(name, '/')
if len(pathparts) == 1
return name
else
"return pathparts[len(pathparts) - 2] . '/' . pathparts[len(pathparts) - 1]
return pathparts[len(pathparts) - 1]
endif
endif
endfunction
"set tabline=%!MyTabLine()
"""""""""" Remaps """"""""""
command W w
map Q ZZ
func Semicolon()
let line = getline('.')
if match(line, "for") == -1 && match(line, "if") == -1
return "\<End>;"
else
return ';'
endif
endfunc
au BufNewFile,BufRead *.frag,*.vert,*.geom,*.fp,*.vp,*.glsl setf glsl
augroup vimrc_cmaps
autocmd FileType c,cpp,rust,typescript inoremap <buffer><expr> ; Semicolon()
autocmd FileType vim,c,cpp,go,rust,python,typescript,tex inoremap <buffer> ( ()<Left>
autocmd FileType vim,c,cpp,go,rust,python,typescript,tex inoremap <buffer> [ []<Left>
autocmd FileType vim,c,cpp,go,rust,python,typescript inoremap <buffer> " ""<Left>
autocmd FileType vim,c,cpp,go,rust,python,typescript inoremap <buffer> ' ''<Left>
autocmd FileType c,cpp,go,rust,typescript inoremap <buffer> { <End>{<CR>}<Up><End><CR>
autocmd FileType c,cpp,go,rust,typescript inoremap <buffer> <C-]> {}<Left>
autocmd FileType vim,tex,python inoremap <buffer> { {}<Left>
autocmd FileType vim,tex,python inoremap <buffer> <C-]> <End>{<CR>}<Up><End><CR>
autocmd Filetype go,rust,python,typescript map <buffer><silent><expr> K CocAction("jumpDefinition")
autocmd FileType c,cpp map <buffer><silent><expr> K CocAction("jumpDeclaration")
autocmd FileType c,cpp map <buffer><silent><expr> <C-K> CocAction("jumpDefinition")
augroup END
let g:python3_host_prog="/usr/bin/python3"
autocmd BufWrite *.cpp,*.c,*.hpp,*.h,*.go,*.rs,*.py Autoformat
"autocmd BufWrite *.go Autoformat
let g:formatdef_autopep8_120ll = '"autopep8 --max-line-length 120 -"'
let g:formatters_python = ['autopep8_120ll']
autocmd TermOpen * startinsert
" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
inoremap <silent><expr> <NUL> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" Press Meta-I to invoke hover
nmap <silent> <Tab> :call CocAction('doHover')<CR>
"nmap <silent><expr> <C-I> CocAction('doHover')
" Use tab for trigger completion / cycle snippet replaces.
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#_select_confirm() :
\ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
\ CheckBackSpace() ? "\<TAB>" :
\ coc#refresh()
function! CheckBackSpace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
let g:coc_snippet_next = '<tab>'
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" GoTo code navigation
nmap <silent> gd :call CocAction("jumpDefinition", v:false)<CR>
nmap <silent> gy :call CocAction("jumpTypeDefinition", v:false)<CR>
nmap <silent> gi :call CocAction("jumpImplementation", v:false)<CR>
nmap <silent> gr :call CocAction("jumpUsed", v:false)<CR>
nmap <silent> gn :e .<CR>
nunmap gri
nunmap grr
nunmap gra
nunmap grn
" Custom list invocation
"let g:coc_enable_locationlist = 0
"autocmd User CocLocationsChange CocList --normal --auto-preview location
" Use Meta-HJKL for Left/Down/Up/Right.
imap <M-H> <Left>
imap <M-J> <Down>
imap <M-K> <Up>
imap <M-L> <Right>
"""""""""" Airline Colors """"""""""
let g:go_highlight_trailing_whitespace_error = 0
set showcmd
let g:airline_mode_map={'s': '选择', 'V': '可视 行', 'ni': '(插入)', 'ic': '补全', 'R': '替换', '': '选择 块', 'no': '等待', '': '可视 块', 'multi': '复合', '__': '------', 'Rv': '可视 替换', 'c': '命令', 'ix': '补全', 'i': '插入', 'n': '正常', 'S': '选择 行', 't': '终端', 'v': '可视'}
let g:airline_section_z='共%L行 %4l行%3v列 %3p%%'
let g:airline_symbols={'space': ' ', 'paste': '粘贴', 'maxlinenr': 'Ln', 'dirty': '!', 'crypt': '加密', 'linenr': 'Cln', 'readonly': '[只读]', 'spell': '拼写', 'modified': '*', 'notexists': '不存在', 'keymap': 'Keymap:', 'ellipsis': '...', 'branch': '分支', 'whitespace': '空格', 'executable': '+x'}
let g:airline#extensions#whitespace#enabled = 0
let g:airline#extensions#whitespace#trailing_format='[%s] 行尾冗余'
let g:airline#extensions#whitespace#mixed_indent_format='[%s] 缩进格式不一致'
let g:airline#extensions#whitespace#long_format='[%s] 行过长'
let g:airline#extensions#whitespace#mixed_indent_file_format='[%s] 缩进格式不一致'
let g:airline#extensions#whitespace#conflicts_format='[%s] 格式冲突'
" Just disable it. Not working in CJK environment.
let g:airline#extensions#wordcount#enabled = 0
let g:airline#extensions#wordcount#formatter#default#fmt='%s 单词'
let g:airline#extensions#wordcount#formatter#default#fmt_short='%s词:'
let g:airline_filetype_overrides = {
\ 'defx': ['defx', '%{b:defx.paths[0]}'],
\ 'gundo': [ 'Gundo', '' ],
\ 'help': [ '帮助', '%f' ],
\ 'minibufexpl': [ 'MiniBufExplorer', '' ],
\ 'nerdtree': [ get(g:, 'NERDTreeStatusline', 'NERD'), '' ],
\ 'startify': [ 'startify', '' ],
\ 'vim-plug': [ '插件', '' ],
\ 'vimfiler': [ 'vimfiler', '%{vimfiler#get_status_string()}' ],
\ 'vimshell': ['vimshell','%{vimshell#get_status_string()}'],
\ }
"source ~/.vim/plugged/vim-airline/autoload/airline/themes/dark-ext.vim
let g:airline#themes#dark#palette.normal_modified = g:airline#themes#dark#palette.normal
let g:airline#themes#dark#palette.insert_modified = g:airline#themes#dark#palette.insert
let g:airline#themes#dark#palette.replace_modified = g:airline#themes#dark#palette.insert_modified
let g:airline#themes#dark#palette.visual_modified = g:airline#themes#dark#palette.visual
"
" For commandline mode, we use the colors from normal mode, except the mode
" indicator should be colored differently, e.g. light green
let s:airline_a_commandline = [ '#00005f' , '#0cff00' , 17 , 40 ]
let s:airline_b_commandline = [ '#ffffff' , '#444444' , 255 , 238 ]
let s:airline_c_commandline = [ '#9cffd3' , '#202020' , 85 , 234 ]
let g:airline#themes#dark#palette.commandline = airline#themes#generate_color_map(s:airline_a_commandline, s:airline_b_commandline, s:airline_c_commandline)
"""""""""" Misc """"""""""
set tags+=~/.cache/ctags
lang zh_CN.UTF-8
" Uncomment the following to have Vim jump to the last position when
" reopening a file
au BufReadPost * exe "normal! g'\""
set noshowmode
set termguicolors
set t_8f=[38:2::%lu:%lu:%lum
set t_8b=[48:2::%lu:%lu:%lum
command -nargs=* C !g++ %:p <Args>
command -nargs=* CR rightb 15split +term\ g++\ <Args>\ %:p\ &&\ ./a.out
command R rightb 15split +term\ ./a.out
function MyCDB(file)
tabe '+term g++ -g '. file .' && gdbtui ./a.out'
endfunction
command CDB call MyCDB( %:p )