commit 6743300e44e3b8328fc254d695faf61f65bd4ec8 Author: Paul Date: Wed Oct 16 10:28:30 2019 +0000 Add vimrc diff --git a/vimrc b/vimrc new file mode 100644 index 0000000..9c23327 --- /dev/null +++ b/vimrc @@ -0,0 +1,375 @@ +" Adapted from Dan's .vimrc, and Sven Gucke's vimrc.forall - Paul + +call plug#begin('~/.vim/plugged') + Plug 'junegunn/vim-easy-align/' + Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } + Plug 'junegunn/fzf.vim', + Plug 'pbogut/fzf-mru.vim', + Plug 'tpope/vim-fugitive' + Plug 'junegunn/gv.vim' + + Plug 'christoomey/vim-tmux-navigator' + Plug 'vim-airline/vim-airline' + + Plug 'scrooloose/nerdtree' + + " be sure to read full install instructions. this still needs + " you to cd ~/.vim/plugged/YouCompleteMe + " python ./install.py --js-completer + Plug 'Valloric/YouCompleteMe' + + Plug 'posva/vim-vue' + Plug 'ap/vim-css-color' + Plug 'pangloss/vim-javascript' + + Plug 'dense-analysis/ale' + Plug 'rust-lang/rust.vim' +call plug#end() + +let mapleader = ' ' +let maplocalleader = ' ' + +" Edit another file in the same directory as the current file. Uses expression +" to extract path from current file's path (thanks to Douglas Potts) +if has("unix") + map ,e :e =expand("%:p:h") . "/" +else + map ,e :e =expand("%:p:h") . "\\" +endif + +set backupdir=/tmp//,. +set directory=/tmp//,. +if v:version >= 703 + set backupdir=/tmp//,. +endif + +" TODO put in a file group +imap cll console.log()==f(a + +let g:tmux_navigator_no_mappings = 1 +let g:tmux_navigator_save_on_switch = 1 +" Disable tmux navigator when zooming the Vim pane +" let g:tmux_navigator_disable_when_zoomed = 1 + +nnoremap :TmuxNavigateLeft +nnoremap :TmuxNavigateDown +nnoremap :TmuxNavigateUp +nnoremap :TmuxNavigateRight +nnoremap :TmuxNavigatePrevious + +set ignorecase smartcase +set incsearch + +set complete=.,b,u,] + +set wildignore+=deps/*,*.sw? + +" set background=light +" source ~/.vim/colors/midnight.vim +color desert + +" enable syntax highlighting if it is supported +if has("syntax") + syntax on +endif + +" Turn off the beeping ('cause it's annoying) +set noerrorbells +set visualbell +set t_vb= + +" Auto-indent code +set autoindent + +" do not redraw the screen during macro execution +set lazyredraw + +" Open new panes to right and bottom. +set splitbelow +set splitright + +let g:tmux_navigator_no_mappings = 1 + +nnoremap :TmuxNavigateLeft +nnoremap :TmuxNavigateDown +nnoremap :TmuxNavigateUp +nnoremap :TmuxNavigateRight +nnoremap :TmuxNavigatePrevious + +" tabbing and indent options +function! TabSize (size) + if a:size==8 + set noexpandtab + else + set expandtab + endif + exe 'set shiftwidth=' . a:size + exe 'set tabstop=' . a:size + return "Tab size = " . a:size +endfunction +call TabSize(2) +map ,t2 :echo TabSize(2) +map ,t3 :echo TabSize(3) +map ,t4 :echo TabSize(4) +map ,t8 :echo TabSize(8) + +" treat C preprocessed assembler files as C +augroup filetype + au! + au BufRead,BufNewFile *.S set filetype=c + au BufRead,BufNewFile *.[ch]@@.+ set filetype=c + au bufRead,BufNewFile *.cc set filetype=cpp + au bufRead,BufNewFile *.cpp set filetype=cpp + " au BufRead,BufNewFile *.ex set filetype=elixir + " au BufRead,BufNewFile *.exs set filetype=elixir + au BufRead,BufNewFile *.eex set filetype=html +augroup END + +augroup cppprog + au! + au BufRead,BufNewFile *.h set cindent + au BufRead,BufNewFile *.cc set cindent + au BufRead,BufNewFile *.cpp set cindent +augroup END + +augroup dropbox + au! + au BufRead,BufNewFile ~/Dropbox/* set directory=~/tmp,/var/tmp,/tmp + au BufRead,BufNewFile Dropbox/* set directory=~/tmp,/var/tmp,/tmp + au BufRead,BufNewFile /home/paul/Dropbox/* set directory=~/tmp,/var/tmp,/tmp +augroup END + +" Turn C syntax on for C and header files +augroup cprog + au! + au BufRead,BufNewFile *.[ch] set cindent + " simulate C++ comments (sort of) and provide a means to uncomment easily + map // ^i/* $a */ + map \\ bhh/ *[*][/]d/[/]x?[/][*]dw + " Normal tabsizes + " call TabSize(4) +augroup END + +" Apply the muttrc colouring to mutt setup files: +au BufNewFile,BufRead .mutt.* set ft=muttrc + +" Automatic typo fixing +iab Cunt Count +iab cunt count +iab LOG_LVL_NOTIFY LOG_LVL_NOTICE +iab KREN_EMERG KERN_EMERG + +" Disable the command 'K' (keyword lookup) +" map K + +" Insert file +map e :read +" List current buffers +map :buffers +" Reformat selected text +" map gq + +" Needed because PuTTY doesn't seem to send the usual ctrl-up/down sequences +map [A +map [B +map [C +map [D + +" And these are for Mobaxterm +map [1;5A +map [1;5B +map [1;5C +map [1;5D +map [H +map [F + +map :wincmd k +map :wincmd j +map :wincmd h +map :wincmd l + +" map :wincmd k +" map :wincmd j + +" Start recording keystrokes (q to finish) +map qa +" Replay keystrokes +map @a + +" map ?"v/""*y:e "*p + +" Set swapsync to 'nothing' - potentially more data loss (no forced write to disk +" on swap write), but makes writes faster. I'm willing to take the chance. :-) +set sws= + +" Set showmatch - this flashes the cursor briefly at the matching ( or { +" when ) or } is entered. (If user keeps typing, cursor just pops up very +" quickly, then comes back.) +set showmatch + +" The command {number}CTRL-G show the current nuffer number, too. +" This is yet another feature that vi does not have. +" As I always want to see the buffer number I map it to CTRL-G. +" Pleae note that here we need to prevent a loop in the mapping by +" using the comamnd "noremap"! +noremap 2 + +" =================================================================== +" VIM - Editing and updating the vimrc: +" As I often make changes to this file I use these commands +" to start editing it and also update it: +if has("unix") + let vimrc='~/.vimrc' +else +" ie: if has("dos16") || has("dos32") || has("win32") + let vimrc='$VIM\_vimrc' +endif + +" Re-source and edit vimrc, respectively +nn ,u :source =vimrc +nn ,v :edit =vimrc + +nn ,s :mks! Session.vim + +" For some reason, the control-up/down doesn't work through putty, so create +" alternates as well. +nn ,p :wincmd k +nn ,l :wincmd j + +" =================================================================== + +" ;rcm = remove "control-m"s - for those mails sent from DOS: +nn ,rcm :%s/$//g + +" ,ksr = "kill space runs" +" substitutes runs of two or more space to a single space: +nmap ,ksr :%s/ \+/ /g +vmap ,ksr :s/ \+/ /g + +" ,Sel = "squeeze empty lines" +" Convert blocks of empty lines (not even whitespace included) +" into *one* empty line (within current visual): +map ,Sel :g/^$/,/./-j + +" ,Sbl = "squeeze blank lines" +" Convert all blocks of blank lines (containing whitespace only) +" into *one* empty line (within current visual): +map ,Sbl :g/^\s*$/,/\S/-j + +" make backspace more like a 'normal' editor (help options / backspace) +set backspace=1 + +" make the mouse active when run in an XTerm (this may disable middle click +" pasting) +if has("mouse") + set mouse=ac +endif + +" automatically write files on :make +set autowrite + +" automatically indent code etc +set autoindent + +" show file position +set ruler + +" Don't highlight search targets (irritating) +set nohlsearch + +" Return makes a new line at the cursor without entering insert mode +map i + +" Cut text down to size (C-J does not pre-join the lines) +map 74\|bi +map J74\|bi + +" and indent and unindent code +map :> +map :< +map :< + +" get man page of current function or open current URL in netscape +map :!man +"map ?[ \t'"()<>{}[\]]ly/[ \t'"()<>{}[\]]:!gnome-moz-remote --newwin " + +" Use fzf to find files +map :Files +map :Files + +nnoremap m :FZFMru +map :Ag =expand("") + +" use F4 to jump into and out of hex editing. Bit dangerous for normal use... +" map :set binary:%!xxd +" map :%!xxd -r + +" use F4 to bring up NERDTree +map :NERDTree +nnoremap n :NERDTreeToggle + +" Use F6 to swap buffers +map :b # +nnoremap b :b # + +map :split +map :only + +" map :cal SetSyn("c") +map :syntax sync fromstart + +" repeat the last command on the next line (F12 is Again on Sun keyboards) +map j. + +" use Print Screen to print the current file +map :!a2ps % + +" date functions +map ,dn ik!!date +'\%d/\%m/\%y'kJJ +map ,dw ik!!date +'\%V'kJJ + +" (double) quote up the word under the cursor +map ` bi"wwhi" + +" use GNU make (gnu_make is a script to perform builds with GNU make +" and filter results into GNU format error report) +" :set mp=gnu_make +:set mp=make + +" xterm title magic +if "$TERM" != "dumb" + set title +endif + +" set up cscope support (:help cscope) +if has("cscope") + set cscopetag + set cscopetagorder=0 + set nocsverb + " compress the path display to only the final 2 elements + if has("cscopepathcomp") + set cscopepathcomp=2 + endif + set csverb + map ,fs :cs find s =expand("") + map ,fg :cs find g =expand("") + map ,fd :cs find d =expand("") + map ,fc :cs find c =expand("") + map ,fa :cs find t =expand("") + map ,fi :cs find i =expand("%:t") + map ,ss :cs find s + map ,sg :cs find g + map ,sd :cs find d + map ,sc :cs find c + map ,sa :cs find t +endif +filetype plugin indent on + +" Avoids printing anything by accident... +set printexpr=PrintFile(v:fname_in) +function! PrintFile(fname) + "call system("ghostview " . a:fname) + "call system("lpr " . a:fname) + call delete(a:fname) + return v:shell_error +endfunction