vim/vimrc

293 lines
6.7 KiB
VimL
Raw Normal View History

2017-09-10 20:22:02 +00:00
filetype off " required
set ttyfast
2017-09-10 20:22:02 +00:00
2018-03-17 23:42:49 +00:00
source vimrc.plugins.vim
source vimrc.functions.vim
for f in split(glob('vimrc.d/*.vim'), '\n')
exe 'source' f
endfor
2017-09-10 20:22:02 +00:00
2018-02-22 18:12:33 +00:00
2018-03-15 15:26:21 +00:00
" #settings{{{
2018-02-22 18:12:33 +00:00
" set t_Sf=<Esc>[3%p1%dm " foreground colour
if &term == 'xterm-256color'
2018-02-03 18:54:18 +00:00
set termguicolors
endif
2018-02-22 18:12:33 +00:00
syntax on
colorscheme customred256
2018-02-10 11:41:22 +00:00
set guioptions-=mTrLb
set guioptions+=c
2018-02-22 18:12:33 +00:00
" set t_Sb=<Esc>[4%p1%dm " background coloru
2018-02-23 13:12:42 +00:00
set updatetime=100
2018-02-11 21:01:24 +00:00
2017-09-30 22:09:41 +00:00
set backupdir=~/.vimtmp
set directory=~/.vimtmp
2018-03-15 13:54:38 +00:00
set tags+=./.tags,.tags;/home/ray/
2018-03-15 12:56:42 +00:00
2018-02-22 18:12:33 +00:00
" persisitent undo file
set undodir=/home/ray/.vim/undodir
set undofile
2018-02-03 14:41:01 +00:00
set clipboard=unnamedplus
2017-09-18 20:20:14 +00:00
set ignorecase
set smartcase
2017-12-26 22:11:45 +00:00
set wildmenu
set wildmode=longest:full,full
set hidden
2017-12-26 22:54:44 +00:00
set background=dark
2017-10-02 10:30:23 +00:00
set number relativenumber
2018-02-22 18:12:33 +00:00
set hlsearch
2017-12-29 16:37:04 +00:00
set foldcolumn=1
2018-02-22 18:12:33 +00:00
set iskeyword+=-
set scrolloff=10
set showcmd
set incsearch
set laststatus=2
set foldmethod=manual
set showmode
set autoindent
set breakindent
set showbreak=
set mouse=a
set listchars=eol,tab:->,trail:~,extends:>,precedes:<,space
2017-09-18 23:25:41 +00:00
2018-02-22 18:12:33 +00:00
set textwidth=180
set formatoptions=cq
set wrapmargin=0
2018-03-15 15:26:21 +00:00
"}}}
2018-02-22 18:12:33 +00:00
2018-03-15 15:26:21 +00:00
" key #mappings{{{
let g:mapleader = "\<space>"
2018-03-17 23:50:54 +00:00
nnoremap <space>rc :so $MYVIMRC<CR>
2018-03-15 13:54:38 +00:00
" Focus on current fold, close the rest
2018-03-17 23:50:54 +00:00
nnoremap <space>zz zMzvzz
2018-03-15 13:54:38 +00:00
2018-02-10 11:58:33 +00:00
" replace current word with last yanked/deleted text
2018-03-17 23:50:54 +00:00
nnoremap <space>rr "_diwP
2018-02-10 11:58:33 +00:00
" replace current word with last yanked text
2018-03-17 23:50:54 +00:00
nnoremap <space>ry diw"0P
2018-02-10 11:58:33 +00:00
inoremap jk <esc>
2017-12-26 22:32:39 +00:00
nnoremap A :call CheckLineEnding()<CR>
2018-03-17 23:50:54 +00:00
nnoremap <space>co :!clear;
2018-03-01 21:35:28 +00:00
2018-03-17 23:50:54 +00:00
nnoremap <space>gs :!clear; echo 'git status'; git status<CR>
nnoremap <space>gd :!clear; echo 'git diff'; git diff<CR>
nnoremap <space>ga :!clear; git add %; git status<CR>
nnoremap <space>gA :!clear; git add .; git status<CR>
nnoremap <space>gc :!clear; git commit -m ''<Left>
nnoremap <space>gg :!clear; git add %; git commit -m ''<Left>
nnoremap <space>gp :!clear; echo 'git push'; git push<CR>
nnoremap <space>gl :!clear; git log<CR>
2018-02-18 12:19:37 +00:00
" netrw
2018-03-17 23:50:54 +00:00
nnoremap <space>ex :Ex<CR>
nnoremap <space>ee :e .<CR>
nnoremap <space>eq :Rex<CR>
2017-09-10 20:22:02 +00:00
" better window navigaton
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
nnoremap <C-k> <C-w>k
nnoremap <C-j> <C-w>j
2018-02-17 14:15:42 +00:00
nnoremap <Esc>j :resize -5<CR>
nnoremap <Esc>k :resize +5<CR>
nnoremap <Esc>l :vertical resize +5<CR>
2018-02-23 13:41:21 +00:00
nnoremap <Esc>h :vertical resize -5<CR>
2018-02-17 14:24:00 +00:00
nnoremap <Esc>= <C-w>=
2017-09-10 20:22:02 +00:00
2017-12-27 12:43:01 +00:00
"location list and quickfix mappings
2018-03-17 23:50:54 +00:00
nnoremap <space>ll :botright lwindow<CR>
nnoremap <space>lp :lprev<CR>
nnoremap <space>ln :lnext<CR>
nnoremap <space>lc :lclose<CR>
nnoremap <space>llh :lhistory<CR>
nnoremap <space>llp :lolder<CR>
nnoremap <space>lln :lnewer<CR>
nnoremap <space>qf :botright cwindow<CR>
nnoremap <space>qp :cprev<CR>
nnoremap <space>qn :cnext<CR>
nnoremap <space>qc :cclose<CR>
nnoremap <space>qfh :chistory<CR>
nnoremap <space>qfp :colder<CR>
nnoremap <space>qfn :cnewer<CR>
nnoremap <space>nh :noh<CR>
2017-12-29 12:24:31 +00:00
2017-12-27 13:15:57 +00:00
" quick grep of visual selection
2018-03-17 23:50:54 +00:00
vnoremap <space>gr y:grep! -R <C-r>" .
2017-12-27 13:15:57 +00:00
2017-12-27 13:28:03 +00:00
" open quickfix window of TODOs
2018-03-17 23:50:54 +00:00
nnoremap <space>td :grep! -R '// *TODO' .<CR>:botright cwindow<CR>:echo len(getqflist()) 'TODOs'<CR>
2017-12-27 13:28:03 +00:00
2017-09-18 21:08:35 +00:00
" brace/quotes completion
2018-02-11 15:28:21 +00:00
inoremap {{ {}<left>
2018-02-11 21:01:24 +00:00
inoremap {<CR> {<CR>}<esc>O
inoremap {; {<CR>};<esc>O
inoremap }} {{}}<Left><Left>
2018-02-11 15:28:21 +00:00
inoremap (( ()<Left>
2018-02-11 21:01:24 +00:00
inoremap (; ();<Left><Left>
2018-02-11 15:28:21 +00:00
inoremap [[ []<Left>
2018-02-11 21:01:24 +00:00
inoremap [<CR> [<CR>]<esc>O
2018-02-11 15:28:21 +00:00
2018-02-11 21:01:24 +00:00
inoremap "" ""<Left>
inoremap "; "";<Left><Left>
inoremap '' ''<Left>
inoremap '; '';<Left><Left>
2018-02-11 15:28:21 +00:00
inoremap ;; ;<esc>
2017-10-04 11:16:08 +00:00
2018-03-17 23:50:54 +00:00
nnoremap <space>nn :set invrelativenumber<CR>
nnoremap <space>hl :nohlsearch<CR>
2017-12-29 12:24:31 +00:00
2018-02-11 15:28:21 +00:00
" devdocs mapping
2018-03-17 23:50:54 +00:00
nnoremap <space>dd :DD<CR>
2018-03-15 15:26:21 +00:00
"}}}
2018-02-11 15:28:21 +00:00
2018-03-15 15:26:21 +00:00
" #abbreviations{{{
iabbrev adn and
iabbrev waht what
iabbrev tehn then
2018-03-15 15:26:21 +00:00
"}}}
2017-09-10 20:22:02 +00:00
2018-03-15 15:26:21 +00:00
" #autocommands{{{
2017-09-10 20:22:02 +00:00
2018-02-01 17:46:16 +00:00
" persistent folds
augroup AutoSaveFolds
autocmd!
autocmd BufWritePost *.* mkview
2018-02-01 17:46:16 +00:00
autocmd BufWinEnter *.* silent loadview
augroup END
2017-09-10 20:22:02 +00:00
" fix higlight problems such as vertical-align etc
augroup VimCSS3Syntax
autocmd!
autocmd FileType css setlocal iskeyword+=-
augroup END
" Show trailing whitepace and spaces before a tab:
augroup whitespaceerrors
autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\t/ containedin=ALL
augroup END
2017-09-12 19:55:49 +00:00
" automatically reload if color scheme file written
augroup coloreload
au!
au BufWritePost customred256.vim so $MYVIMRC
augroup end
2017-12-28 21:01:58 +00:00
augroup linenumbering
autocmd InsertEnter * :set norelativenumber
autocmd InsertLeave * :set number relativenumber
autocmd WinEnter * :set number relativenumber
autocmd WinLeave * set norelativenumber
augroup END
2017-09-12 19:55:49 +00:00
2017-12-28 21:01:58 +00:00
augroup colorcolumns
autocmd WinEnter * set colorcolumn=80
autocmd WinLeave * set colorcolumn=0
augroup END
2017-09-10 20:22:02 +00:00
" Automatically reload .vimrc if chanaged
augroup myvimrc
au!
au BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
augroup END
2018-03-15 15:26:21 +00:00
"}}}
2017-09-10 20:22:02 +00:00
2018-03-15 15:26:21 +00:00
" #functions{{{
2018-02-22 18:12:33 +00:00
2018-03-16 19:56:24 +00:00
" TODO better name
2018-03-17 00:58:49 +00:00
function! GetStatusFrag(condition, colorname, conditionprefix, text) abort "{{{
2018-03-16 19:56:24 +00:00
let l:frag='%#' . a:colorname . '#'
let l:frag.=a:conditionprefix
let l:frag.='%{(' . a:condition . ")?'" . a:text . "':''}"
return l:frag
endfunction"}}}
2018-03-17 00:58:49 +00:00
function! CheckLineEnding() abort "{{{
:normal $
if getline('.')[col('.')-1] == ';' || getline('.')[col('.')-1] == ','
:startinsert
else
:startinsert!
endif
2018-03-16 19:56:24 +00:00
endfunction"}}}
2018-02-22 18:12:33 +00:00
" get name of syntax item
2018-03-17 00:58:49 +00:00
function! SyntaxItem() abort "{{{
2018-02-22 18:12:33 +00:00
return synIDattr(synID(line('.'),col('.'),1),'name') . ' -> ' . synIDattr(synIDtrans(synID(line('.'),col('.'),1)), 'name' )
endfunction
2018-03-17 23:50:54 +00:00
nnoremap <space>p :echom SyntaxItem()<CR>"}}}
2018-02-22 18:12:33 +00:00
" devdocs DD
" https://gist.github.com/romainl/8d3b73428b4366f75a19be2dad2f0987#file-devdocs-vim
2018-03-16 19:56:24 +00:00
function! s:Get_env() abort "{{{
2018-02-22 18:12:33 +00:00
if has('win64') || has('win32') || has('win16')
return 'WINDOWS'
else
return toupper(substitute(system('uname'), '\n', '', ''))
endif
endfunction
" What command to use on what system
2018-03-05 16:03:26 +00:00
let s:cmds = {'DARWIN': 'open', 'LINUX': 'qutebrowser', 'WINDOWS': 'start'}
2018-02-22 18:12:33 +00:00
" Build the URL stub
let s:stub = s:cmds[<SID>Get_env()] . " 'http://devdocs.io/?q="
command! -nargs=* DD silent! call system(len(split(<q-args>, ' ')) == 0 ?
\ s:stub . &ft . ' ' . expand('<cword>') . "'" : len(split(<q-args>, ' ')) == 1 ?
\ s:stub . &ft . ' ' . <q-args> . "'" : s:stub . <q-args> . "'")
2018-03-16 19:56:24 +00:00
"}}}
2018-02-22 18:12:33 +00:00
" use ranger as file manager
2018-03-17 00:58:49 +00:00
if !exists('*RangerExplorer') "{{{
function RangerExplorer() abort
2018-02-22 18:12:33 +00:00
exec 'silent !ranger --choosefile=/tmp/vim_ranger_current_file ' . expand('%:p:h')
if filereadable('/tmp/vim_ranger_current_file')
exec 'edit ' . system('cat /tmp/vim_ranger_current_file')
call system('rm /tmp/vim_ranger_current_file')
endif
redraw!
endfun
2018-03-17 23:50:54 +00:00
map <space>ra :call RangerExplorer()<CR>
2018-03-16 19:56:24 +00:00
endif"}}}
2018-03-17 00:58:49 +00:00
function! GetLinterStatus(key) abort "{{{
let l:linter = ale#statusline#Count(bufnr(''))
return l:linter[a:key]
2018-03-16 19:56:24 +00:00
endfunction
2018-03-17 00:58:49 +00:00
2018-03-16 19:56:24 +00:00
"}}}
2018-03-15 15:26:21 +00:00
"}}}
2018-02-22 18:12:33 +00:00
2017-09-10 20:22:02 +00:00
2018-03-15 15:26:21 +00:00
" vim: foldmethod=marker