"""" Vim Cscope quick guide " Integrated Cscope tutorial see, " https://cscope.sourceforge.net/cscope_vim_tutorial.html " """" C-Scope Commands " At top of directory build cscope database with 'cscope -Rb' " Then open vim and run :set csre to allow for autochdir to work " Three lead control options ... " command ... will run command in the same window " command ... will run command in a split horizontal window " command ... will run command in a split vertical window " Commands (all apply to text under cursor), " s : find all uses of symbol X " g : find global definitions(s) of symbol " c : find all calls to a function " f : opens the filename " """" Table Mode " table creator tm to toggle mode on and off " Create New Table by starting with | " use || to create the table header boundary (underneath column titles) " use || to complete a table above the header boundary (when complete with the " table) " use tic to insert a new column " use tdc to delete a column " navigate cells " [| move left " |] move right " {| move up " |} move down """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" let mapleader ="-" call plug#begin('~/.vim/plugged') Plug 'tpope/vim-commentary' " press gcc to auto comment a line Plug 'tpope/vim-repeat' " makes . work better with plugins Plug 'tpope/vim-surround' " surrounds text in (), [], quotes, etc. Plug 'tpope/vim-fugitive' " git wrapper Plug 'vim-airline/vim-airline' " status bar Plug 'kshenoy/vim-signature' " show mark ids left of line number Plug 'morhetz/gruvbox' " colorscheme Plug 'amal-khailtash/vim-xdc-syntax' " xdc syntax Plug 'vhda/verilog_systemverilog.vim' " system verilog Plug 'gutelfuldead/vim-tex-fold' " fork from matze/vim-tex-fold add chapter, sub&subsub section support Plug 'dhruvasagar/vim-table-mode' " allows for automatic table creation in rst/md Plug 'mbbill/undotree' " Creates tree for undo bound to F6 call plug#end() " Some basics: set nocompatible filetype plugin on syntax on set encoding=utf-8 set number set viminfofile=NONE set hlsearch set incsearch set ignorecase " case insensitivity when searching set smartcase " re enables case sensitivity when pattern has upper case set cursorline " set relativenumber set expandtab set shiftwidth=4 set tabstop=4 set autochdir set csre " set autoindent set wildmode=longest,list,full set wildmenu let g:netrw_banner=0 set tags=cscope.out " Linux settings fun! SetLinuxKernelIndentStyle() setlocal noexpandtab shiftwidth=8 tabstop=8 softtabstop=8 endfun " Remove all whitespace from end of a line fun! TrimWhitespace() let l:save = winsaveview() keeppatterns %s/\s\+$//e call winrestview(l:save) endfun " Use t for C/C++ files to run :Dox autocmd FileType c,cpp nnoremap t :Dox " F2 toggle linenumbers noremap :set invnumber " F3 toggle to paste mode (assumes relativenumber IS set, use F2 to get there) nnoremap :set invpaste " F4 toggle auto change directory, useful to disable for cscope noremap :set invautochdir " F5 to trim all white space in a file noremap :call TrimWhitespace() " F6 toggle UndoTree nnoremap :UndotreeToggle " F7 retab noremap :retab " place swap files and others in a common directory set backupdir=~/.vim/backup// set directory=~/.vim/swap// " Instead of noesckeys use this so arrows can still be used in insert mode set timeout " timeout on partial command like: , g, etc. set tm=1000 " timeoutlen is 1 second set ttimeout " have separate value for timeout re: leaving insert mode set ttimeoutlen=0 " insert / visual timeout immediately " Theme set background=dark if v:version == 802 colorscheme industry else let g:gruvbox_contrast_dark = 'hard' colorscheme gruvbox endif " remap ESC to jk because my pinky is fucked inoremap jk " Splits open at the bottom and right, instead of the stupid default set splitbelow set splitright " keep search results at the center of the screen nnoremap n nzz nnoremap N Nzz " Tab shortcuts map te :tabedit map tn :tabnext map tx :tabclose " Run Black on the current file " Install on PC with `pip install black` command! Black write | execute '!python3 -m black %' | edit! " Press Enter to remove search highlights noremap :noh " Press r to resource ~/.vimrc noremap r :source ~/.vimrc " Get RST style tables let g:table_mode_corner_corner='+' let g:table_mode_header_fillchar='=' " set service file syntac autocmd BufNewFile,BufRead *.service set ft=systemd " set comment string for vhdl files to work with vim-commentary autocmd FileType vhdl setlocal commentstring=--\ %s " set comment string for conf files autocmd FileType conf setlocal commentstring=#\ %s " set comment string for xdc files autocmd FileType xdc setlocal commentstring=#\ %s " Interpret _defconfig,config files as conf autocmd BufNewFile,BufRead *_defconfig,*.defconfig,*.config set syntax=conf " set comment string for conf files autocmd FileType defconfig setlocal commentstring=#\ %s " Interpret ITS files as device tree autocmd BufNewFile,BufRead *.its set syntax=dts " interpret markdown files autocmd BufNewFile,BufRead *.md set filetype=markdown " .tex files automatically detected autocmd BufRead,BufNewFile *.tex set filetype=tex let g:tex_flavor='latex' let g:Tex_DefaultTargetFormat='pdf' au! BufRead,BufNewFile *.cls setfiletype tex au! BufRead,BufNewFile *.lco setfiletype tex " open pdf preview of latex (latex preview) noremap llp :LLPStartPreview " .bash* files automatically detected autocmd BufRead,BufNewFile *.bash* set filetype=sh autocmd BufRead,BufNewFile *.d set filetype=sh " autodetect xilinx constraints (.xdc) autocmd BufNewFile,BufRead *.xdc setfiletype xdc " Readmes autowrap text " autocmd BufRead,BufNewFile README.* set tw=79 " Always make TODO highlight as an error (red) match Error "TODO" " Spell-check (underline misspelled words in md,rst files) hi clear SpellBad hi SpellBad cterm=underline " ignore case for spellcheck set spellcapcheck= set spelllang=en_us set spellfile=$HOME/.spellen.utf-8.add autocmd BufRead,BufNewFile *.md setlocal spell autocmd BufRead,BufNewFile *.rst setlocal spell autocmd BufRead,BufNewFile *.tex setlocal spell " next misspelled word map sn ]s " previous misspelled word map sp [s " accept spelling as good word and update dictionary map sa zg " suggest alternate spellings map s? z= " when in inset mode ctrl+l to go back and auto-accept spelling suggestions inoremap u[s1z=`]au " resize current buffer by +/- 5 noremap :vertical resize +5 noremap :resize -5 noremap :resize +5 noremap :vertical resize -5 " Set diff mode to ignore whitespace if &diff set diffopt+=iwhite endif " Automatically retab on save " autocmd BufWritePre * retab " Automatically deletes all trailing whitespace on save " autocmd BufWritePre * %s/\s\+$//e " Automatically run clang-format when using gg=G " autocmd FileType c,cpp setlocal equalprg=clang-format " Disables automatic commenting on newline " autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o " Use word wrapping in vimdiff autocmd FilterWritePre * if &diff | setlocal wrap< | endif " Allows to see diff in current file before saving with :diffSaved function! s:DiffWithSaved() let filetype=&ft diffthis vnew | r # | normal! 1Gdd diffthis exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype endfunction com! DiffSaved call s:DiffWithSaved() " Allows to see diff between current file and git function! s:DiffWithGITCheckedOut() let filetype=&ft diffthis vnew | exe "%!git diff " . fnameescape( expand("#:p") ) . " | patch -p 1 -Rs -o -" exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype diffthis wincmd R endfunction com! GitDiff call s:DiffWithGITCheckedOut() " Add directory for persistent undo files if has("persistent_undo") let target_path = expand('~/.vim/undodir') " create the directory and any parent directories " if the location does not exist. if !isdirectory(target_path) call mkdir(target_path, "p", 0700) endif let &undodir=target_path set undofile endif