|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- call plug#begin('~/.vim/plugged')
-
- "{{ The Basics }}
- Plug 'joshdick/onedark.vim' " Colors
- Plug 'itchyny/lightline.vim' " Lightline statusbar
- "{{ File management }}
- Plug 'scrooloose/nerdtree' " Nerdtree
- Plug 'tiagofumo/vim-nerdtree-syntax-highlight' " Highlighting Nerdtree
- Plug 'ryanoasis/vim-devicons' " Icons for Nerdtree
- "{{ Syntax Highlighting and Colors }}
- Plug 'ap/vim-css-color' " Color previews for CSS
- "{{ Junegunn Choi Plugins }}
- Plug 'junegunn/limelight.vim' " Hyperfocus on a range
- Plug 'junegunn/fzf.vim'
- "{{ C++ development }}
- Plug 'neoclide/coc.nvim', {'branch': 'release'}
- Plug 'jackguo380/vim-lsp-cxx-highlight'
- Plug 'vim-syntastic/syntastic'
- Plug 'rhysd/vim-clang-format'
- Plug 'lambdalisue/suda.vim'
- call plug#end()
-
- " for transparent background
- function! AdaptColorscheme()
- highlight clear CursorLine
- highlight Normal ctermbg=none
- highlight LineNr ctermbg=none
- highlight Folded ctermbg=none
- highlight NonText ctermbg=none
- highlight SpecialKey ctermbg=none
- highlight VertSplit ctermbg=none
- highlight SignColumn ctermbg=none
- endfunction
-
- autocmd ColorScheme * call AdaptColorscheme()
-
-
- set cursorline
-
- " colorscheme
- syntax on
-
- " brackets
- inoremap " ""<left>
- inoremap ' ''<left>
- inoremap ( ()<left>
- inoremap [ []<left>
- inoremap { {}<left>
- inoremap {<CR> {<CR>}<ESC>O
- inoremap {;<CR> {<CR>};<ESC>O
-
- filetype plugin on
- let g:instant_markdown_browser = "firefox --new-window"
-
- " Make Vim more useful
- set nocompatible
- " Long lines as one line
- set nowrap
- " Ruler
- set ruler
- " Horizontal splits will automatically be below
- set splitbelow
- " Vertical splits will automatically be to the right
- set splitright
- " Indent
- set smartindent
- set autoindent
- " Use the OS clipboard by default (on versions compiled with `+clipboard`)
- set clipboard+=unnamedplus
- " Enhance command-line completion
- set wildmenu
- " Disables automatic commenting on newline:
- autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
- " Allow cursor keys in insert mode
- " Allow backspace in insert mode
- set backspace=indent,eol,start
- " Optimize for fast terminal connections
- set ttyfast
- " Add the g flag to search/replace by default
- set gdefault
- " Use UTF-8 without BOM
- set encoding=utf-8
- " Change mapleader
- let mapleader=","
- " Don’t add empty newlines at the end of files
- set binary
- set noeol
- set smartcase
- set noswapfile
- set nobackup
- set undodir=~/.vim/undodir
- set undofile
-
- " 256 colors
- set t_Co=256
- " Respect modeline in files
- set modeline
- set modelines=4
- " Enable per-directory .vimrc files and disable unsafe commands in them
- set exrc
- set secure
- " Enable line numbers
- set number
- " Make tabs as wide as two spaces
- set tabstop=4
- set shiftwidth=4
- set smarttab
- set expandtab
- " Highlight searches
- set hlsearch
- " Ignore case of searches
- set ignorecase
- " Highlight dynamically as pattern is typed
- set incsearch
- " Always show status line
- set laststatus=2
- " Enable mouse in all modes
- set mouse=a
- " Disable error bells
- set noerrorbells
- " Don’t reset cursor to start of line when moving around.
- set nostartofline
- " Show the cursor position
- set ruler
- " Don’t show the intro message when starting Vim
- set shortmess=atI
- " Show the current mode
- set showmode
- " Show the filename in the window titlebar
- set title
- " Show the (partial) command as it’s being typed
- set showcmd
- " Use relative line numbers
-
- " For C++ plugins
- set hidden
- set nobackup
- set nowritebackup
- set updatetime=300
- set shortmess+=c
-
- " Give more space for displaying messages.
- set cmdheight=2
- set pumheight=5
-
- " Always show the signcolumn, otherwise it would shift the text each time
- " diagnostics appear/become resolved.
- if has("nvim-0.5.0") || has("patch-8.1.1564")
- " Recently vim can merge signcolumn and number column into one
- set signcolumn=number
- else
- set signcolumn=yes
- endif
-
- 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.
- if has('nvim')
- inoremap <silent><expr> <c-return> coc#refresh()
- else
- inoremap <silent><expr> <c-@> coc#refresh()
- endif
-
- " 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)
-
- " 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)
-
- " 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
-
-
- " 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')
-
- let g:lightline = {
- \ 'colorscheme': 'onedark',
- \ 'active': {
- \ 'left': [ [ 'mode', 'paste' ],
- \ [ 'cocstatus', 'readonly', 'filename', 'modified' ] ]
- \ },
- \ 'component_function': {
- \ 'cocstatus': 'coc#status'
- \ },
- \ }
-
- " Use autocmd to force lightline update.
- autocmd User CocStatusChange,CocDiagnosticChange call lightline#update()
-
- " 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>
-
- " c++ syntax highlighting
- let g:cpp_class_scope_highlight = 1
- let g:cpp_member_variable_highlight = 1
- let g:cpp_class_decl_highlight = 1
-
- " c++ linting
- let g:syntastic_cpp_checkers = ['cpplint']
- let g:syntastic_c_checkers = ['cpplint']
- let g:syntastic_cpp_cpplint_exec = 'cpplint'
- " The following two lines are optional. Configure it to your liking!
- let g:syntastic_check_on_open = 1
- let g:syntastic_check_on_wq = 0
-
- nnoremap <Leader>f :<C-u>ClangFormat<CR>
-
- " header guards
- function! s:insert_gates()
- let gatename = substitute(toupper(expand("%:t")), "\\.", "_", "g")
- execute "normal! i#ifndef " . gatename
- execute "normal! o#define " . gatename . " "
- execute "normal! Go#endif /* " . gatename . " */"
- normal! ko
- endfunction
- autocmd BufNewFile *.{h,hpp} call <SID>insert_gates()
-
- if exists("&relativenumber")
- set relativenumber
- au BufReadPost * set relativenumber
- endif " Start scrolling three lines before the horizontal window border
- set scrolloff=3
-
- " Toggle spellchecking
- function! ToggleSpellCheck()
- set spell!
- if &spell
- echo "Spellcheck ON"
- else
- echo "Spellcheck OFF"
- endif
- endfunction
-
-
- " Better tabbing
- vnoremap < <gv
- vnoremap > >gv
-
- " Better window navigation
- nnoremap <C-h> <C-w>h
- nnoremap <C-j> <C-w>j
- nnoremap <C-k> <C-w>k
- nnoremap <C-l> <C-w>l
-
- map <Leader>c :w! \| !make <CR>
- map <Leader>r <c-w>v <c-w>l :terminal ./run.sh <c-r>% <CR>a
- map <Leader>t :!st&<CR><CR>
- map <Leader>o :FZF<CR>
- map <Leader>s :call ToggleSpellCheck()<CR>
- map <Leader>n :NERDTreeToggle<CR>
- map Q gq
- " Insert mode completion
- imap <c-x><c-k> <plug>(fzf-complete-word)
- imap <c-x><c-f> <plug>(fzf-complete-path)
- imap <c-x><c-l> <plug>(fzf-complete-line)
- vnoremap <C-c> "+y
-
- " Write as root
- cnoremap w!! SudaWrite
-
- colorscheme onedark
|