2018-05-13 17:21:50 -05:00
|
|
|
" Sane vim defaults for ArchLabs
|
2018-05-01 23:57:34 -05:00
|
|
|
|
2018-05-13 17:21:50 -05:00
|
|
|
" Arch defaults
|
2018-05-01 23:57:34 -05:00
|
|
|
runtime! archlinux.vim
|
|
|
|
|
2018-06-10 20:30:50 -05:00
|
|
|
set modeline " enable vim modelines
|
2018-05-13 17:21:50 -05:00
|
|
|
set clipboard^=unnamedplus " system clipboard (requires +clipboard)
|
|
|
|
set number " enable line numbers
|
|
|
|
set confirm " ask confirmation for some things, like save before quit, etc.
|
|
|
|
set wildmenu " Tab completion menu when using command mode
|
|
|
|
set expandtab " Tab key inserts spaces not tabs
|
|
|
|
set softtabstop=4 " spaces to enter for each tab
|
|
|
|
set shiftwidth=4 " amount of spaces for indentation
|
|
|
|
set shortmess+=aAcIws " Hide or shorten certain messages
|
2018-05-01 23:57:34 -05:00
|
|
|
|
2018-06-16 21:09:51 -05:00
|
|
|
" ------ leader mapping ------
|
|
|
|
|
|
|
|
let g:mapleader = ','
|
|
|
|
map <Space> ,
|
|
|
|
|
|
|
|
|
|
|
|
" ------ enable additional features ------
|
|
|
|
|
|
|
|
" enable mouse
|
2018-05-01 23:57:34 -05:00
|
|
|
set mouse=a
|
|
|
|
if has('mouse_sgr')
|
2018-06-16 21:09:51 -05:00
|
|
|
" sgr mouse is better but not every term supports it
|
2018-05-01 23:57:34 -05:00
|
|
|
set ttymouse=sgr
|
|
|
|
endif
|
|
|
|
|
2018-06-16 21:09:51 -05:00
|
|
|
" syntax highlighting
|
2018-05-01 23:57:34 -05:00
|
|
|
syntax enable
|
2018-06-17 00:46:22 -05:00
|
|
|
|
|
|
|
if has('termguicolors') && $DISPLAY !=? '' && &t_Co == 256
|
|
|
|
|
|
|
|
let g:jinx_colors = 'night' " night or day (shift-t to change on the fly)
|
|
|
|
|
2018-06-16 21:09:51 -05:00
|
|
|
" true color in the terminal
|
2018-05-01 23:57:34 -05:00
|
|
|
set termguicolors
|
2018-06-17 00:46:22 -05:00
|
|
|
colorscheme jinx
|
2018-06-16 21:09:51 -05:00
|
|
|
|
|
|
|
" fix true color in some terminals (nvim doesn't have this issue)
|
2018-06-10 20:30:50 -05:00
|
|
|
if !has('nvim') && !($TERM =~? 'xterm' || &term =~? 'xterm')
|
|
|
|
let $TERM = 'xterm-256color'
|
|
|
|
let &term = 'xterm-256color'
|
|
|
|
endif
|
2018-06-17 00:46:22 -05:00
|
|
|
else
|
|
|
|
set nocursorline
|
|
|
|
set notermguicolors
|
|
|
|
colorscheme evening
|
2018-06-10 20:30:50 -05:00
|
|
|
endif
|
|
|
|
|
2018-06-16 21:09:51 -05:00
|
|
|
" change cursor shape for different editing modes (nvim does this by default)
|
2018-06-10 20:30:50 -05:00
|
|
|
if !has('nvim') && exists('$TMUX')
|
|
|
|
let &t_SI = "\<Esc>Ptmux;\<Esc>\e[5 q\<Esc>\\"
|
|
|
|
let &t_SR = "\<Esc>Ptmux;\<Esc>\e[4 q\<Esc>\\"
|
|
|
|
let &t_EI = "\<Esc>Ptmux;\<Esc>\e[2 q\<Esc>\\"
|
|
|
|
elseif !has('nvim')
|
|
|
|
let &t_SI = "\e[6 q"
|
|
|
|
let &t_SR = "\e[4 q"
|
|
|
|
let &t_EI = "\e[2 q"
|
2018-05-01 23:57:34 -05:00
|
|
|
endif
|
|
|
|
|
2018-06-16 21:09:51 -05:00
|
|
|
|
|
|
|
" ------ basic maps ------
|
|
|
|
|
|
|
|
" open ranger as a file chooser using the function below
|
|
|
|
nnoremap <leader>r :call <SID>ranger()<CR>
|
|
|
|
|
2018-05-01 23:57:34 -05:00
|
|
|
" paste while in insert mode
|
|
|
|
inoremap <silent><C-v> <Esc>:set paste<CR>a<C-r>+<Esc>:set nopaste<CR>a
|
|
|
|
|
2018-05-13 17:21:50 -05:00
|
|
|
" alt defaults
|
2018-05-01 23:57:34 -05:00
|
|
|
nnoremap 0 ^
|
|
|
|
nnoremap Y y$
|
|
|
|
nnoremap n nzzzv
|
|
|
|
nnoremap N Nzzzv
|
|
|
|
nnoremap <Tab> ==j
|
|
|
|
|
2018-06-16 21:09:51 -05:00
|
|
|
" re-visual text after changing indent
|
|
|
|
vnoremap > >gv
|
|
|
|
vnoremap < <gv
|
|
|
|
|
2018-06-09 18:51:08 -05:00
|
|
|
" j = gj :: k = gk while preserving numbered jumps ie. 12j or 30k
|
2018-05-01 23:57:34 -05:00
|
|
|
nnoremap <buffer><silent><expr>j v:count ? 'j' : 'gj'
|
|
|
|
nnoremap <buffer><silent><expr>k v:count ? 'k' : 'gk'
|
|
|
|
|
2018-06-16 21:09:51 -05:00
|
|
|
|
|
|
|
" ------ autocmd ------
|
|
|
|
|
2018-05-13 17:21:50 -05:00
|
|
|
" Reload changes if file changed outside of vim requires autoread
|
2018-05-01 23:57:34 -05:00
|
|
|
augroup load_changed_file
|
|
|
|
autocmd!
|
|
|
|
autocmd FocusGained,BufEnter * if mode() !=? 'c' | checktime | endif
|
|
|
|
autocmd FileChangedShellPost * echo "Changes loaded from file"
|
|
|
|
augroup END
|
|
|
|
|
2018-05-13 17:21:50 -05:00
|
|
|
" when quitting a file, save the cursor position
|
2018-05-01 23:57:34 -05:00
|
|
|
augroup save_cursor_position
|
|
|
|
autocmd!
|
|
|
|
autocmd BufReadPost * call setpos(".", getpos("'\""))
|
|
|
|
augroup END
|
2018-06-16 21:09:51 -05:00
|
|
|
|
|
|
|
|
|
|
|
" ------ adv maps ------
|
|
|
|
|
|
|
|
" toggle line numbers
|
|
|
|
nnoremap <silent> <Leader>nn
|
|
|
|
\ :if &number <Bar>
|
|
|
|
\ set nonumber
|
|
|
|
\ <Bar> else <Bar>
|
|
|
|
\ set number
|
|
|
|
\ <Bar> endif<CR>
|
|
|
|
|
|
|
|
" strip trailing whitespace
|
|
|
|
nnoremap <silent> <Leader>ss
|
|
|
|
\ :let _p = getpos(".") <Bar>
|
|
|
|
\ let _s = (@/ != '') ? @/ : '' <Bar>
|
|
|
|
\ %s/\s\+$//e <Bar>
|
|
|
|
\ let @/ = _s <Bar>
|
|
|
|
\ nohlsearch <Bar>
|
|
|
|
\ unlet _s <Bar>
|
|
|
|
\ call setpos('.', _p) <Bar>
|
|
|
|
\ unlet _p <CR>
|
|
|
|
|
|
|
|
" global replace
|
|
|
|
vnoremap <Leader>sw "hy
|
|
|
|
\ :let b:sub = input('global replacement: ') <Bar>
|
|
|
|
\ if b:sub !=? '' <Bar>
|
|
|
|
\ let b:rep = substitute(getreg('h'), '/', '\\/', 'g') <Bar>
|
|
|
|
\ execute '%s/'.b:rep."/".b:sub.'/g' <Bar>
|
|
|
|
\ unlet b:sub b:rep <Bar>
|
|
|
|
\ endif <CR>
|
|
|
|
nnoremap <Leader>sw
|
|
|
|
\ :let b:sub = input('global replacement: ') <Bar>
|
|
|
|
\ if b:sub !=? '' <Bar>
|
|
|
|
\ execute "%s/<C-r><C-w>/".b:sub.'/g' <Bar>
|
|
|
|
\ unlet b:sub <Bar>
|
|
|
|
\ endif <CR>
|
|
|
|
|
|
|
|
" prompt before each replace
|
|
|
|
vnoremap <Leader>cw "hy
|
|
|
|
\ :let b:sub = input('interactive replacement: ') <Bar>
|
|
|
|
\ if b:sub !=? '' <Bar>
|
|
|
|
\ let b:rep = substitute(getreg('h'), '/', '\\/', 'g') <Bar>
|
|
|
|
\ execute '%s/'.b:rep.'/'.b:sub.'/gc' <Bar>
|
|
|
|
\ unlet b:sub b:rep <Bar>
|
|
|
|
\ endif <CR>
|
|
|
|
nnoremap <Leader>cw
|
|
|
|
\ :let b:sub = input('interactive replacement: ') <Bar>
|
|
|
|
\ if b:sub !=? '' <Bar>
|
|
|
|
\ execute "%s/<C-r><C-w>/".b:sub.'/gc' <Bar>
|
|
|
|
\ unlet b:sub <Bar>
|
|
|
|
\ endif <CR>
|
|
|
|
|
|
|
|
" highlight long lines
|
|
|
|
let w:longlines = matchadd('ColorColumn', '\%'.&tw.'v', &tw)
|
|
|
|
nnoremap <silent> <Leader>ll
|
|
|
|
\ :if exists('w:longlines') <Bar>
|
|
|
|
\ silent! call matchdelete(w:longlines) <Bar>
|
|
|
|
\ unlet w:longlines <Bar>
|
|
|
|
\ elseif &textwidth > 0 <Bar>
|
|
|
|
\ let w:longlines = matchadd('ColorColumn', '\%'.&textwidth.'v', &textwidth) <Bar>
|
|
|
|
\ else <Bar>
|
|
|
|
\ let w:longlines = matchadd('ColorColumn', '\%80v', 80) <Bar>
|
|
|
|
\ endif <CR>
|
|
|
|
|
|
|
|
" local keyword jump
|
|
|
|
nnoremap <Leader>fw
|
|
|
|
\ [I:let b:jump = input('Go To: ') <Bar>
|
|
|
|
\ if b:jump !=? '' <Bar>
|
|
|
|
\ execute "normal! ".b:jump."[\t" <Bar>
|
|
|
|
\ unlet b:jump <Bar>
|
|
|
|
\ endif <CR>
|
|
|
|
|
|
|
|
|
|
|
|
" open ranger as a file chooser
|
|
|
|
function! <SID>ranger()
|
|
|
|
let l:temp = tempname()
|
|
|
|
|
|
|
|
execute 'silent !st -e ranger --choosefiles='.shellescape(l:temp).' $PWD'
|
|
|
|
|
|
|
|
if !filereadable(temp)
|
|
|
|
redraw!
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let l:names = readfile(l:temp)
|
|
|
|
if empty(l:names)
|
|
|
|
redraw!
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
execute 'edit '.fnameescape(l:names[0])
|
|
|
|
|
|
|
|
for l:name in l:names[1:]
|
|
|
|
execute 'argadd '.fnameescape(l:name)
|
|
|
|
endfor
|
|
|
|
|
|
|
|
redraw!
|
|
|
|
endfunction
|