Skip to content

Instantly share code, notes, and snippets.

@zprhhs
Last active July 22, 2024 02:57
Show Gist options
  • Save zprhhs/9630dd6d666995236319afb35293a77b to your computer and use it in GitHub Desktop.
Save zprhhs/9630dd6d666995236319afb35293a77b to your computer and use it in GitHub Desktop.
coc.nvim & neovim configure
{
"dependencies": {
"coc-clangd": ">=0.28.0",
"coc-diagnostic": ">=0.23.9",
"coc-git": ">=2.6.1",
"coc-highlight": ">=2.0.4",
"coc-json": ">=1.8.0",
"coc-pairs": ">=1.4.2",
"coc-pyright": ">=1.1.293",
"coc-snippets": ">=3.1.6",
"coc-syntax": ">=1.2.4",
"coc-yaml": ">=1.9.0"
}
}
/*安装方法:
:CocInstall coc-clangd coc-diagnostic coc-git coc-json coc-highlight coc-pairs coc-yaml coc-syntax coc-snippets coc-pyright
*/
# setting prefix to ctrl + a
# --------------------------------[ key bind ]---------------------------------
# set -g prefix M-a
# unbind ctrl + b
# unbind C-b
# bind key for select right pane
bind-key -r -T prefix l select-pane -R
# bind key for select up pane
bind-key -r -T prefix k select-pane -U
# bund key for select down pane
bind-key -r -T prefix j select-pane -D
# bind key for select left pane
bind-key -r -T prefix h select-pane -L
bind-key -r -T prefix M-k resize-pane -U
bind-key -r -T prefix M-j resize-pane -D
bind-key -r -T prefix M-h resize-pane -L
bind-key -r -T prefix M-l resize-pane -R
bind-key % split-window -h -c "#{pane_current_path}"
bind-key \" split-window -v -c "#{pane_current_path}"
# --------------------------------[ Settings ]---------------------------------
set -g default-terminal "screen-256color" # colors!
# set -g default-terminal "tmux-256color"
setw -g xterm-keys on
set -s focus-events on
set-option -sg escape-time 10
set -g status-interval 1
set-window-option -g automatic-rename on
set-option -g set-titles on
set -g history-limit 50000
setw -q -g utf8 on
set -g base-index 1 # start windows numbering at 1
setw -g pane-base-index 1 # make pane numbering consistent with windows
set -g renumber-windows on # renumber windows when a window is closed
set -g set-titles on # set terminal title
set -g display-panes-time 800 # slightly longer pane indicators display time
set -g display-time 1000 # slightly longer status messages display time
setw -g mode-keys vi
set-option -sa terminal-overrides ',$TERM:RGB'
set-option -ga terminal-overrides ',xterm-256color:Tc'
set -g visual-activity on
setw -g monitor-activity on
set-option -g mouse on
# --------------------------------[ Theme ]---------------------------------
# === pane
set-option -g pane-border-style fg='#3C3836'
set-option -g pane-active-border-style fg='#A89984'
# set-option -g pane-border-format " #P"
set-option -g display-panes-active-colour '#458588'
set-option -g display-panes-colour '#D79921'
# === status
set-option -g status-left-length 24
set-option -g status-right-length 120
set-option -g status-position top
set-option -g status-right "#[fg=#EBDBB2,bg=#504945] %m-%d %a %I:%M %p"
set -g status-style bg='#32302F',fg='#A89984'
set -g status-left "#{?client_prefix,#[fg=colour198],#[fg=colour83]}#[bg=#504945]◊#[fg=#EBDBB2]#S:#I-#P "
# === clock
set-window-option -g clock-mode-colour '#98971A'
# === windows
setw -g window-status-format ' #I:#W#F '
setw -g window-status-current-format '#[bg=#458588,fg=#1D2021] #I:#W#F '
setw -g window-status-separator ''
# === message & activity
set-option -g message-style fg='#1d2021',bg='#A89984'
set -g window-active-style 'bg=#1D2021,fg=#EBDBB2'
set-window-option -g window-status-bell-style fg='#3C3836',bg='#CC241D'
{
"jedi.startupMessage": false,
"jedi.enable": true,
"jedi.markupKindPreferred": "plaintext",
"jedi.trace.server": "off",
"jedi.executable.command": "jedi-language-server",
"diagnostic.warningSign":"!!"
}
" =========================== neovim version v0.7.2
" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
call plug#begin('~/.config/vim_plug/plugged')
Plug 'honza/vim-snippets'
Plug 'bfrg/vim-cpp-modern'
Plug 'nvim-lua/plenary.nvim'
Plug 'lewis6991/gitsigns.nvim'
Plug 'nvim-treesitter/nvim-treesitter'
Plug 'nvim-treesitter/nvim-treesitter-refactor'
Plug 'nvim-treesitter/playground'
Plug 'romgrk/nvim-treesitter-context'
Plug 'DanilaMihailov/beacon.nvim'
Plug 'tpope/vim-fugitive'
Plug 'vim-python/python-syntax'
Plug 'vim-scripts/ctags.vim'
Plug 'vim-airline/vim-airline'
Plug 'scrooloose/nerdcommenter'
Plug 'octol/vim-cpp-enhanced-highlight'
Plug 'sainnhe/gruvbox-material'
Plug 'Yggdroot/indentLine'
Plug 'preservim/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'majutsushi/tagbar'
Plug 'simeji/winresizer'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
call plug#end()
filetype plugin on
" set ambiwidth=double
" set t_ut= "
set showmatch " highlight for matched parentheses
set matchtime=1 " match time for parentheses
set noshowmode "do not show edit mode in cmd
set novisualbell
set noerrorbells
set report=0
set ignorecase " ignore case when searching
set nobackup
set autoread
set nocompatible
set backspace=2
set showcmd
set hlsearch
syntax on
" Tab settings
set ts=4
set softtabstop=4
set shiftwidth=4
set expandtab
" indent method
" set cindent
set smartindent
" Set Mouse
set mouse+=a
" set selection=exclusive
" set selectmode=mouse,key
set history=1000 "设置历史记录条数
" close welcome page
set shortmess=atI
set clipboard+=unnamed
" VIM Encoding Method
set encoding=utf-8
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936,latin1
" set fileencoding=gb2312
set fileencoding=utf-8
set termencoding=utf-8
set signcolumn=yes
set cmdheight=1
set ruler
set nu
set cursorline
" reset cursor when vim exits
" au VimLeave * set guicursor=a:ver25-blinkon0
set foldmethod=indent
set foldlevelstart=99 " set close fold at start
" coc.nvim settings
set hidden
set nowritebackup
set updatetime=300
set shortmess+=c
" Line Settings
set wrap
" +================================ colorscheme =====================================+ "
set t_Co=256
set termguicolors
set background=dark
hi ExtraWhitespace ctermbg=red guibg=red
hi Todo ctermbg=red guibg=red
let g:airline_theme = 'gruvbox_material'
let g:gruvbox_material_background = 'hard'
colorscheme gruvbox-material
au FileType gitcommit,gitrebase let g:gutentags_enabled=0
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
let g:python_highlight_all = 1
" +================================ 可视化缩进 =====================================+ "
let g:indent_guides_enable_on_vim_startup = 0 " 默认关闭
let g:indent_guides_guide_size = 1 " 指定对齐线的尺寸
let g:indent_guides_start_level = 2 " 从第二层开始可视化显示缩进
au FileType json let g:indentLine_setConceal = 0 " set default conceal for json
" +================================== NERDTree =======================================+ "
" autocmd vimenter * NERDTree "自动开启Nerdtree
" autocmd vimenter * NERDTreeToggle
let g:NERDTreeWinSize = 25 "设定 NERDTree 视窗大小
let NERDTreeShowBookmarks=1 " 开启Nerdtree时自动显示Bookmarks
"打开vim时如果没有文件自动打开NERDTree
" autocmd vimenter * if !argc()|NERDTree|endif
"当NERDTree为剩下的唯一窗口时自动关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
autocmd BufEnter * if bufname('#') =~ 'NERD_tree_\d\+' && bufname('%') !~ 'NERD_tree_\d\+' && winnr('$') > 1 |
\ let buf=bufnr() | buffer# | execute "normal! \<C-W>w" | execute 'buffer'.buf | endif
" 设置树的显示图标
" let g:NERDTreeDirArrowExpandable = '+'
" let g:NERDTreeDirArrowCollapsible = '-'
let NERDTreeIgnore = ['\.pyc$'] " 过滤所有.pyc文件不显示
let g:NERDTreeShowLineNumbers=0 " 是否显示行号
let g:NERDTreeHidden=0 "不显示隐藏文件
""Making it prettier
let NERDTreeMinimalUI = 1
let NERDTreeDirArrows = 1
" +================================== 按键映射 =======================================+ "
" self key map:
" <leader>s : open key
" <leader>d : close key
" <leader>e : norm key
" quicky paste
noremap <leader>sp :set paste<CR>i
nnoremap <leader>dp :set nopaste<CR>
" fold method change
nnoremap <leader>sf :set foldmethod=manual<CR>
nnoremap <leader>df :set foldmethod=indent<CR>
" enable and disable mouse support
nnoremap <leader>sm :set mouse+=a<CR>
nnoremap <leader>dm :set mouse=<CR>
" match and undo trailing
nnoremap <leader>st :match ExtraWhitespace /\s\+$/<CR>/\s\+$/<CR>
nnoremap <leader>dt :match<CR>:noh<CR>
" close highlight
nnoremap <leader>dh :noh<CR>
inoremap <silent> jj <Esc>
inoremap <M-h> <left>
inoremap <M-j> <down>
inoremap <M-k> <up>
inoremap <M-l> <right>
" swap
vnoremap <C-C> <ESC>`.``gvp``P
" plug key map
nnoremap <silent> <F4> :TagbarToggle<CR> " tagbar
nnoremap <F3> :NERDTreeToggle<CR>:NERDTreeRefreshRoot<CR> " nerdtree
" +================================== coc.nvim ======================================+ "
" Some servers have issues with backup files, see #649.
set nobackup
set nowritebackup
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
set signcolumn=yes
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1):
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice.
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" 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 <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window.
nnoremap <silent> K :call ShowDocumentation()<CR>
function! ShowDocumentation()
if CocAction('hasProvider', 'hover')
call CocActionAsync('doHover')
else
call feedkeys('K', 'in')
endif
endfunction
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" Formatting selected code.
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder.
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" Run the Code Lens action on the current line.
nmap <leader>cl <Plug>(coc-codelens-action)
" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
" Remap <C-f> and <C-b> for scroll float windows/popups.
if has('nvim-0.4.0') || has('patch-8.2.0750')
nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif
" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of language server.
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocActionAsync('format')
" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR :call CocActionAsync('runCommand', 'editor.action.organizeImport')
" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Mappings for CoCList
" Show all diagnostics.
nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list.
nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>
if $CONDA_PREFIX == ""
let s:current_python_path=$CONDA_PYTHON_EXE
else
let s:current_python_path=$CONDA_PREFIX.'/bin/python'
endif
call coc#config('python', {'pythonPath': s:current_python_path})
" +=================================== tagbar =======================================+ "
let g:tagbar_width=30
" +================================== airline =======================================+ "
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#formatter = 'default'
let g:airline#extensions#tabline#buffer_idx_format = {}
let g:airline#extensions#tabline#buffer_idx_mode = 3
let g:airline#extensions#keymap#enabled = 1
nmap <Leader>1g <Plug>AirlineSelectTab01
nmap <Leader>2g <Plug>AirlineSelectTab02
nmap <Leader>3g <Plug>AirlineSelectTab03
nmap <Leader>4g <Plug>AirlineSelectTab04
nmap <Leader>5g <Plug>AirlineSelectTab05
nmap <Leader>6g <Plug>AirlineSelectTab06
nmap <Leader>7g <Plug>AirlineSelectTab07
nmap <Leader>8g <Plug>AirlineSelectTab08
nmap <Leader>9g <Plug>AirlineSelectTab09
nmap <Leader>10g <Plug>AirlineSelectTab10
nmap <Leader>11g <Plug>AirlineSelectTab11
nmap <Leader>12g <Plug>AirlineSelectTab12
nmap <Leader>13g <Plug>AirlineSelectTab13
nmap <Leader>14g <Plug>AirlineSelectTab14
nmap <Leader>15g <Plug>AirlineSelectTab15
nmap <Leader>16g <Plug>AirlineSelectTab16
nmap <Leader>17g <Plug>AirlineSelectTab17
nmap <Leader>18g <Plug>AirlineSelectTab18
nmap <Leader>19g <Plug>AirlineSelectTab19
nmap <Leader>20g <Plug>AirlineSelectTab20
nmap <Leader>21g <Plug>AirlineSelectTab21
nmap <Leader>22g <Plug>AirlineSelectTab22
nmap <Leader>23g <Plug>AirlineSelectTab23
nmap <Leader>24g <Plug>AirlineSelectTab24
nmap <Leader>25g <Plug>AirlineSelectTab25
nmap <Leader>26g <Plug>AirlineSelectTab26
nmap <Leader>27g <Plug>AirlineSelectTab27
nmap <Leader>28g <Plug>AirlineSelectTab28
nmap <Leader>29g <Plug>AirlineSelectTab29
nmap <leader>- <Plug>AirlineSelectPrevTab
nmap <leader>= <Plug>AirlineSelectNextTab
nmap <leader>q :bp<cr>:bd #<cr>
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
" function JumpBuf()
" buffers
" let g:buffer_id = input('Enter buffer: ')
" execute \"buffer\" g:buffer_id
" endfunction
" +=============================== NERD Commenter ====================================+ "
"add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
au FileType python let g:NERDSpaceDelims = 0
" Use compact syntax for prettified multi-line comments
let g:NERDCompactSexyComs = 1
" Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDDefaultAlign = 'left'
" Set a language to use its alternate delimiters by default
let g:NERDAltDelims_java = 1
" Add your own custom formats or override the defaults
" let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } }
" Allow commenting and inverting empty lines (useful when commenting a region)
let g:NERDCommentEmptyLines = 1
" Enable trimming of trailing whitespace when uncommenting
let g:NERDTrimTrailingWhitespace = 1
" Enable NERDCommenterToggle to check all selected lines is commented or not
let g:NERDToggleCheckAllLines = 1
let g:cpp_attributes_highlight = 1
let g:cpp_member_highlight = 1
let g:cpp_simple_highlight = 1
" +=============================== FzF ====================================+ "
let g:fzf_buffers_jump = 1
nnoremap <leader>x :Buffer<CR>
let g:fzf_preview_window = ['hidden,right,50%,<70(up,40%)', 'ctrl-/']
### 1. 插件Yggdroot/indentLine会自动隐藏`*`等符号
在Json、Markdown文件中,插件Yggdroot/indentLine会进行自动隐藏一些符号如:` 和 *
解决方法为https://github.com/Yggdroot/indentLine/issues/140#issuecomment-357620391。
以Json为例:
- 进入vim, 输入`:e $VIMRUNTIME/syntax/json.vim`, 找到并进入json的syntax文件(如果是markdown,则把这里的json直接替换为markdown)
- 输入`/conceal`,匹配到关键字,注释掉设置conceal的语句
### 注意:安装完成后再nvim中使用命令`:checkhealth`进行检查环境检查,将一些必要的error和warning按照提示进行修复
2023.03.16:
tmux和nvim支持鼠标操作,如果和终端不兼容的话可以查找关键字mouse注释掉相关行
nvim支持fzf查看buffers,按下组合键“\+x”打开buffers跳转窗口,在跳转窗口下按下“ctrl+/”打开代码预览窗口
@shanfei-huang
Copy link

你好,我安装的airline有乱码该怎么解决了呀,用的版本是ubuntu 22.04,
0% ㏑:173/245☰℅:1 ☲ [97:208]mix-indent-file
显示出来是这样的效果

@zprhhs
Copy link
Author

zprhhs commented Mar 16, 2023

你好,我没有用过ubuntu的终端,不太确定是那里的问题,可能是字体的问题,比如字体不支持这些特殊字符,或者在airline的readme里面有自定义㏑、☰、☲等符号,您可以看一下

@shanfei-huang
Copy link

shanfei-huang commented Mar 16, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment