Skip to content

Instantly share code, notes, and snippets.

@jamm1985
Last active December 14, 2023 03:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamm1985/eb1e0c46d372912179d57377b33f3390 to your computer and use it in GitHub Desktop.
Save jamm1985/eb1e0c46d372912179d57377b33f3390 to your computer and use it in GitHub Desktop.
Vim configuration as Python IDE (and also C, tex/latex and Julia)
" -- global section --
" colors
syntax enable
" colorscheme vimbrains "~/.vim/colors/vimbrains.vim (fallback colors)
" modern vim
set nocompatible
set backspace=indent,eol,start
set modelines=0
set nu
" spell
set spell
set spelllang=en,ru
" searching
set ignorecase
set smartcase
set gdefault
set incsearch
set showmatch
set hlsearch
" default width
set colorcolumn=80
set textwidth=79 "wrap lines, reformat using gq/gw commands
" tabs
set expandtab
set tabstop=2
set shiftwidth=2
" python specific
au FileType python setlocal
\ foldmethod=indent
\ expandtab
\ autoindent
\ tabstop=4
\ softtabstop=4
\ shiftwidth=4
\ textwidth=119
\ colorcolumn=120
" buffer specific
"au BufNewFile,BufRead *.mutt
" \ set textwidth=80
" Automatically change the current directory
" set autochdir
" GUI
set guioptions=r
" look for a tags file in the directory of the current file, then upward until / and in the working directory, then upward until /
set tags=./tags;,tags;
set langmap=ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯЖ;ABCDEFGHIJKLMNOPQRSTUVWXYZ:\,фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
set signcolumn=yes
" plugins
" https://github.com/junegunn/vim-plug
" Dependencies:
" brew install universal-ctags fzf ripgrep node bat git-delta
call plug#begin('~/.vim/plugged')
Plug 'sainnhe/gruvbox-material'
Plug 'JuliaEditorSupport/julia-vim'
Plug 'jpalardy/vim-slime'
Plug 'scrooloose/nerdtree'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'godlygeek/tabular'
Plug 'plasticboy/vim-markdown'
Plug 'mzlogin/vim-markdown-toc'
Plug 'rhysd/vim-clang-format'
Plug 'justmao945/vim-clang'
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Plug 'lervag/vimtex'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'preservim/tagbar'
Plug 'kkoomen/vim-doge', { 'do': { -> doge#install() } }
call plug#end()
" -- plugins configs selection --
" -- gruvbox-material colors -- "
" Important!!
if has('termguicolors')
set termguicolors
endif
" Apple terminal does not support it!
if $TERM_PROGRAM == "Apple_Terminal"
set notermguicolors
endif
set background=dark
let g:gruvbox_material_background = 'hard'
let g:gruvbox_material_better_performance = 1
let g:gruvbox_material_visual = 'green background'
let g:gruvbox_material_spell_foreground = 'colored'
" order is matter
colorscheme gruvbox-material
let g:airline_theme = 'gruvbox_material'
" -- slime --
let g:slime_target = "vimterminal"
let g:slime_python_ipython = 1
" -- nerd --
map <C-n> :NERDTreeToggle<CR>
let g:NERDTreeWinSize=60
" -- tagbar --
nmap <F8> :TagbarToggle<CR>
let g:tagbar_width=60
let g:tagbar_wrap = 1
" -- airline --
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffer_idx_mode = 1
nmap <leader>1 <Plug>AirlineSelectTab1
nmap <leader>2 <Plug>AirlineSelectTab2
nmap <leader>3 <Plug>AirlineSelectTab3
nmap <leader>4 <Plug>AirlineSelectTab4
nmap <leader>5 <Plug>AirlineSelectTab5
nmap <leader>6 <Plug>AirlineSelectTab6
nmap <leader>7 <Plug>AirlineSelectTab7
nmap <leader>8 <Plug>AirlineSelectTab8
nmap <leader>9 <Plug>AirlineSelectTab9
nmap <F5> <Plug>AirlineSelectPrevTab
nmap <F6> <Plug>AirlineSelectNextTab
"let g:airline_section_b = '%{strftime("%d/%m/%Y %H:%M")}'
let g:airline#extensions#whitespace#enabled = 0
" -- markdown --
let g:vim_markdown_folding_disabled = 1
let g:vim_markdown_toc_autofit = 1
" -- vimtex --
let g:tex_flavor='latex'
let g:vimtex_view_method='skim' " see https://www.reddit.com/r/vim/comments/7c7wd9/vim_vimtex_zathura_on_macos/
let g:vimtex_quickfix_open_on_warning=0
" -- doge --
let g:doge_doc_standard_python = 'google'
" -- status line --
set laststatus=2
" -- FZF --
" scroll preview window
let $FZF_DEFAULT_OPTS="--bind \"ctrl-f:preview-down,ctrl-b:preview-up\""
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.9 } }
" -- coc config --
" Plugins:
" python https://github.com/fannheyward/coc-pyright
" julia https://github.com/fannheyward/coc-julia
" markdown https://github.com/fannheyward/coc-markdownlint
" snippets https://github.com/neoclide/coc-snippets
" vimtex https://github.com/neoclide/coc-vimtex
" clang https://github.com/clangd/coc-clangd
" JSON https://github.com/neoclide/coc-json
" YAML https://github.com/neoclide/coc-yaml
" see .vim/coc-settings.json !! or Use :CocConfig
" to update plugins use :CocUpdate
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: There's always complete item selected by default, you may want to enable
" no select by `"suggest.noselect": true` in your configuration file.
" 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.
let g:airline#extensions#coc#enabled = 1
" 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>
"Original file version from: https://github.com/sherifkandeel/vim-colors
"vimbrains
hi clear
if exists("syntax_on")
syntax reset
endif
let g:colors_name='vimbrains'
if !has('gui_running') && &t_Co != 256
finish
endif
" Palette
let s:bg = ["#1C1B19", 234]
let s:bg2 = ["#2D2C29", 235]
let s:fg = ["#FCE8C3", 223]
let s:muted = ["#918175", 240] "131
let s:key1 = ['#ce7828', 172]
let s:key2 = ["#FBB829", 3]
let s:string = ["#698857", 65]
let s:special = ["#6796bd", 67]
let s:annotation= ["#9975ab", 103]
let s:variable = ["#6c6c6c", 67]
" Setup Variables:
let s:none = ['NONE', 'NONE']
if !exists('g:vimbrains_bold')
let g:vimbrains_bold=1
endif
if !exists('g:vimbrains_italic')
if has('gui_running') || $TERM_ITALICS == 'true'
let g:vimbrains_italic=1
else
let g:vimbrains_italic=0
endif
endif
if !exists('g:vimbrains_undercurl')
let g:vimbrains_undercurl=1
endif
if !exists('g:vimbrains_underline')
let g:vimbrains_underline=1
endif
if !exists('g:vimbrains_inverse')
let g:vimbrains_inverse=1
endif
" Setup Emphasis:
let s:bold = 'bold,'
if g:vimbrains_bold == 0
let s:bold = ''
endif
let s:italic = 'italic,'
if g:vimbrains_italic == 0
let s:italic = ''
endif
let s:underline = 'underline,'
if g:vimbrains_underline == 0
let s:underline = ''
endif
let s:undercurl = 'undercurl,'
if g:vimbrains_undercurl == 0
let s:undercurl = ''
endif
let s:inverse = 'inverse,'
if g:vimbrains_inverse == 0
let s:inverse = ''
endif
" Highlighting Function:
function! s:HL(group, fg, ...)
" Arguments: group, guifg, guibg, gui, guisp
" foreground
let fg = a:fg
" background
if a:0 >= 1
let bg = a:1
else
let bg = s:none
endif
" emphasis
if a:0 >= 2 && strlen(a:2)
let emstr = a:2
else
let emstr = 'NONE,'
endif
let histring = [ 'hi', a:group,
\ 'guifg=' . fg[0], 'ctermfg=' . fg[1],
\ 'guibg=' . bg[0], 'ctermbg=' . bg[1],
\ 'gui=' . emstr[:-2], 'cterm=' . emstr[:-2]
\ ]
" special
if a:0 >= 3
call add(histring, 'guisp=' . a:3[0])
endif
execute join(histring, ' ')
endfunction
" Color definitions
call s:HL('Normal', s:fg, s:bg)
if version >= 700
call s:HL('CursorLine', s:none, s:bg2)
" Tab pages line filler
call s:HL('TabLineFill', s:bg, s:bg)
" Active tab page label
call s:HL('TabLineSel', s:bg, s:bg, s:bold)
" Not active tab page label
hi! link TabLine TabLineFill
" Match paired bracket under the cursor
call s:HL('MatchParen', s:key2, s:bg2, s:bold)
endif
if version >= 703
" Highlighted screen columns
call s:HL('ColorColumn', s:none, s:bg)
" Concealed element: \lambda → λ
call s:HL('Conceal', s:special, s:none)
" Line number of CursorLine
call s:HL('CursorLineNr', s:key2, s:bg)
endif
call s:HL('NonText', s:muted)
call s:HL('SpecialKey', s:muted)
call s:HL('Visual', s:fg, s:bg, s:inverse)
call s:HL('Search', s:bg, s:key2)
call s:HL('IncSearch', s:bg, s:key2)
call s:HL('Underlined', s:special, s:none, s:underline)
call s:HL('StatusLine', s:fg, s:bg2)
call s:HL('StatusLineNC', s:bg2, s:bg, s:underline)
" The column separating vertically split windows
call s:HL('VertSplit', s:fg, s:bg)
" Current match in wildmenu completion
call s:HL('WildMenu', s:key1, s:bg2, s:bold)
" Error messages on the command line
call s:HL('ErrorMsg', s:fg, s:key1)
call s:HL('MoreMsg', s:key2)
" Current mode message: -- INSERT --
call s:HL('ModeMsg', s:fg, s:bg)
" 'Press enter' prompt and yes/no questions
hi! link Question MoreMsg
" Warning messages
hi! link WarningMsg ErrorMsg
" Line number for :number and :# commands
call s:HL('LineNr', s:muted)
" Column where signs are displayed
call s:HL('SignColumn', s:none, s:bg)
" Line used for closed folds
call s:HL('Folded', s:muted, s:bg, s:italic)
" Column where folds are displayed
call s:HL('FoldColumn', s:muted, s:bg)
" Character under cursor
call s:HL('Cursor', s:fg, s:none, s:inverse)
"""" Syntax
"Dont highlight to much
call s:HL('Special', s:fg)
call s:HL('Comment', s:muted, s:none, s:italic)
"TODO
call s:HL('Todo', s:fg, s:bg, s:bold)
call s:HL('Error', s:key1, s:bg, s:bold . s:inverse)
" String constant: "this is a string"
call s:HL('String', s:string)
call s:HL('EscSequence', s:fg, s:none, s:bold)
call s:HL('Statement', s:key1)
" if, then, else, endif, swicth, etc.
hi! link Conditional Statement
" for, do, while, etc.
hi! link Repeat Statement
" case, default, etc.
hi! link Label Statement
" try, catch, throw
hi! link Exception Statement
" sizeof, "+", "*", etc.
""" MF
hi! link Operator Statement
" Any other keyword
hi! link Keyword Statement
call s:HL('Identifier', s:key1)
call s:HL('Function', s:annotation)
" Generic preprocessor
call s:HL('PreProc', s:key1)
" Preprocessor #include
hi! link Include PreProc
" Preprocessor #define
hi! link Define PreProc
" Same as Define
hi! link Macro PreProc
" Preprocessor #if, #else, #endif, etc.
hi! link PreCondit PreProc
" Generic constant
call s:HL('Constant', s:key2)
" Character constant: 'c', '/n'
hi! link Character Constant
" Boolean constant: TRUE, false
hi! link Boolean Constant
" Number constant: 234, 0xff
hi! link Number Constant
" Floating point constant: 2.3e10
hi! link Float Constant
" Generic type
call s:HL('Type', s:key1)
" static, register, volatile, etc
call s:HL('StorageClass', s:key1)
" struct, union, enum, etc.
call s:HL('Structure', s:key1)
" typedef
call s:HL('Typedef', s:key1)
if version >= 700
" Popup menu: normal item
""" MF
call s:HL('Pmenu', s:fg, s:bg2)
" Popup menu: selected item
call s:HL('PmenuSel', s:bg, s:special, s:bold)
" Popup menu: scrollbar
call s:HL('PmenuSbar', s:none, s:bg)
" Popup menu: scrollbar thumb
call s:HL('PmenuThumb', s:none, s:bg)
endif
" Spelling
if has("spell")
" Not capitalised word, or compile warnings
call s:HL('SpellCap', s:special, s:none, s:bold . s:italic)
" Not recognized word
call s:HL('SpellBad', s:none, s:none, s:undercurl, s:key1)
" Wrong spelling for selected region
call s:HL('SpellLocal', s:none, s:none, s:undercurl, s:key2)
" Rare word
call s:HL('SpellRare', s:none, s:none, s:undercurl, s:special)
endif
" Diff
call s:HL('DiffDelete', s:key1, s:bg, s:inverse)
call s:HL('DiffAdd', s:string, s:bg, s:inverse)
" Alternative setting
call s:HL('DiffChange', s:special, s:bg, s:inverse)
call s:HL('DiffText', s:key2, s:bg, s:inverse)
" HTML
call s:HL('htmlLink', s:fg, s:none, s:underline)
call s:HL('htmlTitle', s:fg, s:none, s:bold)
call s:HL('htmlTag', s:key1, s:none)
call s:HL('htmlTagName', s:key1, s:none)
call s:HL('htmlArg', s:key2, s:none)
call s:HL('htmlSpecialChar', s:key2, s:none, s:underline)
call s:HL('htmlBold', s:fg, s:bg, s:bold)
call s:HL('htmlBoldUnderline', s:fg, s:bg, s:bold . s:underline)
call s:HL('htmlBoldItalic', s:fg, s:bg, s:bold . s:italic)
call s:HL('htmlBoldUnderlineItalic', s:fg, s:bg, s:bold . s:underline . s:italic)
call s:HL('htmlUnderline', s:fg, s:bg, s:underline)
call s:HL('htmlUnderlineItalic', s:fg, s:bg, s:underline . s:italic)
call s:HL('htmlItalic', s:fg, s:bg, s:italic)
" Markdown
call s:HL('markdownH1', s:key1, s:bg, s:bold)
hi! link markdownH2 markdownH1
hi! link markdownH3 markdownH1
hi! link markdownH4 markdownH1
hi! link markdownH5 markdownH1
" Python
call s:HL('pythonDecorator', s:annotation, s:bg)
call s:HL('pythonInclude', s:key1, s:bg)
call s:HL('pythonImport', s:key1, s:bg)
call s:HL('pythonBoolean', s:key2, s:bg)
call s:HL('pythonFunction', s:fg, s:bg)
call s:HL('pythonBuiltin', s:key2, s:bg)
call s:HL('pythonStatement', s:key1, s:bg)
hi! link pythonCoding Comment
hi! link pythonBytesEscape EscSequence
" Scala
call s:HL('scalaAnnotation', s:annotation, s:bg)
call s:HL('scalaNameDefinition', s:variable, s:bg)
call s:HL('scalaSquareBracketsBrackets', s:fg, s:bg)
call s:HL('scalaTypeDeclaration', s:fg, s:bg)
call s:HL('scalaKeywordModifier', s:key1, s:bg)
call s:HL('scalaSpecial', s:key2, s:bg)
"Vim
call s:HL('vimBracket', s:key2, s:bg)
hi! link vimNotation vimBracket
hi! link vimMapModKey vimBracket
hi! link vimCommentTitle Todo
"C
hi! link cSpecial EscSequence
"D
hi! link dEscSequence EscSequence
" NERDTree
call s:HL('NERDTreeDir', s:string, s:bg)
hi! link pythonCoding Comment
call s:HL('NERDTreeClosable', s:fg, s:bg)
call s:HL('NERDTreeOpenable', s:fg, s:bg)
call s:HL('NERDTreeDirSlash', s:fg, s:bg)
call s:HL('NERDTreeUp', s:fg, s:bg)
hi Title guifg=gold gui=bold cterm=bold ctermfg=yellow
hi Ignore guifg=grey40 cterm=bold ctermfg=7
hi Directory ctermfg=darkcyan
hi VisualNOS cterm=bold,underline
hi SpellBad cterm=bold ctermfg=7 gui=undercurl,bold
hi ColorColumn ctermbg=235 guibg=#2c2d27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment