syntax enable let mapleader=" " " Files and indentation set encoding=utf-8 " In order to display Chinese in GBK set fileencodings=utf-8,gbk set fileformat=unix set tabstop=4 set softtabstop=4 set shiftwidth=4 set expandtab set smartindent set backspace=indent,eol,start " Auto added comment leader; see :h formatoptions set formatoptions+=/ro " Display and search set background=dark set termguicolors set number set nowrap set signcolumn=auto set smartcase set incsearch set hlsearch set ignorecase set cursorline set conceallevel=0 set showtabline=2 set laststatus=2 "always show status line set noshowmode set wildmenu set colorcolumn=120 highlight ColorColumn ctermbg=0 guibg=lightgrey " Fallback for filetypes without a Tree-sitter parser. set foldmethod=indent set foldlevelstart=99 set foldlevel=99 " Interaction and persistence set mouse=a set autochdir set updatetime=300 set noerrorbells " Turn backup off set noswapfile set nobackup set nowritebackup set undodir=~/.cache/nvim/undodir set undofile " Writes to the unnamed register also writes to the * and + registers. This " makes it easy to interact with the system clipboard if has ('unnamedplus') set clipboard=unnamedplus else set clipboard=unnamed endif " File navigation set tags=tags~;,tags~ "setting gf (go file) path "change kernel version to your version, for kernel development set path=.,lib;,include;,includes; set path+=/usr/include,/usr/include/c++/* set path+=/usr/local/include call plug#begin() " Appearance Plug 'morhetz/gruvbox' Plug 'vim-airline/vim-airline' Plug 'lukas-reineke/indent-blankline.nvim' " Navigation Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } Plug 'junegunn/fzf.vim' Plug 'preservim/nerdtree' Plug 'christoomey/vim-tmux-navigator' Plug 'mbbill/undotree' Plug 'stevearc/aerial.nvim' " Development Plug 'nvim-treesitter/nvim-treesitter' Plug 'neoclide/coc.nvim', {'branch': 'release'} Plug 'zbirenbaum/copilot.lua' " Git Plug 'tpope/vim-fugitive' Plug 'lewis6991/gitsigns.nvim' Plug 'kdheepak/lazygit.nvim' " Markdown Plug 'MeanderingProgrammer/render-markdown.nvim' Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && npx --yes yarn install' } " Optional " execute 'source' fnameescape(expand(':p:h') . '/opt/avante.vim') " execute 'source' fnameescape(expand(':p:h') . '/opt/leetcode.vim') call plug#end() " Appearance if has_key(plugs, 'gruvbox') colorscheme gruvbox endif if has_key(plugs, 'vim-airline') "tabline with airline ":help airline-tabline let g:airline#extensions#tabline#enabled = 1 let g:airline#extensions#tabline#show_buffers = 0 let g:airline#extensions#tabline#show_splits = 0 let g:airline#extensions#tabline#show_tab_count = 0 let g:airline#extensions#tabline#show_close_button = 0 endif if has_key(plugs, 'indent-blankline.nvim') lua require('ibl').setup() endif " Navigation if has_key(plugs, 'fzf.vim') command! -bang -nargs=* GGrep \ call fzf#vim#grep( \ 'git grep --line-number -- ' . fzf#shellescape(), \ fzf#vim#with_preview({ \ 'dir': systemlist(['git', '-C', expand('%:p:h'), 'rev-parse', '--show-toplevel'])[0] \ }), 0) nnoremap :GFiles nnoremap :GGrep endif if has_key(plugs, 'nerdtree') autocmd StdinReadPre * let s:std_in=1 "when vim openning with no file, open NERDTree autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif nnoremap n :NERDTreeToggle endif if has_key(plugs, 'undotree') nnoremap u :UndotreeToggle endif if has_key(plugs, 'aerial.nvim') lua require('aerial').setup() nnoremap a AerialToggle! endif " Development if has_key(plugs, 'nvim-treesitter') lua require('plugin-config/nvim-treesitter') endif if has_key(plugs, "coc.nvim") " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list. nmap g[ (coc-diagnostic-prev) nmap g] (coc-diagnostic-next) " GoTo code navigation. nmap gd (coc-definition) nmap gr (coc-references) nmap gy (coc-type-definition) nmap gi (coc-implementation) " Highlight the symbol and its references when holding the cursor. autocmd CursorHold * silent call CocActionAsync('highlight') " Symbol renaming. nmap rn (coc-rename) " Formatting selected code. xmap f (coc-format-selected) nmap f (coc-format-selected) " Apply AutoFix to problem on the current line. nmap qf (coc-fix-current) " clangd nmap gh :CocCommand clangd.switchSourceHeader " Use K to show documentation in preview window. nnoremap h :call show_documentation() function! s:show_documentation() if (index(['vim','help'], &filetype) >= 0) execute 'h '.expand('') elseif (coc#rpc#ready()) call CocActionAsync('doHover') else execute '!' . &keywordprg . " " . expand('') endif endfunction let g:coc_default_semantic_highlight_groups = 1 let g:coc_global_extensions = [ \'coc-marketplace', \'coc-highlight', \'coc-clangd', \'coc-pyright', \'coc-lua', \'coc-sh', \'coc-cmake', \'coc-xmake', \'coc-json', \'coc-yaml', \'coc-vimlsp', \] endif if has_key(plugs, 'copilot.lua') lua require('plugin-config/copilot') endif " Git if has_key(plugs, 'gitsigns.nvim') lua require('plugin-config/gitsigns') endif if has_key(plugs, 'lazygit.nvim') nnoremap lg :LazyGit endif " Optional if has_key(plugs, 'avante.nvim') lua require('plugin-config/avante') endif if has_key(plugs, 'leetcode.nvim') lua require('plugin-config/leetcode') endif " General mappings nnoremap J :tabprevious nnoremap K :tabnext nnoremap J :tabmove -1 nnoremap K :tabmove +1 nnoremap " viwa"bi"lel nnoremap ' viwa'bi'lel nnoremap + :resize +5 nnoremap - :resize -5 nnoremap v+ :vertical resize +5 nnoremap v- :vertical resize -5 " 禁用 nnoremap xnoremap "HighLight trailing whitespace" highlight ExtraWhitespace ctermbg=red guibg=red match ExtraWhitespace /\s\+$/