Created
March 29, 2022 09:20
-
-
Save dajuno/fde5e63e20f2f1159b72582a13a8fc9d to your computer and use it in GitHub Desktop.
neovim config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if &compatible | |
set nocompatible | |
endif | |
filetype plugin indent on | |
" should be set before loading polyglot | |
let g:polyglot_disabled = ['yaml', 'latex'] " disable vim-polyglot | |
call plug#begin('~/.config/nvim/plugged') | |
Plug 'neoclide/coc.nvim', {'branch': 'release'} | |
" Plug 'neomake/neomake' | |
" Plug 'dense-analysis/ale' | |
Plug 'sheerun/vim-polyglot' | |
Plug 'tpope/vim-fugitive' | |
" Plug 'blindFS/vim-taskwarrior' | |
" Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } | |
Plug 'junegunn/fzf.vim' | |
" distraction free writing | |
Plug 'junegunn/goyo.vim' | |
Plug 'reedes/vim-pencil' | |
Plug 'reedes/vim-colors-pencil' | |
" Python plugins | |
" Plug 'vim-python/python-syntax' " until polyglot uses an updated package | |
" " dont forget to change g:polyglot_disabled !!! | |
" Plug 'Vimjas/vim-python-pep8-indent' | |
Plug 'psf/black', { 'branch': 'stable' } | |
Plug 'jeetsukumaran/vim-indentwise' | |
" YAML Syntax (polyglot doesnt let me set sw=2 ts=2) | |
" Plug 'stephpy/vim-yaml' | |
" rst note taking plugin | |
Plug 'gu-fan/riv.vim' | |
" Plug 'gu-fan/InstantRst' | |
Plug 'tpope/vim-surround' | |
Plug 'tpope/vim-commentary' | |
" Plug 'tpope/vim-obsession' | |
" Plug 'Yggdroot/indentLine' | |
Plug 'lervag/vimtex' | |
Plug 'SirVer/ultisnips' | |
Plug 'honza/vim-snippets' | |
Plug 'majutsushi/tagbar' | |
" Plug 'scrooloose/nerdcommenter' | |
Plug 'vim-airline/vim-airline' | |
Plug 'vim-airline/vim-airline-themes' | |
" Plug 'edkolev/tmuxline.vim' | |
Plug 'chriskempson/base16-vim' | |
Plug 'jeffkreeftmeijer/vim-numbertoggle' | |
Plug 'tmhedberg/SimpylFold' | |
Plug 'Konfekt/FastFold' | |
" Plug 'bfredl/nvim-ipy' | |
" Plug 'ivanov/vim-ipython' | |
" Plug 'vim-pandoc/vim-pandoc' | |
" Plug 'vim-pandoc/vim-pandoc-syntax' | |
Plug 'jpalardy/vim-slime' | |
" Plug 'xolox/vim-colorscheme-switcher' | |
" Plug 'xolox/vim-misc' " dependency of colorscheme-switcher | |
call plug#end() | |
" set statusline+=%#ErrorMsg#%{neomake#statusline#LoclistStatus()} | |
"let mapleader = '-' | |
let mapleader = ';' | |
" hard wrap | |
set formatoptions=t | |
set textwidth=80 | |
set wrapmargin=0 | |
set colorcolumn=80 | |
" tabulator | |
set expandtab | |
set tabstop=4 | |
set shiftwidth=4 | |
set smarttab | |
" appearance | |
set number | |
set showmatch | |
set cursorline | |
set background=dark | |
" show 3 lines before first line when scrolling | |
set scrolloff=3 | |
set mouse=a | |
set undofile " Save undo's after file closes | |
set undodir=$HOME/.config/nvim/undo " where to save undo histories | |
set undolevels=1000 " How many undos | |
set undoreload=10000 " number of lines to save for undo | |
" COLORSCHEMES | |
" fix leaking terminal background color in urxvt | |
" autocmd VimEnter * redraw! | |
set termguicolors | |
colorscheme base16-default-dark " or desert-warm-256 or apprentice | |
" function! SwitchLightDark() | |
" if g:colors_name == 'flattened_light' | |
" colorscheme flattened_dark | |
" redraw | |
" elseif g:colors_name == 'flattened_dark' | |
" colorscheme flattened_light | |
" redraw | |
" endif | |
" endfunction | |
" enable conceal syntax elements for pandoc | |
" hi! link Conceal Special | |
" MAPPINGS | |
nnoremap <Leader>n :bn<CR> | |
nnoremap <Leader>b :bp<CR> | |
nnoremap <C-s> :w<CR> | |
inoremap <C-s> <ESC>:w<CR> | |
nnoremap <space> za | |
" nnoremap <Leader><ESC> :syntax sync minlines=50<CR> | |
nnoremap <Leader><ESC> :syntax sync fromstart<CR> | |
nnoremap <Leader>q :copen<CR> | |
function ToggleColors() | |
if (g:colors_name == "base16-default-dark") | |
colorscheme base16-gruvbox-light-soft | |
set background=light | |
else | |
colorscheme base16-default-dark | |
set background=dark | |
endif | |
endfunction | |
function TogglePaste() | |
" because set pastetoggle=<key> does not work with multi key combinations | |
if (&paste == 0) | |
set paste | |
echo ":set paste" | |
else | |
set nopaste | |
echo ":set nopaste" | |
endif | |
endfunction | |
let g:pencil#wrapModeDefault = 'soft' " default is 'hard' | |
" nnoremap <expr> <F6> g:colors_name == "base16-default-dark" ? ":colo base16-gruvbox-light-soft\<CR>" : ":colo base16-default-dark\<CR>" :Goyo<CR> | |
nnoremap <F6> :call ToggleColors()<CR>:Goyo<CR>:PencilToggle<CR> | |
nnoremap <Leader>p :call TogglePaste()<CR> | |
command InitVim edit ~/.config/nvim/init.vim | |
" disable arrow keys | |
noremap <Up> <Nop> | |
noremap <Down> <Nop> | |
noremap <Left> <Nop> | |
noremap <Right> <Nop> | |
" focus on new splits | |
set splitbelow | |
set splitright | |
" autocmds | |
au BufNewFile,BufRead *.geo set filetype=gmsh | |
au BufNewFile,BufRead *.tikz set filetype=tex | |
au BufNewFile,BufRead *.edp set filetype=freefem | |
" au BufRead,BufNewFile *.rst setlocal spell | |
" possibly slow, try to avoid syntax HL problems. ..... | |
" autocmd BufEnter * :syntax sync fromstart | |
autocmd BufEnter * :syntax sync minlines=10 | |
""" PLUGINS | |
" fzf | |
nnoremap <Leader>f :Files<cr> | |
nnoremap <Leader>l :Buffers<cr> | |
" | |
" use ripgrep as grepprg | |
set grepprg=rg\ --vimgrep | |
let g:goyo_width = 81 | |
let g:black_linelength = 80 | |
" Airline | |
let g:airline#extensions#tmuxline#enabled = 1 | |
let g:airline#extensions#coc#enabled = 1 | |
let g:airline#extensions#tabline#enabled = 1 | |
let g:airline#extensions#tabline#excludes = ['LaTeX TOC', '__Tagbar__'] | |
let g:airline_exclude_filenames = ['LaTeX TOC'] | |
let g:airline#extensions#tabline#buffer_nr_show = 1 | |
let g:airline#extensions#tabline#buffer_min_count = 2 | |
let g:airline#extensions#tabline#buffers_label = '' | |
let g:airline#extensions#whitespace#show_message = 0 | |
set gfn=Liberation\ Mono\ for\ Powerline\ 10 | |
let g:airline_powerline_fonts = 1 | |
" let g:airline_theme = 'bubblegum' "'jellybeans' | |
" let g:airline_theme = 'apprentice' "'jellybeans' | |
" let g:airline_theme = 'base16_default' | |
let g:airline_theme = 'monochrome' | |
let g:airline_mode_map = { | |
\ '__' : '-', | |
\ 'n' : 'N', | |
\ 'i' : 'I', | |
\ 'R' : 'R', | |
\ 'c' : 'C', | |
\ 'v' : 'V', | |
\ 'V' : 'V', | |
\ '' : 'V', | |
\ 's' : 'S', | |
\ 'S' : 'S', | |
\ '' : 'S', | |
\ } | |
let g:airline_section_z = airline#section#create('%p%% %{g:airline_symbols.linenr}%#__accent_bold#%3l:%#__restore__#%2v') | |
let g:airline_skip_empty_sections = 1 | |
" let g:airline_section_warning = airline#section#create('%{neomake#statusline#LoclistStatus()}') | |
" TagBar | |
nmap <F8> :TagbarToggle<CR> | |
" " Unite.vim | |
" call unite#filters#sorter_default#use(['sorter_rank']) | |
" nnoremap <leader>f :<C-u>Unite -start-insert file<cr> | |
" call unite#filters#matcher_default#use(['matcher_fuzzy']) | |
" nnoremap <leader>r :<C-u>Unite -start-insert file_rec/neovim:!<cr> | |
" nnoremap <leader>l :Unite -quick-match buffer<cr> | |
"" vim commentary gmsh | |
autocmd FileType gmsh setlocal commentstring=//\ %s | |
vmap gi <ESC>:'<,'>norm gcc<cr> | |
" SimpylFold | |
let g:SimpylFold_docstring_preview = 1 | |
"autocmd BufWinEnter *.py setlocal foldexpr=SimpylFold(v:lnum) foldmethod=expr | |
"autocmd BufWinLeave *.py setlocal foldexpr< foldmethod< | |
" Slime | |
let g:slime_target = "tmux" | |
let g:slime_python_ipython = 1 | |
let python_highlight_all=1 | |
let g:slime_paste_file = "$HOME/.slime_paste" | |
let g:slime_no_mappings = 1 | |
xmap <leader>s <Plug>SlimeRegionSend | |
nmap <leader>s <Plug>SlimeMotionSend | |
nmap <leader>ss <Plug>SlimeLineSend | |
nmap <leader>sc <Plug>SlimeConfig | |
" FastFold | |
let g:tex_fold_enabled=1 | |
" VimTeX | |
let g:tex_flavor = 'latex' " vim detects tex | |
let g:tex_comment_nospell = 1 " disable spell checking in comments (standard tex plugin) | |
let g:vimtex_syntax_nospell_comments = 1 " disable spell checking in comments | |
let g:vimtex_enabled = 1 | |
let g:vimtex_fold_enabled = 1 | |
let g:vimtex_view_enabled = 1 | |
let g:vimtex_view_method = 'zathura' " -x nvr --remote-silent %f -c %l' | |
" let g:vimtex_latexmk_progname = 'nvr' | |
" let g:vimtex_compiler_progname = 'nvr' | |
" IndentLine | |
" let g:indentLine_char='▏' | |
" let g:indentLine_enabled=0 | |
" tagbar for markdown/pandoc | |
" .ctags: | |
"--langdef=markdown | |
"--langmap=markdown:.md | |
"--regex-markdown=/^(#+)[ \t]+([^#]*)/\1 \2/h,header,Markdown Headers/ | |
"--regex-markdown=/\[([^\[]+)\]\(([^\)]+)\)/\1/l,link,Markdown Links/ | |
"--regex-markdown=/!\[\]\(.*[\/ ](.*\.[a-z]{3})\)/\1/i,image,Markdown Image/ | |
let g:tagbar_type_pandoc = { | |
\ 'ctagstype' : 'markdown', | |
\ 'kinds' : [ | |
\ 'h:headings', | |
\ 'l:links', | |
\ 'i:images' | |
\ ], | |
\ "sort" : 0 | |
\ } | |
let g:tagbar_type_rst = { | |
\ 'ctagstype': 'rst', | |
\ 'ctagsbin' : 'rst2ctags', | |
\ 'ctagsargs' : '-f - --sort=yes', | |
\ 'kinds' : [ | |
\ 's:sections', | |
\ 'i:images' | |
\ ], | |
\ 'sro' : '|', | |
\ 'kind2scope' : { | |
\ 's' : 'section', | |
\ }, | |
\ 'sort': 0, | |
\ } | |
" CoC {{{ | |
" from CoC example config | |
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable | |
" delays and poor user experience. | |
set updatetime=300 | |
" Don't pass messages to |ins-completion-menu|. | |
set shortmess+=c | |
" Always show the signcolumn, otherwise it would shift the text each time | |
" diagnostics appear/become resolved. | |
if has("patch-8.1.1564") | |
" Recently vim can merge signcolumn and number column into one | |
set signcolumn=number | |
else | |
set signcolumn=yes | |
endif | |
command! -nargs=0 Format :call CocAction('format') | |
" Formatting selected code. | |
" xmap <leader>F <Plug>(coc-format-selected) | |
" nmap <leader>F <Plug>(coc-format-selected) | |
xmap <leader>F :Format<cr> | |
nmap <leader>F :Format<cr> | |
" 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> | |
\ pumvisible() ? "\<C-n>" : | |
\ <SID>check_back_space() ? "\<TAB>" : | |
\ coc#refresh() | |
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>" | |
function! s:check_back_space() abort | |
let col = col('.') - 1 | |
return !col || getline('.')[col - 1] =~# '\s' | |
endfunction | |
" Use <c-space> to trigger completion. | |
inoremap <silent><expr> <c-space> coc#refresh() | |
" Make <CR> auto-select the first completion item and notify coc.nvim to | |
" format on enter, <cr> could be remapped by other vim plugin | |
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm() | |
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>" | |
" 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 <SID>show_documentation()<CR> | |
function! s:show_documentation() | |
if (index(['vim','help'], &filetype) >= 0) | |
execute 'h '.expand('<cword>') | |
elseif (coc#rpc#ready()) | |
call CocActionAsync('doHover') | |
else | |
execute '!' . &keywordprg . " " . expand('<cword>') | |
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) | |
" 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) | |
" 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 <tab> for trigger completion and navigate to next complete item | |
" function! s:check_back_space() abort | |
" let col = col('.') - 1 | |
" return !col || getline('.')[col - 1] =~ '\s' | |
" endfunction | |
" " Next by Tab | |
" inoremap <silent><expr> <TAB> | |
" \ pumvisible() ? "\<C-n>" : | |
" \ <SID>check_back_space() ? "\<TAB>" : | |
" \ coc#rpc#request('doKeymap', ['snippets-expand', "\<TAB>"]) | |
" " Previous by Tab | |
" inoremap <silent><expr><S-Tab> | |
" \ pumvisible() ? "\<C-p>" : | |
" \<SID>check_back_space() ? "\<S-Tab>" : | |
" \ coc#rpc#request('doKeymap', ['snippets-expand', "\<S-Tab>"]) | |
" " use <c-space>for trigger completion | |
" imap <expr><c-space> coc#refresh() | |
" " Don't go to new line on enter when completing | |
" inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>" | |
" " Use <C-l> to trigger snippet expand. | |
" imap <C-l> <Plug>(coc-snippets-expand) | |
" " Use <C-j> to select text for visual text of snippet. | |
" vmap <C-j> <Plug>(coc-snippets-select) | |
" }}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment