Xinqi Bao's Git

e6cb7fd4bb198a61ff93a0257a091378eb45f621
[dotfiles.git] / .config / nvim / init.vim
1 syntax enable
2 let mapleader=" "
3
4 set background=dark
5 set termguicolors
6 set t_Co=256 "terminal color
7 set t_ut=""
8 "set term=xterm-256color
9
10 "In order to display chinese in GBK
11 "let &termencoding=&encoding
12 set fileencodings=utf-8,gbk
13 set fileformat=unix
14 set foldmethod=indent
15 set encoding=utf-8 "required for ycm
16
17 set tabstop=4
18 set softtabstop=4
19 set shiftwidth=4
20 set expandtab
21 set smartindent
22 set backspace=indent,eol,start
23
24 set number
25 set nowrap
26 set signcolumn=auto
27 set smartcase
28 set incsearch
29 set hlsearch
30 set ignorecase
31 set cursorline
32 set conceallevel=0
33 set showtabline=2
34 set laststatus=2 "always show status line
35 set noshowmode
36 set wildmenu
37
38 set mouse=a
39 set autochdir
40 set updatetime=300
41 set noerrorbells
42
43 " Turn backup off
44 set noswapfile
45 set nobackup
46 set nowritebackup
47 set undodir=~/.cache/nvim/undodir
48 set undofile
49
50 " auto added comment leader, detail for :h formatoptions
51 set formatoptions+=/ro
52
53 set tags=tags~;,tags~
54 "setting gf (go file) path
55 "change kernel version to your version, for kernel development
56 set path=.,lib;,include;,includes;
57 set path+=/usr/include,/usr/include/c++/*
58 set path+=/usr/local/include
59
60 "ColumnLimit
61 set colorcolumn=120
62 highlight ColorColumn ctermbg=0 guibg=lightgrey
63
64 " Writes to the unnamed register also writes to the * and + registers. This
65 " makes it easy to interact with the system clipboard
66 if has ('unnamedplus')
67 set clipboard=unnamedplus
68 else
69 set clipboard=unnamed
70 endif
71
72 call plug#begin()
73 Plug 'morhetz/gruvbox'
74 Plug 'Yggdroot/indentLine'
75 Plug 'christoomey/vim-tmux-navigator'
76 Plug 'vim-airline/vim-airline'
77
78 Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
79 Plug 'junegunn/fzf.vim'
80 Plug 'ludovicchabant/vim-gutentags'
81
82 Plug 'mbbill/undotree'
83 Plug 'preservim/nerdtree'
84 Plug 'majutsushi/tagbar'
85
86 Plug 'MeanderingProgrammer/render-markdown.nvim'
87 Plug 'plasticboy/vim-markdown'
88 Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && npx --yes yarn install' }
89
90 Plug 'tpope/vim-fugitive'
91 Plug 'airblade/vim-gitgutter'
92 Plug 'kdheepak/lazygit.nvim'
93
94 Plug 'neoclide/coc.nvim', {'branch': 'release'}
95
96 Plug 'nvim-treesitter/nvim-treesitter'
97
98 Plug 'zbirenbaum/copilot.lua'
99
100 " execute 'source' fnameescape(expand('<sfile>:p:h') . '/opt/avante.vim')
101
102 call plug#end()
103
104 "----------------------
105 " gruvbox setting
106 "----------------------
107 if has_key(plugs, 'gruvbox')
108 colorscheme gruvbox
109 endif
110
111 "----------------------
112 " vim-airline setting
113 "----------------------
114 if has_key(plugs, 'vim-airline')
115 "tabline with airline
116 ":help airline-tabline
117 let g:airline#extensions#tabline#enabled = 1
118 let g:airline#extensions#tabline#show_buffers = 0
119 let g:airline#extensions#tabline#show_splits = 0
120 let g:airline#extensions#tabline#show_tab_count = 0
121 let g:airline#extensions#tabline#show_close_button = 0
122 endif
123
124 "----------------------
125 " fzf.vim setting
126 "----------------------
127 if has_key(plugs, 'fzf.vim')
128 "mapping for fzf.vim
129 nnoremap <C-p> :GFiles<CR>
130 "as default <C-f>/<C-b> pair used to page down/up entire page
131 nnoremap <C-f> :Tags<CR>
132 endif
133
134 "----------------------
135 " undotree setting
136 "----------------------
137 if has_key(plugs, 'undotree')
138 nnoremap <leader>u :UndotreeToggle<CR>
139 endif
140
141 "----------------------
142 " nerdtree setting
143 "----------------------
144 if has_key(plugs, 'nerdtree')
145 autocmd StdinReadPre * let s:std_in=1
146 "when vim openning with no file, open NERDTree
147 autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
148 nnoremap <leader>n :NERDTreeToggle<CR>
149 endif
150
151 "----------------------
152 " tagbar setting
153 "----------------------
154 if has_key(plugs, 'tagbar')
155 nnoremap <leader>t :TagbarToggle<CR>
156 endif
157
158 "----------------------
159 " coc.vim setting
160 "----------------------
161 if has_key(plugs, "coc.nvim")
162 " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
163 nmap <silent> <leader>g[ <Plug>(coc-diagnostic-prev)
164 nmap <silent> <leader>g] <Plug>(coc-diagnostic-next)
165
166 " GoTo code navigation.
167 nmap <silent> <leader>gd <Plug>(coc-definition)
168 nmap <silent> <leader>gr <Plug>(coc-references)
169 nmap <silent> <leader>gy <Plug>(coc-type-definition)
170 nmap <silent> <leader>gi <Plug>(coc-implementation)
171
172 " Highlight the symbol and its references when holding the cursor.
173 autocmd CursorHold * silent call CocActionAsync('highlight')
174
175 " Symbol renaming.
176 nmap <leader>rn <Plug>(coc-rename)
177
178 " Formatting selected code.
179 xmap <leader>f <Plug>(coc-format-selected)
180 nmap <leader>f <Plug>(coc-format-selected)
181
182 " Apply AutoFix to problem on the current line.
183 nmap <leader>qf <Plug>(coc-fix-current)
184
185 " clangd
186 nmap <leader>gh :CocCommand clangd.switchSourceHeader<CR>
187
188 " Use K to show documentation in preview window.
189 nnoremap <silent> <leader>h :call <SID>show_documentation()<CR>
190 function! s:show_documentation()
191 if (index(['vim','help'], &filetype) >= 0)
192 execute 'h '.expand('<cword>')
193 elseif (coc#rpc#ready())
194 call CocActionAsync('doHover')
195 else
196 execute '!' . &keywordprg . " " . expand('<cword>')
197 endif
198 endfunction
199
200 let g:coc_default_semantic_highlight_groups = 1
201 let g:coc_global_extensions = [
202 \'coc-marketplace',
203 \'coc-highlight',
204 \'coc-clangd',
205 \'coc-pyright',
206 \'coc-lua',
207 \'coc-sh',
208 \'coc-cmake',
209 \'coc-xmake',
210 \'coc-json',
211 \'coc-yaml',
212 \'coc-vimlsp',
213 \]
214 endif
215
216 "----------------------
217 " nvim-treesitter setting
218 "----------------------
219 if has_key(plugs, 'nvim-treesitter')
220 lua require('plugin-config/nvim-treesitter')
221
222 "set foldmethod=expr
223 set foldmethod=indent
224 set foldexpr=nvim_treesitter#foldexpr()
225 set foldlevel=99
226 endif
227
228 "----------------------
229 " copilot.lua setting
230 "----------------------
231 if has_key(plugs, 'copilot.lua')
232 lua require('plugin-config/copilot')
233 endif
234
235 "----------------------
236 " avante.nvim setting
237 "----------------------
238 if has_key(plugs, 'avante.nvim')
239 lua require('plugin-config/avante')
240 endif
241
242 nnoremap J :tabprevious<CR>
243 nnoremap K :tabnext<CR>
244 nnoremap <leader>J :tabmove -1<CR>
245 nnoremap <leader>K :tabmove +1<CR>
246 nnoremap <C-h> <C-w>h
247 nnoremap <C-j> <C-w>j
248 nnoremap <C-k> <C-w>k
249 nnoremap <C-l> <C-w>l
250 nnoremap <leader>" viw<esc>a"<esc>bi"<esc>lel
251 nnoremap <leader>' viw<esc>a'<esc>bi'<esc>lel
252 nnoremap <silent> <Leader>+ :resize +5<CR>
253 nnoremap <silent> <Leader>- :resize -5<CR>
254 nnoremap <silent> <Leader>v+ :vertical resize +5<CR>
255 nnoremap <silent> <Leader>v- :vertical resize -5<CR>
256
257 " shortcut for folding
258 nnoremap <silent> <Leader>fi :set foldmethod=indent<CR>
259 nnoremap <silent> <Leader>fd :set foldmethod=manual<CR>ggVGzD
260
261 " 禁用 <C-a>
262 nnoremap <C-a> <Nop>
263 xnoremap <C-a> <Nop>
264
265 "HighLight trailing whitespace"
266 highlight ExtraWhitespace ctermbg=red guibg=red
267 match ExtraWhitespace /\s\+$/
268
269 "use powerline-vim for normal use
270 "instead of installing for both user and root
271 "run to install lib: pip3 install --user powerline-status
272 "python3 from powerline.vim import setup as powerline_setup
273 "python3 powerline_setup()
274 "python3 del powerline_setup