Skip to content

Instantly share code, notes, and snippets.

@WuJunkai2004
Last active May 3, 2026 17:05
Show Gist options
  • Select an option

  • Save WuJunkai2004/3956a5e2a4f0b5bc4680e962d89a2bcc to your computer and use it in GitHub Desktop.

Select an option

Save WuJunkai2004/3956a5e2a4f0b5bc4680e962d89a2bcc to your computer and use it in GitHub Desktop.
a vim configure of WuJunkai2004
" modified: 2026/05/03
" map leader as ,
let mapleader=","
" for the normal mode of chinese input
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030
" the number of the line
set number
set hidden
set mouse=a
set cursorline
set modeline
set nofixeol
hi CursorLine cterm=NONE ctermbg=darkgrey
set guicursor=n-i:ver25,v-sm-r-c:block
" change the windows
nnoremap <C-p> <C-w><C-w>
" auto insert mode
function g:Auto_ins() abort
if col('.') == col('$')-1
call feedkeys('a', 'n')
else
call feedkeys('i', 'n')
endif
endfunction
" the move keys IJKL
inoremap jj <Esc>
inoremap JJ <Esc>
nnoremap j h
nnoremap i k
nnoremap k j
nnoremap <Space><Space> :call g:Auto_ins()<cr>
vnoremap j h
vnoremap i k
vnoremap k j
" just use microssoft's shortcut
source $VIMRUNTIME/mswin.vim
if !has("clipboard")
vnoremap <C-x> +d
endif
inoremap <C-s> <Esc>:w<cr>
if has('linux')
nnoremap <C-q> :AsyncRun -mode=term -close -rows=12 bash<cr>
else
if executable('pwsh')
nnoremap <C-q> :AsyncRun -mode=term -close -rows=12 pwsh<cr>
elseif executable('powershell')
nnoremap <C-q> :AsyncRun -mode=term -close -rows=12 powershell<cr>
endif
endif
" Auto close the buffer
autocmd Bufenter * if ( len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1 ) | nnoremap <C-w> :q<cr> | else | nnoremap <C-w> :bw<cr> | endif
" delete the useless shortcut
nnoremap w <Nop>
nnoremap W <Nop>
nnoremap s <Nop>
nnoremap S <Nop>
nnoremap dd <Nop>
nnoremap dw <Nop>
nnoremap o <Nop>
nnoremap p <Nop>
nnoremap u <Nop>
" use some shortcut by a safer way
nnoremap ddd dd
" load pluggins
call plug#begin('~/.vim/plugged')
" the bar which is in top and buttom
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
let g:airline#extensions#tabline#enabled=1
let g:airline#extensions#tabline#buffer_nr_show=0
let g:airline#extensions#tabline#left_sep=' '
let g:airline#extensions#tabline#left_alt_sep='|'
let g:airline#extensions#tabline#formatter='unique_tail'
let g:airline#extensions#whitespace#enabled=0
let g:airline_section_z='(%l,%c) - %L*%2p%%'
" the visible of the space and tab
set tabstop=4
set shiftwidth=4
set expandtab
Plug 'WuJunkai2004/indentline'
" the paired parentheses
let g:AutoPairsMapBS = 0
Plug 'jiangmiao/auto-pairs'
Plug 'luochen1990/rainbow'
let g:rainbow_active = 1 "set to 0 if you want to enable it later via :RainbowToggle:
let g:rainbow_conf = {
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'],
\ 'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'],
\ 'operators': '_,_',
\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
\ 'separately': {
\ '*': {},
\ 'tex': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
\ },
\ 'lisp': {
\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'],
\ },
\ 'vim': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
\ },
\ 'html': {
\ 'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#</\z1># fold'],
\ },
\ 'css': 0,
\ 'nerdtree': 0,
\ }
\}
" the file tree
Plug 'scrooloose/nerdtree'
nnoremap <F3> :NERDTreeToggle<CR>
"打开vim时如果没有文件自动打开NERDTree
autocmd vimenter * if !argc()|NERDTree|endif
"当NERDTree为剩下的唯一窗口时自动关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
"set the icon of the tree
let g:NERDTreeDirArrowExpandable = ''
let g:NERDTreeDirArrowCollapsible = ''
" ignore some types of files
let NERDTreeIgnore = ['\.pyc$', '\.swp', '\.swo', '\.vscode', '__pycache__']
let g:NERDTreeShowLineNumbers=0 " 是否显示行号
let g:NERDTreeHidden=0 " 不显示隐藏文件
let NERDTreeQuitOnOpen=1 " 打开文件后自动关闭NERDTree
" code runner
let g:asynctasks_term_pos = 'bottom'
let g:asynctasks_term_rows = 8
Plug 'skywind3000/asyncrun.vim'
Plug 'skywind3000/asynctasks.vim'
nnoremap <C-r> :AsyncTask file-run<cr>
inoremap <C-r> <Esc>:w<cr>:AsyncTask file-run<cr>
" use AI to help coding
if v:version >= 900
if has("linux") && executable('node')
Plug 'github/copilot.vim'
endif
if executable('python') || executable('python3')
Plug 'WuJunkai2004/copylot.vim'
nnoremap <F2> :call copylot#chat#toggle()<cr>
endif
else
Plug 'ervandew/supertab', { 'commit': 'a9dab76' }
endif
" the Git integration
Plug 'airblade/vim-gitgutter'
highlight GitGutterAdd guifg=green ctermfg=green
highlight GitGutterChange guifg=yellow ctermfg=yellow
highlight GitGutterDelete guifg=red ctermfg=red
let g:gitgutter_sign_added = '+'
let g:gitgutter_sign_modified = '~'
let g:gitgutter_sign_removed = '-'
let g:gitgutter_sign_removed_first_line = '^'
let g:gitgutter_sign_removed_above_and_below = '-'
let g:gitgutter_sign_modified_removed = '~'
" the better search and replace
set hlsearch
set incsearch
set ignorecase
set smartcase
Plug 'romainl/vim-cool'
Plug 'PeterRincker/vim-searchlight'
" better buffer changed
let g:airline#extensions#tabline#fnametruncate=16
let g:airline#extensions#tabline#fnamecollapse=2
let g:airline#extensions#tabline#buffer_idx_mode=1
let g:cj_lsp_debug = 1
let g:CJ_lsp_auto_format_on_save = 1
Plug 'https://gitcode.com/Neila/cangjie.vim.git'
function g:Buf_switch(num) abort
let l:buf_goal=a:num
let l:buf_index=a:num
let l:buf_list=filter(range(1, bufnr('$')), 'buflisted(v:val)')
for idx in range(len(l:buf_list))
if getbufvar(l:buf_list[idx], '&buftype') ==# 'quickfix'
call remove(l:buf_list, idx)
break
endif
endfor
let l:buf_count=len(l:buf_list)
if a:num > l:buf_count
return
endif
execute ':b'.l:buf_list[l:buf_goal-1]
endfunction
nnoremap <leader>1 :call g:Buf_switch(1)<cr>
nnoremap <leader>2 :call g:Buf_switch(2)<cr>
nnoremap <leader>3 :call g:Buf_switch(3)<cr>
nnoremap <leader>4 :call g:Buf_switch(4)<cr>
nnoremap <leader>5 :call g:Buf_switch(5)<cr>
nnoremap <leader>6 :call g:Buf_switch(6)<cr>
nnoremap <leader>7 :call g:Buf_switch(7)<cr>
nnoremap <leader>8 :call g:Buf_switch(8)<cr>
nnoremap <leader>9 :call g:Buf_switch(9)<cr>
nnoremap <leader>0 :call g:Buf_switch(10)<cr>
function g:Upgrade(url, goal, min_line) abort
let l:file_temp = tempname()
let l:curl_cmd = 'curl '.a:url.' -o '.l:file_temp
call system(l:curl_cmd)
if !filereadable(l:file_temp)
echom "Failed to download the file. Please check your internet connection."
return 1
endif
let l:file_content = readfile(l:file_temp)
if len(l:file_content) < a:min_line
echom "The downloaded file seems to be empty or too short. Please check the URL."
return 1
endif
let l:file_path = expand(a:goal)
if filereadable(l:file_path)
call delete(l:file_path)
call rename(l:file_temp, l:file_path)
else
call rename(l:file_temp, l:file_path)
endif
echom "Download " . l:file_path . " successfully"
return 0
endfunction
function! g:UpgradeAll() abort
if !executable('curl')
echo "curl is not installed. Please install it to upgrade your vimrc."
return
endif
call g:Upgrade('https://gist.githubusercontent.com/WuJunkai2004/3956a5e2a4f0b5bc4680e962d89a2bcc/raw/.vimrc',
\ '~/.vimrc', 50)
call g:Upgrade('https://gist.githubusercontent.com/WuJunkai2004/eb05dfe041eb584049b5bfa1ec64668f/raw/task.ini',
\ '~/.vim/tasks.ini', 5)
endfunction
command! Rconfig call g:UpgradeAll()
call plug#end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment