├── README.md ├── coc-settings.json ├── cocrc.vim ├── cp.vim └── init.vim /README.md: -------------------------------------------------------------------------------- 1 | # vim-and-cp 2 | 3 | Some helpful bits and pieces for your vimrc 4 | 5 | ## compiling 6 | 7 | ```vim 8 | :CompileAndRun 9 | ``` 10 | 11 | Using a file as input, for example `input.txt` 12 | 13 | ```vim 14 | :CompileAndRunWithFile "input.txt" 15 | ``` 16 | 17 | To compile and run separately, you can use the following command definitions: 18 | 19 | ```vim 20 | command! -nargs=0 Compile call TermWrapper(printf('g++ -std=c++11 %s', expand('%'))) 21 | command! -nargs=0 Run call TermWrapper('./a.out') 22 | ``` 23 | 24 | These commands can be mapped to keys of your choice, for example: 25 | 26 | ```vim 27 | autocmd FileType cpp nnoremap fw :CompileAndRun 28 | ``` 29 | 30 | ## options 31 | 32 | Choose between 'vertical' and 'horizontal' for how the terminal window is split 33 | (default is vertical) 34 | 35 | ```vim 36 | let g:split_term_style = 'horizontal' 37 | ``` 38 | 39 | Add a custom command to resize the terminal window to your preference 40 | (default is to split the screen equally) 41 | 42 | ```vim 43 | let g:split_term_resize_cmd = 'resize 6' 44 | ``` 45 | -------------------------------------------------------------------------------- /coc-settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "suggest.enablePreselect": true, 3 | "suggest.noselect": false, 4 | "python.jediEnabled": false, 5 | "clangd.path": "/usr/bin/clangd", 6 | "diagnostic.displayByAle": true 7 | } 8 | -------------------------------------------------------------------------------- /cocrc.vim: -------------------------------------------------------------------------------- 1 | " coc {{{ 2 | 3 | set cmdheight=2 updatetime=0 4 | 5 | " Don't pass messages to |ins-completion-menu|. 6 | set shortmess+=c 7 | 8 | " Always show the signcolumn, otherwise it would shift the text each time 9 | " diagnostics appear/become resolved. 10 | if has("patch-8.1.1564") 11 | " Recently vim can merge signcolumn and number column into one 12 | set signcolumn=number 13 | else 14 | set signcolumn=yes 15 | endif 16 | 17 | " Use to trigger completion. 18 | if has('nvim') 19 | inoremap coc#refresh() 20 | else 21 | inoremap coc#refresh() 22 | endif 23 | 24 | " Use `[g` and `]g` to navigate diagnostics 25 | " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list. 26 | nmap [g (coc-diagnostic-prev) 27 | nmap ]g (coc-diagnostic-next) 28 | 29 | " GoTo code navigation. 30 | nmap gd (coc-definition) 31 | nmap gy (coc-type-definition) 32 | nmap gi (coc-implementation) 33 | nmap gr (coc-references) 34 | 35 | " Use K to show documentation in preview window. 36 | nnoremap K :call show_documentation() 37 | 38 | function! s:show_documentation() 39 | if (index(['vim','help'], &filetype) >= 0) 40 | execute 'h '.expand('') 41 | else 42 | call CocAction('doHover') 43 | endif 44 | endfunction 45 | 46 | autocmd CursorHold * silent call CocActionAsync('highlight') 47 | 48 | augroup CocStuff 49 | autocmd! 50 | autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') 51 | augroup end 52 | 53 | 54 | xmap if (coc-funcobj-i) 55 | omap if (coc-funcobj-i) 56 | xmap af (coc-funcobj-a) 57 | omap af (coc-funcobj-a) 58 | xmap ic (coc-classobj-i) 59 | omap ic (coc-classobj-i) 60 | xmap ac (coc-classobj-a) 61 | omap ac (coc-classobj-a) 62 | 63 | nmap (coc-range-select) 64 | xmap (coc-range-select) 65 | 66 | command! -nargs=0 Format :call CocAction('format') 67 | command! -nargs=? Fold :call CocAction('fold', ) 68 | command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') 69 | 70 | nnoremap cc :CocList commands 71 | nnoremap cd :CocList diagnostics 72 | nnoremap ce :CocList extensions 73 | nnoremap cj :CocNext 74 | nnoremap ck :CocPrev 75 | nnoremap co :CocList outline 76 | nnoremap cp :CocListResume 77 | nnoremap cs :CocList -I symbols 78 | nmap cr (coc-rename) 79 | 80 | xmap cf (coc-format-selected) 81 | nmap cf (coc-format-selected) 82 | xmap ca (coc-codeaction-selected) 83 | nmap ca (coc-codeaction-selected) 84 | nmap cac (coc-codeaction) 85 | nmap cq (coc-fix-current) 86 | " }}} 87 | -------------------------------------------------------------------------------- /cp.vim: -------------------------------------------------------------------------------- 1 | " for detecting OS 2 | if !exists("g:os") 3 | if has("win64") || has("win32") || has("win16") 4 | let g:os = "Windows" 5 | else 6 | let g:os = substitute(system('uname'), '\n', '', '') 7 | endif 8 | endif 9 | 10 | " important option that should already be set! 11 | set hidden 12 | 13 | " available options: 14 | " * g:split_term_style 15 | " * g:split_term_resize_cmd 16 | function! TermWrapper(command) abort 17 | if !exists('g:split_term_style') | let g:split_term_style = 'vertical' | endif 18 | if g:split_term_style ==# 'vertical' 19 | let buffercmd = 'vnew' 20 | elseif g:split_term_style ==# 'horizontal' 21 | let buffercmd = 'new' 22 | else 23 | echoerr 'ERROR! g:split_term_style is not a valid value (must be ''horizontal'' or ''vertical'' but is currently set to ''' . g:split_term_style . ''')' 24 | throw 'ERROR! g:split_term_style is not a valid value (must be ''horizontal'' or ''vertical'')' 25 | endif 26 | exec buffercmd 27 | if exists('g:split_term_resize_cmd') 28 | exec g:split_term_resize_cmd 29 | endif 30 | exec 'term ' . a:command 31 | exec 'setlocal nornu nonu' 32 | exec 'startinsert' 33 | autocmd BufEnter startinsert 34 | endfunction 35 | 36 | command! -nargs=0 CompileAndRun call TermWrapper(printf('g++ -std=c++11 %s && ./a.out', expand('%'))) 37 | command! -nargs=1 -complete=file CompileAndRunWithFile call TermWrapper(printf('g++ -std=c++11 %s && ./a.out < %s', expand('%'), )) 38 | autocmd FileType cpp nnoremap fw :CompileAndRun 39 | 40 | " For those of you that like to use the default ./a.out 41 | " This C++ toolkit gives you commands to compile and/or run in different types 42 | " of terminals for your own preference. 43 | " NOTE: this version is more stable than the other version with specified 44 | " output executable! 45 | augroup CppToolkit 46 | autocmd! 47 | if g:os == 'Darwin' 48 | autocmd FileType cpp nnoremap fn :!g++ -std=c++11 -o %:r % && open -a Terminal './a.out' 49 | endif 50 | autocmd FileType cpp nnoremap fb :!g++ -std=c++11 % && ./a.out 51 | autocmd FileType cpp nnoremap fr :!./a.out 52 | autocmd FileType cpp nnoremap fw :CompileAndRun 53 | augroup END 54 | 55 | " For those of you that like to use -o and a specific outfile executable 56 | " (i.e., xyz.cpp makes executable xyz, as opposed to a.out 57 | " This C++ toolkit gives you commands to compile and/or run in different types 58 | " of terminals for your own preference. 59 | augroup CppToolkit 60 | autocmd! 61 | if g:os == 'Darwin' 62 | autocmd FileType cpp nnoremap fn :!g++ -std=c++11 -o %:r % && open -a Terminal './%:r' 63 | endif 64 | autocmd FileType cpp nnoremap fb :!g++ -std=c++11 -o %:r % && ./%:r 65 | autocmd FileType cpp nnoremap fr :!./%:r.out 66 | augroup END 67 | 68 | " options 69 | " choose between 'vertical' and 'horizontal' for how the terminal window is split 70 | " (default is vertical) 71 | let g:split_term_style = 'horizontal' 72 | 73 | " add a custom command to resize the terminal window to your preference 74 | " (default is to split the screen equally) 75 | let g:split_term_resize_cmd = 'resize 6' 76 | " (or let g:split_term_resize_cmd = 'vertical resize 40') 77 | -------------------------------------------------------------------------------- /init.vim: -------------------------------------------------------------------------------- 1 | " 2 | " init.vim 3 | " 4 | 5 | " using vim-plug 6 | call plug#begin('~/.config/nvim/plugged') 7 | 8 | Plug 'tpope/vim-commentary' 9 | 10 | Plug 'neoclide/coc.nvim', {'branch': 'release'} 11 | Plug 'honza/vim-snippets' 12 | Plug 'dense-analysis/ale' 13 | 14 | Plug 'tpope/vim-endwise' 15 | Plug 'rstacruz/vim-closer' 16 | 17 | call plug#end() 18 | 19 | set number hidden 20 | hi LineNr ctermfg=8 21 | 22 | tnoremap 23 | 24 | 25 | let mapleader=" " 26 | 27 | source ~/.config/nvim/cocrc.vim 28 | --------------------------------------------------------------------------------