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-07-15 00:11:15 -05:00
|
|
|
" additional settings
|
2018-10-29 03:36:27 -05:00
|
|
|
set modeline " enable vim modelines
|
|
|
|
set hlsearch " highlight search items
|
|
|
|
set incsearch " searches are performed as you type
|
|
|
|
set clipboard^=unnamed,unnamedplus " system clipboard (requires +clipboard)
|
|
|
|
set number " enable line numbers
|
|
|
|
set confirm " ask confirmation like save before quit.
|
|
|
|
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-07-15 00:11:15 -05:00
|
|
|
let g:netrw_altv = 1
|
|
|
|
let g:netrw_liststyle = 3
|
|
|
|
let g:netrw_browse_split = 3
|
|
|
|
|
2018-06-16 21:09:51 -05:00
|
|
|
" ------ leader mapping ------
|
|
|
|
|
2018-11-05 00:19:12 -06:00
|
|
|
let g:mapleader = "\<Space>"
|
2018-06-16 21:09:51 -05:00
|
|
|
|
|
|
|
" ------ 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
|
2018-10-29 03:36:27 -05:00
|
|
|
set termguicolors " true colors in the terminal
|
|
|
|
let g:jinx_colors = 'night' " night or day
|
2018-07-15 00:11:15 -05:00
|
|
|
try
|
|
|
|
colorscheme jinx
|
|
|
|
catch
|
|
|
|
colorscheme evening
|
|
|
|
endtry
|
2018-06-16 21:09:51 -05:00
|
|
|
|
2018-07-15 00:11:15 -05:00
|
|
|
" fix true colors in some terminals (neovim doesn't seem to 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
|
2018-08-18 17:15:37 -05:00
|
|
|
colorscheme slate
|
2018-06-10 20:30:50 -05:00
|
|
|
endif
|
|
|
|
|
2018-08-18 15:16:42 -05:00
|
|
|
" change cursor shape for different editing modes, neovim does this by default
|
2018-07-15 00:11:15 -05:00
|
|
|
if !has('nvim')
|
|
|
|
if 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>\\"
|
|
|
|
else
|
|
|
|
let &t_SI = "\e[6 q"
|
|
|
|
let &t_SR = "\e[4 q"
|
|
|
|
let &t_EI = "\e[2 q"
|
|
|
|
endif
|
2018-05-01 23:57:34 -05:00
|
|
|
endif
|
|
|
|
|
2018-08-18 15:16:42 -05:00
|
|
|
set linebreak " wrap lines at full words rather than the last character to fit
|
|
|
|
set breakindent " wrapped lines match the same indent level
|
2018-07-15 00:11:15 -05:00
|
|
|
|
2018-08-18 15:16:42 -05:00
|
|
|
set list listchars=tab:>>,trail:~
|
|
|
|
if has('multi_byte') && $DISPLAY !=? ''
|
2018-07-15 00:11:15 -05:00
|
|
|
set listchars=tab:»»,trail:•
|
|
|
|
set fillchars=vert:┃ showbreak=↪
|
|
|
|
endif
|
2018-06-16 21:09:51 -05:00
|
|
|
|
2018-08-18 15:16:42 -05:00
|
|
|
" ------ commands ------
|
|
|
|
|
|
|
|
command! D Explore
|
|
|
|
command! R call <SID>ranger()
|
|
|
|
command! Q call <SID>quitbuffer()
|
|
|
|
command! -nargs=1 B :call <SID>bufferselect("<args>")
|
|
|
|
command! W execute 'silent w !sudo tee % >/dev/null' | edit!
|
|
|
|
|
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-08-18 15:16:42 -05:00
|
|
|
" match string to switch buffer
|
|
|
|
nnoremap <Leader>b :let b:buf = input('Match: ')<Bar>call <SID>bufferselect(b:buf)<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-07-13 16:01:38 -05:00
|
|
|
" change windows with ctrl+(hjkl)
|
|
|
|
nnoremap <C-J> <C-W><C-J>
|
|
|
|
nnoremap <C-K> <C-W><C-K>
|
|
|
|
nnoremap <C-L> <C-W><C-L>
|
|
|
|
nnoremap <C-H> <C-W><C-H>
|
|
|
|
|
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-07-13 16:01:38 -05:00
|
|
|
" j = gj :: k = gk while preserving numbered jumps eg. 12j
|
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-08-18 15:16:42 -05:00
|
|
|
" open a terminal in $PWD
|
|
|
|
nnoremap <silent> <Leader>tt :terminal<CR>
|
|
|
|
|
|
|
|
" tab control
|
|
|
|
nnoremap <silent> <M-j> :tabmove -1<CR>
|
|
|
|
nnoremap <silent> <M-k> :tabmove +1<CR>
|
|
|
|
nnoremap <silent> <Leader>te :tabnew<CR>
|
|
|
|
nnoremap <silent> <Leader>tn :tabnext<CR>
|
|
|
|
nnoremap <silent> <Leader>tf :tabfirst<CR>
|
|
|
|
nnoremap <silent> <Leader>tp :tabprevious<CR>
|
|
|
|
|
|
|
|
" close current buffer and/or tab
|
|
|
|
nnoremap <silent> <Leader>q :B<CR>:silent tabclose<CR>gT
|
|
|
|
nnoremap <silent> <Leader>tl :execute "tabn ".g:lasttab<CR>
|
|
|
|
|
2018-07-13 16:01:38 -05:00
|
|
|
" open a new tab in the current directory with netrw
|
|
|
|
nnoremap <silent> <Leader>- :tabedit <C-R>=expand("%:p:h")<CR><CR>
|
2018-06-16 21:09:51 -05:00
|
|
|
|
2018-08-18 15:16:42 -05:00
|
|
|
" split the window vertically and horizontally
|
|
|
|
nnoremap _ <C-W>s<C-W><Down>
|
|
|
|
nnoremap <Bar> <C-W>v<C-W><Right>
|
|
|
|
|
|
|
|
|
2018-06-16 21:09:51 -05:00
|
|
|
" ------ autocmd ------
|
|
|
|
|
2018-08-18 15:16:42 -05:00
|
|
|
let g:lasttab = 1
|
|
|
|
augroup save_last_tab
|
|
|
|
autocmd!
|
|
|
|
autocmd TabLeave * let g:lasttab = tabpagenr()
|
|
|
|
augroup END
|
|
|
|
|
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
|
2018-08-18 15:16:42 -05:00
|
|
|
autocmd FileChangedShellPost * echo "Changes loaded from source file"
|
2018-05-01 23:57:34 -05:00
|
|
|
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
|
|
|
|
2018-08-18 15:16:42 -05:00
|
|
|
" when not running in a console or a terminal that doesn't support 256 colors
|
|
|
|
" enable cursorline in the currently active window and disable it in inactive ones
|
|
|
|
if $DISPLAY !=? '' && &t_Co == 256
|
|
|
|
augroup cursorline
|
|
|
|
autocmd!
|
|
|
|
autocmd VimEnter,WinEnter,BufWinEnter * setlocal cursorline
|
|
|
|
autocmd WinLeave * setlocal nocursorline
|
|
|
|
augroup END
|
|
|
|
endif
|
2018-06-16 21:09:51 -05:00
|
|
|
|
|
|
|
" ------ adv maps ------
|
|
|
|
|
2018-11-05 00:19:12 -06:00
|
|
|
" visual quote surround
|
|
|
|
vnoremap ;' <Esc>:call QuickWrap("'")<CR>
|
|
|
|
vnoremap ;" <Esc>:call QuickWrap('"')<CR>
|
|
|
|
|
|
|
|
" quote 'surround'
|
|
|
|
nnoremap ;' ciW''<Esc>P
|
|
|
|
nnoremap ;'' ciw''<Esc>P
|
|
|
|
nnoremap ;" ciW""<Esc>P
|
|
|
|
nnoremap ;"" ciw""<Esc>P
|
|
|
|
|
|
|
|
" Smart Quotes
|
|
|
|
inoremap <expr> ' strpart(getline('.'), col('.')-1, 1) == "\'" ? "\<C-g>U\<Right>" : "''\<C-g>U\<Left>"
|
|
|
|
inoremap '' '
|
|
|
|
inoremap <expr> " strpart(getline('.'), col('.')-1, 1) == "\"" ? "\<C-g>U\<Right>" : '""'."\<C-g>U\<Left>"
|
|
|
|
inoremap "" "
|
|
|
|
|
|
|
|
" Smart Parens
|
|
|
|
"inoremap <expr> <BS> strpart(getline('.'), col('.')-1, 1) == ")" | "}" ? "\<Right><BS><BS>" : "<BS>"
|
|
|
|
inoremap <expr> ) strpart(getline('.'), col('.')-1, 1) == ")" ? "\<C-g>U\<Right>" : ")"
|
|
|
|
inoremap ( ()<C-g>U<Left>
|
|
|
|
inoremap (<CR> (<CR>)<Esc>O
|
|
|
|
inoremap (( (
|
|
|
|
inoremap () ()
|
|
|
|
|
|
|
|
" Smart Braces
|
|
|
|
inoremap <expr> } strpart(getline('.'), col('.')-1, 1) == "}" ? "\<C-g>U\<Right>" : "}"
|
|
|
|
inoremap { {}<C-g>U<Left>
|
|
|
|
inoremap {<CR> {<CR>}<Esc>O
|
|
|
|
inoremap {{ {
|
|
|
|
inoremap {} {}
|
|
|
|
|
|
|
|
" Smart Brackets
|
|
|
|
inoremap <expr> ] strpart(getline('.'), col('.')-1, 1) == "]" ? "\<C-g>U\<Right>" : "]"
|
|
|
|
inoremap [ []<C-g>U<Left>
|
|
|
|
inoremap [<CR> [<CR>]<Esc>O
|
|
|
|
inoremap [[ [
|
|
|
|
inoremap [] []
|
|
|
|
|
|
|
|
" Smart Brackets
|
|
|
|
inoremap <expr> > strpart(getline('.'), col('.')-1, 1) == ">" ? "\<C-g>U\<Right>" : ">"
|
|
|
|
inoremap < <><C-g>U<Left>
|
|
|
|
inoremap </ </><C-g>U<Left>
|
|
|
|
inoremap << <
|
|
|
|
inoremap <> <>
|
|
|
|
|
|
|
|
" Quote wrapper function
|
|
|
|
function! QuickWrap(wrapper)
|
|
|
|
let l:w = a:wrapper
|
|
|
|
let l:inside_or_around = (&selection ==? 'exclusive') ? ('i') : ('a')
|
|
|
|
normal `>
|
|
|
|
execute "normal " . inside_or_around . escape(w, '\')
|
|
|
|
normal `<
|
|
|
|
execute "normal i" . escape(w, '\')
|
|
|
|
normal `<
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2018-08-18 15:16:42 -05:00
|
|
|
" toggle line numbers, nn (no number)
|
2018-06-16 21:09:51 -05:00
|
|
|
nnoremap <silent> <Leader>nn
|
|
|
|
\ :if &number <Bar>
|
2018-08-18 15:16:42 -05:00
|
|
|
\ set nonumber
|
|
|
|
\ <Bar> echo 'Line numbers disabled'
|
2018-06-16 21:09:51 -05:00
|
|
|
\ <Bar> else <Bar>
|
2018-08-18 15:16:42 -05:00
|
|
|
\ set number
|
|
|
|
\ <Bar> echo 'Line numbers enabled'
|
2018-06-16 21:09:51 -05:00
|
|
|
\ <Bar> endif<CR>
|
|
|
|
|
2018-08-18 15:16:42 -05:00
|
|
|
" strip trailing whitespace, ss (strip space)
|
2018-06-16 21:09:51 -05:00
|
|
|
nnoremap <silent> <Leader>ss
|
2018-08-18 15:16:42 -05:00
|
|
|
\ :let b:_p = getpos(".") <Bar>
|
|
|
|
\ let b:_s = (@/ != '') ? @/ : '' <Bar>
|
2018-06-16 21:09:51 -05:00
|
|
|
\ %s/\s\+$//e <Bar>
|
2018-08-18 15:16:42 -05:00
|
|
|
\ let @/ = b:_s <Bar>
|
2018-06-16 21:09:51 -05:00
|
|
|
\ nohlsearch <Bar>
|
2018-08-18 15:16:42 -05:00
|
|
|
\ unlet b:_s <Bar>
|
|
|
|
\ call setpos('.', b:_p) <Bar>
|
|
|
|
\ unlet b:_p <CR>
|
2018-06-16 21:09:51 -05:00
|
|
|
|
|
|
|
" 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>
|
2018-11-05 00:19:12 -06:00
|
|
|
|
2018-06-16 21:09:51 -05:00
|
|
|
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>
|
|
|
|
|
2018-08-18 15:16:42 -05:00
|
|
|
" highlight long lines, ll (long lines)
|
|
|
|
let w:longlines = matchadd('ColorColumn', '\%'.&textwidth.'v', &textwidth)
|
2018-06-16 21:09:51 -05:00
|
|
|
nnoremap <silent> <Leader>ll
|
|
|
|
\ :if exists('w:longlines') <Bar>
|
|
|
|
\ silent! call matchdelete(w:longlines) <Bar>
|
2018-08-18 15:16:42 -05:00
|
|
|
\ echo 'Long line highlighting disabled'
|
|
|
|
\ <Bar> unlet w:longlines <Bar>
|
2018-06-16 21:09:51 -05:00
|
|
|
\ elseif &textwidth > 0 <Bar>
|
|
|
|
\ let w:longlines = matchadd('ColorColumn', '\%'.&textwidth.'v', &textwidth) <Bar>
|
2018-08-18 15:16:42 -05:00
|
|
|
\ echo 'Long line highlighting enabled'
|
|
|
|
\ <Bar> else <Bar>
|
|
|
|
\ let w:longlines = matchadd('ColorColumn', '\%80v', 81) <Bar>
|
|
|
|
\ echo 'Long line highlighting enabled'
|
|
|
|
\ <Bar> endif <CR>
|
2018-06-16 21:09:51 -05:00
|
|
|
|
|
|
|
" 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>
|
|
|
|
|
|
|
|
|
2018-08-18 15:16:42 -05:00
|
|
|
" quit the current buffer and switch to the next
|
|
|
|
" without this vim will leave you on an empty buffer after quiting the current
|
|
|
|
function! <SID>quitbuffer() abort
|
|
|
|
let l:bf = bufnr('%')
|
|
|
|
let l:pb = bufnr('#')
|
|
|
|
if buflisted(l:pb)
|
|
|
|
buffer #
|
|
|
|
else
|
|
|
|
bnext
|
|
|
|
endif
|
|
|
|
if bufnr('%') == l:bf
|
|
|
|
new
|
|
|
|
endif
|
|
|
|
if buflisted(l:bf)
|
|
|
|
execute('bdelete! ' . l:bf)
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" switch active buffer based on pattern matching
|
|
|
|
" if more than one match is found then list the matches to choose from
|
|
|
|
function! <SID>bufferselect(pattern) abort
|
|
|
|
let l:bufcount = bufnr('$')
|
|
|
|
let l:currbufnr = 1
|
|
|
|
let l:nummatches = 0
|
|
|
|
let l:matchingbufnr = 0
|
|
|
|
" walk the buffer count
|
|
|
|
while l:currbufnr <= l:bufcount
|
|
|
|
if (bufexists(l:currbufnr))
|
|
|
|
let l:currbufname = bufname(l:currbufnr)
|
|
|
|
if (match(l:currbufname, a:pattern) > -1)
|
|
|
|
echo l:currbufnr.': '.bufname(l:currbufnr)
|
|
|
|
let l:nummatches += 1
|
|
|
|
let l:matchingbufnr = l:currbufnr
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
let l:currbufnr += 1
|
|
|
|
endwhile
|
|
|
|
|
|
|
|
" only one match
|
|
|
|
if (l:nummatches == 1)
|
|
|
|
execute ':buffer '.l:matchingbufnr
|
|
|
|
elseif (l:nummatches > 1)
|
|
|
|
" more than one match
|
|
|
|
let l:desiredbufnr = input('Enter buffer number: ')
|
|
|
|
if (strlen(l:desiredbufnr) != 0)
|
|
|
|
execute ':buffer '.l:desiredbufnr
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
echoerr 'No matching buffers'
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-06-16 21:09:51 -05:00
|
|
|
" open ranger as a file chooser
|
|
|
|
function! <SID>ranger()
|
|
|
|
let l:temp = tempname()
|
2018-08-18 15:16:42 -05:00
|
|
|
execute 'silent !xterm -e ranger --choosefiles='.shellescape(l:temp).' $PWD'
|
2018-06-16 21:09:51 -05:00
|
|
|
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
|