4 " Files and indentation
6 " In order to display Chinese in GBK
7 set fileencodings=utf-8,gbk
14 set backspace=indent,eol,start
15 " Auto added comment leader; see :h formatoptions
16 set formatoptions+=/ro
31 set laststatus=2 "always show status line
35 highlight ColorColumn ctermbg=0 guibg=lightgrey
36 " Fallback for filetypes without a Tree-sitter parser.
41 " Interaction and persistence
51 set undodir=~/.cache/nvim/undodir
54 " Writes to the unnamed register also writes to the * and + registers. This
55 " makes it easy to interact with the system clipboard
56 if has ('unnamedplus')
57 set clipboard=unnamedplus
64 "setting gf (go file) path
65 "change kernel version to your version, for kernel development
66 set path=.,lib;,include;,includes;
67 set path+=/usr/include,/usr/include/c++/*
68 set path+=/usr/local/include
72 Plug 'morhetz/gruvbox'
73 Plug 'vim-airline/vim-airline'
74 Plug 'lukas-reineke/indent-blankline.nvim'
77 Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
78 Plug 'junegunn/fzf.vim'
79 Plug 'preservim/nerdtree'
80 Plug 'christoomey/vim-tmux-navigator'
81 Plug 'mbbill/undotree'
82 Plug 'majutsushi/tagbar'
83 Plug 'ludovicchabant/vim-gutentags'
86 Plug 'nvim-treesitter/nvim-treesitter'
87 Plug 'neoclide/coc.nvim', {'branch': 'release'}
88 Plug 'zbirenbaum/copilot.lua'
91 Plug 'tpope/vim-fugitive'
92 Plug 'lewis6991/gitsigns.nvim'
93 Plug 'kdheepak/lazygit.nvim'
96 Plug 'MeanderingProgrammer/render-markdown.nvim'
97 Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && npx --yes yarn install' }
100 " execute 'source' fnameescape(expand('<sfile>:p:h') . '/opt/avante.vim')
101 " execute 'source' fnameescape(expand('<sfile>:p:h') . '/opt/leetcode.vim')
106 if has_key(plugs, 'gruvbox')
110 if has_key(plugs, 'vim-airline')
111 "tabline with airline
112 ":help airline-tabline
113 let g:airline#extensions#tabline#enabled = 1
114 let g:airline#extensions#tabline#show_buffers = 0
115 let g:airline#extensions#tabline#show_splits = 0
116 let g:airline#extensions#tabline#show_tab_count = 0
117 let g:airline#extensions#tabline#show_close_button = 0
120 if has_key(plugs, 'indent-blankline.nvim')
121 lua require('ibl').setup()
125 if has_key(plugs, 'fzf.vim')
126 command! -bang -nargs=* GGrep
128 \ 'git grep --line-number -- ' . fzf#shellescape(<q-args>),
129 \ fzf#vim#with_preview({
130 \ 'dir': systemlist(['git', '-C', expand('%:p:h'), 'rev-parse', '--show-toplevel'])[0]
132 nnoremap <C-p> :GFiles<CR>
133 nnoremap <C-f> :GGrep<CR>
136 if has_key(plugs, 'nerdtree')
137 autocmd StdinReadPre * let s:std_in=1
138 "when vim openning with no file, open NERDTree
139 autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
140 nnoremap <leader>n :NERDTreeToggle<CR>
143 if has_key(plugs, 'undotree')
144 nnoremap <leader>u :UndotreeToggle<CR>
147 if has_key(plugs, 'tagbar')
148 nnoremap <leader>t :TagbarToggle<CR>
152 if has_key(plugs, 'nvim-treesitter')
153 lua require('plugin-config/nvim-treesitter')
156 if has_key(plugs, "coc.nvim")
157 " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
158 nmap <silent> <leader>g[ <Plug>(coc-diagnostic-prev)
159 nmap <silent> <leader>g] <Plug>(coc-diagnostic-next)
161 " GoTo code navigation.
162 nmap <silent> <leader>gd <Plug>(coc-definition)
163 nmap <silent> <leader>gr <Plug>(coc-references)
164 nmap <silent> <leader>gy <Plug>(coc-type-definition)
165 nmap <silent> <leader>gi <Plug>(coc-implementation)
167 " Highlight the symbol and its references when holding the cursor.
168 autocmd CursorHold * silent call CocActionAsync('highlight')
171 nmap <leader>rn <Plug>(coc-rename)
173 " Formatting selected code.
174 xmap <leader>f <Plug>(coc-format-selected)
175 nmap <leader>f <Plug>(coc-format-selected)
177 " Apply AutoFix to problem on the current line.
178 nmap <leader>qf <Plug>(coc-fix-current)
181 nmap <leader>gh :CocCommand clangd.switchSourceHeader<CR>
183 " Use K to show documentation in preview window.
184 nnoremap <silent> <leader>h :call <SID>show_documentation()<CR>
185 function! s:show_documentation()
186 if (index(['vim','help'], &filetype) >= 0)
187 execute 'h '.expand('<cword>')
188 elseif (coc#rpc#ready())
189 call CocActionAsync('doHover')
191 execute '!' . &keywordprg . " " . expand('<cword>')
195 let g:coc_default_semantic_highlight_groups = 1
196 let g:coc_global_extensions = [
211 if has_key(plugs, 'copilot.lua')
212 lua require('plugin-config/copilot')
216 if has_key(plugs, 'gitsigns.nvim')
217 lua require('plugin-config/gitsigns')
220 if has_key(plugs, 'lazygit.nvim')
221 nnoremap <silent> <leader>lg :LazyGit<CR>
225 if has_key(plugs, 'avante.nvim')
226 lua require('plugin-config/avante')
229 if has_key(plugs, 'leetcode.nvim')
230 lua require('plugin-config/leetcode')
234 nnoremap J :tabprevious<CR>
235 nnoremap K :tabnext<CR>
236 nnoremap <leader>J :tabmove -1<CR>
237 nnoremap <leader>K :tabmove +1<CR>
238 nnoremap <leader>" viw<esc>a"<esc>bi"<esc>lel
239 nnoremap <leader>' viw<esc>a'<esc>bi'<esc>lel
240 nnoremap <silent> <Leader>+ :resize +5<CR>
241 nnoremap <silent> <Leader>- :resize -5<CR>
242 nnoremap <silent> <Leader>v+ :vertical resize +5<CR>
243 nnoremap <silent> <Leader>v- :vertical resize -5<CR>
249 "HighLight trailing whitespace"
250 highlight ExtraWhitespace ctermbg=red guibg=red
251 match ExtraWhitespace /\s\+$/