nnoremap ,f :find *
nnoremap ,s :sfind *
nnoremap ,v :vert sfind *
nnoremap ,t :tabfind *
nnoremap ,F :find <C-R>=fnameescape(expand('%:p:h')).'/**/*'<CR>
nnoremap ,S :sfind <C-R>=fnameescape(expand('%:p:h')).'/**/*'<CR>
nnoremap ,V :vert sfind <C-R>=fnameescape(expand('%:p:h')).'/**/*'<CR>
nnoremap ,T :tabfind <C-R>=fnameescape(expand('%:p:h')).'/**/*'<CR>
" MRU command-line completion
function! s:MRUComplete(ArgLead, CmdLine, CursorPos)
return filter(copy(v:oldfiles), 'v:val =~ a:ArgLead')
endfunction
" MRU function
function! s:MRU(command, arg)
if a:command == "tabedit"
execute a:command . " " . a:arg . "|lcd %:p:h"
else
execute a:command . " " . a:arg
endif
endfunction
" commands
command! -nargs=1 -complete=customlist,<sid>MRUComplete ME call <sid>MRU('edit', <f-args>)
command! -nargs=1 -complete=customlist,<sid>MRUComplete MS call <sid>MRU('split', <f-args>)
command! -nargs=1 -complete=customlist,<sid>MRUComplete MV call <sid>MRU('vsplit', <f-args>)
command! -nargs=1 -complete=customlist,<sid>MRUComplete MT call <sid>MRU('tabedit', <f-args>)
I recently turned it into a handy micro-plugin.
nnoremap gb :ls<CR>:buffer<Space>
nnoremap gB :ls<CR>:sbuffer<Space>
nnoremap ,b :buffer *
nnoremap ,B :sbuffer *
I like completion but I hate it when it's automatic. Therefore I only have a bunch of useful completion mappings which are not really an alternative to ACP, YCM, or whatever:
inoremap ,, <C-x><C-o><C-r>=pumvisible() ? "\<lt>Down>\<lt>C-p>\<lt>Down>" : ""<CR>
inoremap ,; <C-n><C-r>=pumvisible() ? "\<lt>Down>\<lt>C-p>\<lt>Down>" : ""<CR>
inoremap ,: <C-x><C-f><C-r>=pumvisible() ? "\<lt>Down>\<lt>C-p>\<lt>Down>" : ""<CR>
inoremap ,= <C-x><C-l><C-r>=pumvisible() ? "\<lt>Down>\<lt>C-p>\<lt>Down>" : ""<CR>
command! -nargs=+ -complete=file_in_path -bar Grep silent! grep! <args> | redraw!
command! -nargs=+ -complete=file_in_path -bar LGrep silent! lgrep! <args> | redraw!
nnoremap <silent> ,G :Grep <C-r><C-w><CR>
if executable("ag")
set grepprg=ag\ --nogroup\ --nocolor\ --ignore-case\ --column\ --vimgrep
set grepformat=%f:%l:%c:%m,%f:%l:%m
endif
nnoremap <Space><Space> :'{,'}s/\<<C-r>=expand('<cword>')<CR>\>/
nnoremap <Space>% :%s/\<<C-r>=expand('<cword>')<CR>\>/
nnoremap ,; *``cgn
nnoremap ,, #``cgN
nnoremap ,j :tjump /
nnoremap ,p :ptjump /
nnoremap ,d :dlist /
nnoremap [D [D:djump <C-r><C-w><S-Left><Left>
nnoremap ]D ]D:djump <C-r><C-w><S-Left><Left>
nnoremap ,i :ilist /
nnoremap [I [I:ijump <C-r><C-w><S-Left><Left><Left>
nnoremap ]I ]I:ijump <C-r><C-w><S-Left><Left><Left>
command! -range=% SP silent execute <line1> . "," . <line2> . "w !curl -F 'sprunge=<-' http://sprunge.us | tr -d '\\n' | pbcopy"
command! -range=% IX silent execute <line1> . "," . <line2> . "w !curl -F 'f:1=<-' ix.io | tr -d '\\n' | pbcopy"
setlocal errorformat=%f:\ line\ %l\\,\ col\ %c\\,\ %m,%-G%.%#
setlocal makeprg=jshint
autocmd! BufWritePost <buffer> silent make! % | silent redraw! | silent wincmd p
command! -buffer -range=% Format let b:winview = winsaveview() |
\ execute <line1> . "," . <line2> . "!js-beautify -f - -j -t -s " . &shiftwidth |
\ call winrestview(b:winview)
I don't like autoclosing brackets and quotes but I *love* "autoexpansion".
inoremap (<CR> (<CR>)<Esc>O
inoremap {<CR> {<CR>}<Esc>O
inoremap {; {<CR>};<Esc>O
inoremap {, {<CR>},<Esc>O
inoremap [<CR> [<CR>]<Esc>O
inoremap [; [<CR>];<Esc>O
inoremap [, [<CR>],<Esc>O
cnoremap <expr> <Tab> getcmdtype() == "/" \|\| getcmdtype() == "?" ? "<CR>/<C-r>/" : "<C-z>"
cnoremap <expr> <S-Tab> getcmdtype() == "/" \|\| getcmdtype() == "?" ? "<CR>?<C-r>/" : "<S-Tab>"
command! SC vnew | setlocal nobuflisted buftype=nofile bufhidden=wipe noswapfile
augroup minivimrc
autocmd!
" automatic location/quickfix window
autocmd QuickFixCmdPost [^l]* cwindow
autocmd QuickFixCmdPost l* lwindow
augroup END
function! s:CCR()
if getcmdtype() == ":"
let cmdline = getcmdline()
if cmdline =~ '\v\C^(dli|il)' | return "\<CR>:" . cmdline[0] . "jump " . split(cmdline, " ")[1] . "\<S-Left>\<Left>"
elseif cmdline =~ '\v\C^(cli|lli)' | return "\<CR>:silent " . repeat(cmdline[0], 2) . "\<Space>"
elseif cmdline =~ '\C^old' | return "\<CR>:edit #<"
elseif cmdline =~ '\C^ls' | return "\<CR>:b"
elseif cmdline =~ '/#$' | return "\<CR>:"
else | return "\<CR>" | endif
else | return "\<CR>" | endif
endfunction
cnoremap <expr> <CR> <SID>CCR()