406 lines
10 KiB
VimL
406 lines
10 KiB
VimL
" Adapted from Dan's .vimrc, and Sven Gucke's vimrc.forall - Paul
|
|
|
|
if empty(glob('~/.vim/autoload/plug.vim'))
|
|
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
|
|
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
|
|
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
|
|
endif
|
|
|
|
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 'jreybert/vimagit'
|
|
|
|
Plug 'vim-airline/vim-airline'
|
|
Plug 'vim-airline/vim-airline-themes'
|
|
|
|
Plug 'scrooloose/nerdtree'
|
|
Plug 'wesQ3/vim-windowswap'
|
|
Plug 'majutsushi/tagbar'
|
|
|
|
" 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 'dense-analysis/ale'
|
|
Plug 'tpope/vim-commentary'
|
|
|
|
Plug 'posva/vim-vue'
|
|
Plug 'ap/vim-css-color'
|
|
Plug 'pangloss/vim-javascript'
|
|
Plug 'othree/html5.vim'
|
|
|
|
Plug 'elixir-editors/vim-elixir'
|
|
Plug 'elzr/vim-json'
|
|
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 <C-R>=expand("%:p:h") . "/"<CR>
|
|
else
|
|
map ,e :e <C-R>=expand("%:p:h") . "\\"<CR>
|
|
endif
|
|
|
|
set backupdir=/tmp//,.
|
|
set directory=/tmp//,.
|
|
if v:version >= 703
|
|
set backupdir=/tmp//,.
|
|
endif
|
|
|
|
" TODO put in file groups
|
|
" imap cll console.log()<Esc>==f(a
|
|
|
|
augroup filetype_elixir
|
|
autocmd!
|
|
autocmd BufRead * imap ii IO.inspect(
|
|
autocmd BufRead * imap ip IO.puts(
|
|
augroup END
|
|
|
|
augroup filetype_vue
|
|
autocmd!
|
|
autocmd BufRead * imap cll console.log()<Esc>==f(a
|
|
augroup END
|
|
|
|
set ignorecase smartcase
|
|
set incsearch
|
|
|
|
set complete=.,b,u,]
|
|
|
|
set wildignore+=deps/*,node_modules/*,*.sw?
|
|
|
|
color desert
|
|
if has("AirlineTheme")
|
|
if has("gui_running")
|
|
let g:airline_theme="papercolor"
|
|
endif
|
|
endif
|
|
|
|
" 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
|
|
|
|
map <C-T> :pop<CR>
|
|
|
|
" 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)<CR>
|
|
map ,t3 :echo TabSize(3)<CR>
|
|
map ,t4 :echo TabSize(4)<CR>
|
|
map ,t8 :echo TabSize(8)<CR>
|
|
|
|
" 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 *.inc set filetype=make
|
|
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
|
|
call TabSize(4)
|
|
augroup END
|
|
|
|
augroup cprog
|
|
au!
|
|
au BufRead,BufNewFile *.[ch] set cindent
|
|
" simulate C++ comments (sort of) and provide a means to uncomment easily
|
|
map // ^i/* <ESC>$a */<ESC>
|
|
map \\ bhh/ *[*][/]<CR>d/[/]<CR>x?[/][*]<CR>dw
|
|
" map // 0v$gc
|
|
call TabSize(4)
|
|
augroup END
|
|
|
|
" Apply the muttrc colouring to mutt setup files:
|
|
au BufNewFile,BufRead .mutt.* set ft=muttrc
|
|
|
|
" Automatic typo fixing
|
|
iab KREN_EMERG KERN_EMERG
|
|
|
|
" Disable the command 'K' (keyword lookup)
|
|
" map K <NUL>
|
|
|
|
" Insert file
|
|
map <C-K>e :read
|
|
" List current buffers
|
|
map <C-L> :buffers<CR>
|
|
" Reformat selected text
|
|
" map <C-W> gq
|
|
|
|
" Needed because PuTTY doesn't seem to send the usual ctrl-up/down sequences
|
|
map <ESC>[A <C-Up>
|
|
map <ESC>[B <C-Down>
|
|
map <ESC>[C <C-Right>
|
|
map <ESC>[D <C-Left>
|
|
|
|
" And these are for Mobaxterm
|
|
map <ESC>[1;5A <C-Up>
|
|
map <ESC>[1;5B <C-Down>
|
|
map <ESC>[1;5C <C-Right>
|
|
map <ESC>[1;5D <C-Left>
|
|
map <ESC>[H <Home>
|
|
map <ESC>[F <End>
|
|
|
|
map <C-Up> :wincmd k<CR>
|
|
map <C-Down> :wincmd j<CR>
|
|
map <C-Left> :wincmd h<CR>
|
|
map <C-Right> :wincmd l<CR>
|
|
|
|
" Don't automatically resize windows to be the same.
|
|
set noequalalways
|
|
" Fix the width of the window
|
|
nnoremap <leader>wfw :set winfixwidth
|
|
" Fix the height of the window
|
|
nnoremap <leader>wfh :set winfixheight
|
|
|
|
" map <C-Up> :wincmd k<CR>
|
|
" map <C-Down> :wincmd j<CR>
|
|
|
|
" Start recording keystrokes (q to finish)
|
|
map <C-M> qa
|
|
" Replay keystrokes
|
|
map <C-CR> @a
|
|
|
|
" map <C-CR> ?"<CR><RIGHT>v/"<CR><LEFT>"*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. :-)
|
|
if !has("nvim")
|
|
set sws=
|
|
endif
|
|
|
|
" 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 <C-G> 2<C-G>
|
|
|
|
" ===================================================================
|
|
" 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 <C-R>=vimrc<CR><CR>
|
|
nn ,v :edit <C-R>=vimrc<CR><CR>
|
|
|
|
nn ,s :mks! Session.vim<CR>
|
|
|
|
" For some reason, the control-up/down doesn't work through putty, so create
|
|
" alternates as well.
|
|
nn ,p :wincmd k<CR>
|
|
nn ,l :wincmd j<CR>
|
|
|
|
" ===================================================================
|
|
|
|
" ;rcm = remove "control-m"s - for those mails sent from DOS:
|
|
nn ,rcm :%s/<C-V><C-M>$//g<CR>
|
|
|
|
" ,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 <CR> i<CR><ESC>
|
|
|
|
" Cut text down to size (C-J does not pre-join the lines)
|
|
map <C-J> 74\|bi<CR><ESC>
|
|
map <C-S-J> J74\|bi<CR><ESC>
|
|
|
|
" <Tab> and <S-Tab> indent and unindent code
|
|
map <Tab> :><CR>
|
|
map <S-Tab> :<<CR>
|
|
map <C-S-Tab> :<<CR><DOWN>
|
|
|
|
" get man page of current function or open current URL in netscape
|
|
map <F1> :!man <cword><CR>
|
|
"map <S-F1> ?[ \t'"()<>{}[\]]<CR>ly/[ \t'"()<>{}[\]]<CR>:!gnome-moz-remote --newwin <C-R>"<CR>
|
|
|
|
" Use fzf to find files
|
|
map <F2> :Files<CR>
|
|
map <C-P> :Files<CR>
|
|
" map <C-S-P> :Files <C-R>=expand("%:p:h")<CR>
|
|
|
|
nnoremap <silent> <leader>m :FZFMru<CR>
|
|
|
|
map <F3> :Ag <C-R>=expand("<cword>")<CR><CR>
|
|
nnoremap <leader>f :Ag <C-R>=expand("<cword>")<CR><CR>
|
|
|
|
" use F4 to bring up NERDTree
|
|
map <F4> :NERDTree<CR>
|
|
nnoremap <leader>n :NERDTreeToggle<cr>
|
|
|
|
" Use F6 to swap buffers
|
|
map <F6> :b #<CR>
|
|
nnoremap <leader>b :b #<CR>
|
|
|
|
map <F8> :split<CR>
|
|
map <F9> :only<CR>
|
|
|
|
" map <F11> :cal SetSyn("c")<CR>
|
|
" map <F11> :syntax sync fromstart<CR>
|
|
nnoremap <leader>ss :syntax sync fromstart<CR>
|
|
|
|
nnoremap <leader>t :TagbarToggle<CR>
|
|
|
|
" repeat the last command on the next line (F12 is Again on Sun keyboards)
|
|
map <F12> j.
|
|
|
|
" use Print Screen to print the current file
|
|
map <F22> :!a2ps %<CR>
|
|
|
|
" date functions
|
|
map ,dn i<CR><CR><ESC>k!!date +'\%d/\%m/\%y'<CR>kJJ
|
|
map ,dw i<CR><CR><ESC>k!!date +'\%V'<CR>kJJ
|
|
|
|
" (double) quote up the word under the cursor
|
|
map ` bi"<ESC>wwhi"<ESC>
|
|
|
|
" 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 ,scs0 :cs add cscope.out<CR>
|
|
map ,fs :cs find s <C-R>=expand("<cword>")<CR><CR>
|
|
map ,fg :cs find g <C-R>=expand("<cword>")<CR><CR>
|
|
map ,fd :cs find d <C-R>=expand("<cword>")<CR><CR>
|
|
map ,fc :cs find c <C-R>=expand("<cword>")<CR><CR>
|
|
map ,fa :cs find t <C-R>=expand("<cword>")<CR><CR>
|
|
map ,fi :cs find i <C-R>=expand("%:t")<CR><CR>
|
|
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
|
|
|
|
function! ToggleWindowHorizontalVerticalSplit()
|
|
if !exists('t:splitType')
|
|
let t:splitType = 'vertical'
|
|
endif
|
|
|
|
if t:splitType == 'vertical' " is vertical switch to horizontal
|
|
windo wincmd K
|
|
let t:splitType = 'horizontal'
|
|
else " is horizontal switch to vertical
|
|
windo wincmd H
|
|
let t:splitType = 'vertical'
|
|
endif
|
|
endfunction
|
|
|
|
nnoremap <silent> <leader>wst :call ToggleWindowHorizontalVerticalSplit()<cr>
|
|
|