"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Behaviour. " " All our scripts and files are here. if filereadable(expand("~/devel/scripts/vim/vimrc")) set runtimepath+=~/devel/scripts/vim endif " Set 'nocompatible' to ward off unexpected things that your distro might " have made, as well as sanely reset options when re-sourcing .vimrc set nocompatible " Line ending is UNIX. set fileformat=unix " Swap files go here. "set directory="~/tmp,." console version complains all the time. " Don't backup files. set nobackup "set backupdir="~/tmp,." git commit doesn't work. " Try to set up UTF-8 encoding. if has('multi_byte') if &termencoding == "" let &termencoding = &encoding endif set encoding=utf-8 setglobal fileencoding=utf-8 "setglobal bomb set fileencodings=ucs-bom,utf-8,latin1 endif " Make tabes to be equal to 4 space chars. set tabstop=4 " Number of spaces a counts. If different from tabstop a combination of " tabs and spaces will be inserted. set softtabstop=4 " For indentation shift by 4 chars. set shiftwidth=4 " When on insert shiftwidth space in front of line. When off inserts " blanks according to softtabstop. set smarttab " Don't expand tabs. set expandtab if has('autocmd') " Unset expandtab for make files in any case. autocmd FileType make setlocal noexpandtab " Set expandtab for python files in any case. autocmd FileType python setlocal expandtab endif " Attempt to determine the type of a file based on its name and possibly its " contents. Use this to allow intelligent auto-indenting for each filetype, " and for plugins that are filetype specific. filetype indent plugin on " When opening a new line and no filetype-specific indenting is enabled, keep " the same indent as the line you're currently on. Useful for READMEs, etc. set autoindent " Allow backspacing over autoindent, line breaks and start of insert action set backspace=indent,eol,start " Stop certain movements from always going to the first character of a line. " While this behaviour deviates from that of Vi, it does what most users " coming from other editors would expect. set nostartofline " Try to not cross 80 char boundary. set textwidth=80 " Existing long lines are not broken. set formatoptions+=l " Auto-wrap comments using textwidth. set formatoptions=cq " Insert comment leader if is hit in insert mode or 'o' in Normal mode. set formatoptions+=ro "set formatoptions-=o " don't autoformat on 'o' e.g. comment wrapping " " C++ oriented. " "do not auto insert single line comments set comments-=:// " Auto-insert multi-line comment continuations set comments+=f:// " Do not indent after namespace XX{ set cino+=N-s " Match open-bracket indentation when breaking parameter lists over multiple " lines. set cino+=(0 " enable omni completion set omnifunc=syntaxcomplete#Complete " If modlines available then turn it on so each file could set its settings. " ex. # vim: set expandtab: if exists('+modeline') set modeline set modelines=5 endif " read/write a .viminfo file, don't store more if exists('+viminfo') set viminfo='20,\"50 endif " than 50 lines of registers let g:netrw_preview = 1 " netrw open window to the right let g:netrw_browse_split = 3 " open in a tab set ttyfast "tf "smooths redraw by using more bandwidth "set sessionoptions-=options "show shortmessages "set shortmess+=atIW " Set timeout for detecting command key sequence set timeoutlen=400 " Quickly time out on keycodes, but never time out on mappings set notimeout ttimeout ttimeoutlen=200 " Use to toggle between 'paste' and 'nopaste' "set pastetoggle= """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Display " " Configure coloring on command line terminals. if &term=="xterm" " enable 256 colors set t_Co=256 " set t_Co=8 set t_Sb=[4%dm set t_Sf=[3%dm endif " " Configure color theme, fonts and other graphics. " if &t_Co > 16 " set color scheme colorscheme darkblue "set guioptions-=m "set guioptions-=T "set lines=50 "set columns=85 " Set the font. if has("win32") || has("win64") "set guifont=FreeMono:h14:cANSI "set guifont=Courier\ AM:h12 else "set guifont=Bitstream\ Vera\ Sans\ Mono\ 12 set guifont=Monospace\ 12 endif endif " Switch syntax highlighting on, when the terminal has colors " Also switch on highlighting the last used search pattern. if &t_Co > 2 || has('gui_running') syntax on set hlsearch endif " wrap text at window edge without modifying buffer set nowrap " Scroll this much chars when scrolled horizontally. set sidescroll=1 " break at a suitable character (as in breakat) "set linebreak " Begin scrolling this lines from window edge. set scrolloff=0 " Set the command window height to 2 lines, to avoid many cases of having to " press to continue" set cmdheight=2 " Always display the status line, even if only one window is displayed set laststatus=2 " Display the cursor position on the last line of the screen or in the status " line of a window if exists('+ruler') set ruler endif " Instead of failing a command because of unsaved changes, raise a dialogue " asking if you wish to save changed files. if exists('+confirm') set confirm endif " Use visual bell instead of beeping when doing something wrong if exists('+visualbell') set visualbell " And reset the terminal code for the visual bell. If visualbell is set, and " this line is also included, vim will neither flash nor beep. If visualbell " is unset, this does nothing. set t_vb= endif " Display line numbers on the left if exists('+number') set number endif " Turn on spell check. if exists('+spell') && !&diff set spell highlight clear SpellBad highlight SpellBad cterm=underline ctermfg=red gui=undercurl guisp=Red endif " Show 80th column. if exists('+colorcolumn') set colorcolumn=+1 " color textwidth+1-th line endif " Show command-line completion above the command line. set wildmenu " wildmenu ignore list set wildignore=*.o,*.obj,*.bak,*.exe,*.d,*.dd " Complete to longest common string set wildmode=longest:full " remember more history set history=1000 " Highlight searched string as typed. set incsearch " Enable syntax highlighting highlight DiffAdd cterm=none ctermfg=Black ctermbg=Green gui=none guifg=Black guibg=Green highlight DiffDelete cterm=none ctermfg=Black ctermbg=Red gui=none guifg=Black guibg=Red highlight DiffChange cterm=none ctermfg=Black ctermbg=Yellow gui=none guifg=Black guibg=Yellow highlight DiffText cterm=none ctermfg=Black ctermbg=Magenta gui=none guifg=Black guibg=Magenta " Display tabs and trailing spaces visually set list set listchars=tab:>-,trail:ยท " In many terminal emulators the mouse works just fine, thus enable it. if has('mouse') " set mouse=n endif """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " vimdiff " " Turn on spell check. if &diff "turn off spelling set nospell " ignore whitespaces set diffopt+=iwhite endif """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " TODO: review " " One such option is the 'hidden' option, which allows you to re-use the same " window and switch from an unsaved buffer without saving it first. Also allows " you to keep an undo history for multiple files when re-using the same window " in this way. Note that using persistent undo also lets you undo in multiple " files even in the same window, but is less efficient and is actually designed " for keeping undo history after closing Vim entirely. Vim will complain if you " try to quit without saving, and swap files will keep you safe if your computer " crashes. if exists('&hidden') set hidden endif " Set fold method if supported if has('folding') set nofoldenable set foldmethod=indent "fold based on indent set foldnestmax=3 set foldminlines=4 set foldlevel=1 set foldcolumn=2 " foldcolumn is width 2 if has("autocmd") autocmd FileType vim setlocal foldmethod=marker autocmd FileType c setlocal foldmethod=syntax autocmd FileType h setlocal foldmethod=syntax autocmd FileType cpp setlocal foldmethod=syntax endif endif " Only do this part when compiled with support for autocommands. if has('autocmd') " Enable file type detection. " Use the default filetype settings, so that mail gets 'tw' set to 72, " 'cindent' is on in C files, etc. " Also load indent files, to automatically do language-dependent indenting. filetype plugin indent on " start with all folds open au BufRead,BufNewFile,BufWinEnter * normal zR " highlight lone colon characters highlight WarnChar ctermbg=yellow ctermfg=red guibg=#FFCC33 guifg=#FF0000 "apply highlight when opening a file, changing text (N or I), or opening a split au BufRead,InsertCharPre *.cpp 2mat WarnChar /\w\+;\?:;\?\w\+/ " Put these in an autocmd group, so that we can delete them easily. augroup vimrcEx au! " When editing a file, always jump to the last known cursor position. " Don't do it when the position is invalid or when inside an event handler " (happens when dropping a file on gvim). " Also don't do it when the mark is in the first line, that is the default " position when opening a file. autocmd BufReadPost * \ if line("'\"") > 1 && line("'\"") <= line("$") | \ exe "normal! g`\"" | \ endif augroup END endif " has("autocmd") """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Commands " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Key Mappings " " " if has('gui_running') ":tab drop {file} " Hide show menu and toolbar. map :if &guioptions =~# 'm' \set guioptions-=m \set guioptions-=T \set showtabline=0 \else \set guioptions+=m \set guioptions+=T \set showtabline=1 \endif endif " open ctag definition in new tab map :tab split:exec("tag ".expand("")) " Create a new tab. "map :tabnew " " Grep the word under cursor. " " Grep options affect GNU grep. The intend is that greps not supporting the " options will continue working without options. " let $GREP_OPTIONS.=' --exclude-dir=.git --exclude-dir=.svn --exclude-dir=.hg' let $GREP_OPTIONS.=' --exclude=tags --exclude=*.o --exclude=*.log' let $GREP_OPTIONS.=' --exclude=*.swp' let $GREP_OPTIONS.=' --exclude-dir=llcalc* --exclude-dir=00*' "let $GREP_OPTIONS.=' --include *.sh' "let $GREP_OPTIONS.=' --include *.php' "let $GREP_OPTIONS.=' --include *.h --include *.cpp --include *.c' "let $GREP_OPTIONS.=' --include *.py' "let $GREP_OPTIONS.=' --include *.java' "let $GREP_OPTIONS.=' --include *.f' "let $GREP_OPTIONS.=' --include *.xsd --include *.xml' "let $GREP_OPTIONS.=' --include Makefile' map af :execute "grep! ".expand("")." -r ." cw " " CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo, " so that you can undo CTRL-U after inserting a line break. " inoremap u " " Move through wrapped lines instead of buffer lines. " noremap gk noremap gj "imap gk "imap gj " " Working with tabs especially if using console version. " " nnoremap th :tabfirst " nnoremap tj :tabnext " nnoremap tk :tabprev " nnoremap tl :tablast " nnoremap tm :tabm " nnoremap td :tabclose """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Plugins " if filereadable(expand("~/.vim/autoload/plug.vim")) " Specify a directory for plugins " - For Neovim: stdpath('data') . '/plugged' " - Avoid using standard Vim directory names like 'plugin' call plug#begin('~/.vim/plugged') " " Adds nice status and tabline. " Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes' let g:airline#extensions#tabline#enabled = 1 let g:airline#extensions#tabline#left_sep = ' ' let g:airline#extensions#tabline#left_alt_sep = '|' let g:airline_powerline_fonts = 1 " Plug 'scrooloose/nerdtree' let g:NERDTreeQuitOnOpen = 1 let g:NERDTreeDirArrows = 1 let g:NERDTreeDirArrowExpandable = '+' let g:NERDTreeDirArrowCollapsible = '-' let g:NERDTreeIgnore = ['\.o$', '\.so$', '\.tsk$'] map at :NERDTreeToggle "map am :NERDTreeFind " " Commented out in favour of NERDTree " "Plug 'eiginn/netrw' "let g:netrw_altv = 1 "let g:netrw_fastbrowse = 2 "let g:netrw_keepdir = 0 "let g:netrw_liststyle = 3 "let g:netrw_retmap = 1 "let g:netrw_silent = 1 "let g:netrw_special_syntax= 1 "map :Explore "map :Explore %:p:h " " Manipulation with buffers and tabs. " Plug 'vim-scripts/Buffergator' let g:buffergator_autodismiss_on_select = 0 let g:buffergator_autoupdate = 1 let g:buffergator_suppress_keymaps = 1 let g:buffergator_viewport_split_policy = "L" map ab :BuffergatorToggle "map at :BuffergatorTabsToggle " " :A switches to the header file (or vise versa) " :AS splits and switches " :AV vertical splits and switches " :AT new tab and switches " :AN cycles through matches " :IH switches to file under cursor " :IHS splits and switches " :IHV vertical splits and switches " :IHT new tab and switches " :IHN cycles through matches " ih switches to file under cursor " is switches to the alternate file of file under " cursor (e.g. on switches to foo.cpp) " ihn cycles through matches " Plug 'vim-scripts/a.vim' let g:alternateExtensions_h = "cpp,c" let g:alternateExtensions_cpp = "h" let g:alternateExtensions_c = "h" map ah :A " " Tmux integration. " Plug 'benmills/vimux' " " Extends modeline to variables. " Needed by CF5 compile to read options right from file. " Plug 'vim-scripts/let-modeline.vim' " " CF5 compile. " Compiling cpp files without make file. " Plug 'vishap/cf5-compile' map ac :call CF5CompileOnly() map ar :call CF5CompileAndRun() " " Provide templates " Plug 'aperezdc/vim-template' "let g:templates_no_autocmd = 1 let g:templates_no_builtin_templates = 1 " " Local vimrc " Plug 'embear/vim-localvimrc' let g:localvimrc_name = [ ".vimrc.local" ] let g:localvimrc_ask = 0 " " Comment code. " gc - visual mode - comment selection. " Plug 'tpope/vim-commentary' Plug 'tpope/vim-surround' " Plug 'tpope/vim-repeat' nmap al CommentaryLine vmap al Commentary " " Git wrapper. " Plug 'tpope/vim-fugitive' " nmap git :Git " nmap gst :Gstatus " " Shows git diff. " [c - jump prev diff " ]c - jump nex diff " hs - stage the hunk " hr - revert the hunk " :GitGutterNextHunk " :GitGutterPrevHunk " :GitGutterStageHunk " :GitGutterRevertHunk " :GitGutterToggle " :GitGutterLineHighlightsToggle " Plug 'airblade/vim-gitgutter' let g:gitgutter_map_keys = 0 let g:gitgutter_realtime = 0 let g:gitgutter_eager = 0 let g:gitgutter_async = 1 " " Check syntaxis on fly. " "Plug 'scrooloose/syntastic' "let g:syntastic_cpp_compiler_options = ' -std=c++1y' "let g:syntastic_mode_map = { " \ "mode": "active", " \ "active_filetypes": ["ruby", "php"], " \ "passive_filetypes": ["c", "cpp"] } " " Nice colorschemes. " Actual colorscheme is set outside as vundle resets it. " if &t_Co >= 256 || has('gui_running') Plug 'nanotech/jellybeans.vim' let g:jellybeans_use_lowcolor_black = 0 let g:jellybeans_use_gui_italics = 0 "colorscheme jellybeans endif " " :set syntax=cpp.doxygen to highlight doxygen comments. " Plug 'vim-scripts/DoxyGen-Syntax' " " In vim, place the cursor on the line and " :DoxLic - generates license comment. " :DoxAuthor - skeleton and leave the cursor just after @author tag. " :Dox - generates function/class comment. " :DoxUndoc(DEBUG) - if you want to ignore all code fragment ifdefed with " DEBUG. " :DoxBlock - " Plug 'vim-scripts/DoxygenToolkit.vim' " " Color table and picker. " :XtermColorTable " press: # to yank, t to toggle, f to set text color " "Plug 'xterm-color-table.vim' " Promising GDB manager. " Plug 'vim-scripts/gdbmgr' " Completion " Plug 'neoclide/coc.nvim', {'branch': 'release'} " See configuration below Plug 'w0rp/ale' " Set up hack support through vim-hack and ale let g:ale_hack_hack_executable = 'hh' let g:ale_linters = { 'hack': ['hack', 'aurora'] } let g:ale_echo_msg_format = '[%linter%]% [code]% %s' " Set up haskell support though ale " Some suggestions oh how it works. " First start haxlsh with `haxlsh --lsp` " Then start `sigma_lsp` (proxy for the LSP client) " Load the module in haxlsh and voila " Some wiki: https://fburl.com/wiki/grt9tzi1 let g:ale_haskell_hie_executable = 'sigma_lsp' " let g:ale_haskell_hie_executable = '/home/nedyalkop/nedy_sigma_lsp' let g:ale_haskell_hdevtools_options = '' " Set up IDE type bindings with ALE nnoremap K :ALEHover nnoremap . :ALEGoToDefinition nnoremap fr :ALEFindReferences Plug 'hhvm/vim-hack' Plug 'raichoo/haskell-vim' endif call plug#end() " " Vundle resets this if set inside vundle section. " if &t_Co >= 256 || has('gui_running') colorscheme jellybeans hi clear SpellBad hi SpellBad cterm=underline, ctermfg=red endif if exists("dddd") "Plug 'Rip-Rip/clang_complete' "Plug 'flazz/vim-colorschemes' "Plug 'Valloric/YouCompleteMe' "Plug 'rhysd/vim-clang-format' Plug 'vim-scripts/Mark' Plug 'danro/rename.vim' Plug 'kana/vim-operator-user' Plug 'kien/ctrlp.vim' let g:ctrlp_root_markers = ['.ctrlp'] let g:ctrlp_custom_ignore = { \ 'file': '\v\.(o|d|dd)$', \ } Plug 'majutsushi/tagbar' map :TagbarToggle let g:tagbar_autoclose = 1 let g:tagbar_autofocus = 1 let g:tagbar_autoshowtag = 1 let g:tagbar_compact = 1 let g:tagbar_indent = 1 let g:tagbar_sort = 1 let g:tagbar_width = 60 let g:tagbar_ctags_bin = "/opt/swt/bin/ctags" Plug 'mattn/emmet-vim' Plug 'tmhedberg/matchit' Plug 'tpope/vim-dispatch' Plug 'tpope/vim-unimpaired' Plug 'vim-scripts/Align' Plug 'vim-scripts/taglist.vim' Plug 'vim-scripts/xml.vim' Plug 'junegunn/vim-easy-align' Plug 'ntpeters/vim-better-whitespace' let g:strip_whitespace_on_save = 1 "Plug 'vim-scripts/TagHighlight' "Plug 'gcmt/taboo.vim' "let g:taboo_tab_format = "[%m:%N:%W] %f" " - - - - - - - - - - - - - - " powerline " - - - - - - - - - - - - - - let g:Powerline_symbols = "unicode" " Ack Plug 'mileszs/ack.vim' let g:ack_default_options = " --ignore-file=is:tags -s -H --nocolor --nogroup --column" let g:ack_highlight = 1 endif "------------------------------------------------------------ " COC configuration " if 1 " if hidden is not set, TextEdit might fail. " set hidden " Some servers have issues with backup files, see #649 " set nobackup " set nowritebackup " Better display for messages " set cmdheight=2 " You will have bad experience for diagnostic messages when it's default 4000. set updatetime=300 " don't give |ins-completion-menu| messages. " set shortmess+=c " always show signcolumns set signcolumn=yes " Use tab for trigger completion with characters ahead and navigate. " Use command ':verbose imap ' to make sure tab is not mapped by other plugin. inoremap \ pumvisible() ? "\" : \ check_back_space() ? "\" : \ coc#refresh() inoremap pumvisible() ? "\" : "\" function! s:check_back_space() abort let col = col('.') - 1 return !col || getline('.')[col - 1] =~# '\s' endfunction " Use to trigger completion. inoremap coc#refresh() " Use to confirm completion, `u` means break undo chain at current position. " Coc only does snippet and additional edit on confirm. inoremap pumvisible() ? "\" : "\u\" " Use `[c` and `]c` to navigate diagnostics nmap [c (coc-diagnostic-prev) nmap ]c (coc-diagnostic-next) " Remap keys for gotos nmap gd (coc-definition) nmap gy (coc-type-definition) nmap gi (coc-implementation) nmap gr (coc-references) " Use K to show documentation in preview window nnoremap K :call show_documentation() function! s:show_documentation() if (index(['vim','help'], &filetype) >= 0) execute 'h '.expand('') else call CocAction('doHover') endif endfunction " Highlight symbol under cursor on CursorHold autocmd CursorHold * silent call CocActionAsync('highlight') " Remap for rename current word nmap rn (coc-rename) " Remap for format selected region xmap f (coc-format-selected) nmap f (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 " Remap for do codeAction of selected region, ex: `aap` for current paragraph xmap a (coc-codeaction-selected) nmap a (coc-codeaction-selected) " Remap for do codeAction of current line nmap ac (coc-codeaction) " Fix autofix problem of current line nmap qf (coc-fix-current) " Use for select selections ranges, needs server support, like: coc-tsserver, coc-python nmap (coc-range-select) xmap (coc-range-select) xmap (coc-range-select-backword) " Use `:Format` to format current buffer command! -nargs=0 Format :call CocAction('format') " Use `:Fold` to fold current buffer command! -nargs=? Fold :call CocAction('fold', ) " use `:OR` for organize import of current buffer command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') " Add status line support, for integration with other plugin, checkout `:h coc-status` set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')} " Using CocList " Show all diagnostics nnoremap a :CocList diagnostics " Manage extensions nnoremap e :CocList extensions " Show commands nnoremap c :CocList commands " Find symbol of current document nnoremap o :CocList outline " Search workspace symbols nnoremap s :CocList -I symbols " Do default action for next item. nnoremap j :CocNext " Do default action for previous item. nnoremap k :CocPrev " Resume latest coc list nnoremap p :CocListResume endif