-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
161 lines (131 loc) · 4.92 KB
/
Copy pathvimrc
File metadata and controls
161 lines (131 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
" backup, undo and swap with XDG support
if empty($XDG_CACHE_HOME) | let $XDG_CACHE_HOME = $HOME."/.cache" | endif
set backupdir=$XDG_CACHE_HOME/vim/backup | call mkdir(&backupdir, 'p', 0700)
set directory=$XDG_CACHE_HOME/vim/swap | call mkdir(&directory, 'p', 0700)
set undodir=$XDG_CACHE_HOME/vim/undo | call mkdir(&undodir, 'p', 0700)
set backup
set undofile
set swapfile
" filetype support
filetype plugin indent on
syntax on
runtime macros/matchit.vim
" various settings
set autoindent
set autoread
set backspace=indent,eol,start
set clipboard^=unnamed
set complete+=d
set completeopt+=menuone,noinsert,noselect
set foldlevelstart=999
set foldmethod=indent
set grepprg=LC_ALL=C\ grep\ -nrsH
set hidden
set incsearch
set laststatus=2
set number
set path=.,,**
set ruler
set shiftround
set tags=./tags;,tags;
set virtualedit=block
set visualbell t_vb=
set wildcharm=<C-z>
set wildmenu
colorscheme dim
" use ripgrep if it's there
if executable('rg')
set grepformat=%f:%l:%c:%m
set grepprg=rg\ --vimgrep\ --no-heading\ $*
endif
augroup myvimrc
autocmd!
" automatic location/quickfix window
autocmd QuickFixCmdPost [^l]* cwindow
autocmd QuickFixCmdPost l* lwindow
autocmd VimEnter * cwindow
autocmd FileType gitcommit nnoremap <buffer> { ?^@@<CR>|nnoremap <buffer> } /^@@<CR>|setlocal iskeyword+=-
autocmd CompleteDone * silent! pclose
" undo if filter shell command returned an error
autocmd ShellFilterPost * if v:shell_error | undo | endif
augroup END
" files
nnoremap <Leader>f :find *
nnoremap <Leader>s :sfind *
nnoremap <Leader>v :vertical sfind *
nnoremap <Leader>t :tabfind *
" buffers
nnoremap <Leader>b :buffer *
nnoremap <Leader>a :buffer#<CR>
" command-line
cnoremap <C-k> <Up>
cnoremap <C-j> <Down>
" tags
nnoremap <Leader>j :tjump /
nnoremap <Leader>p :ptjump /
" definitions
nnoremap <Leader>d :dlist /
nnoremap [D [D:djump<Space><Space><Space><C-r><C-w><S-Left><Left>
nnoremap ]D ]D:djump<Space><Space><Space><C-r><C-w><S-Left><Left>
" matches
nnoremap <Leader>i :ilist /
nnoremap [I [I:ijump<Space><Space><Space><C-r><C-w><s-left><Left><Left>
nnoremap ]I ]I:ijump<Space><Space><Space><C-r><C-w><S-Left><Left><Left>
" location/quickfix entries
nnoremap [q :cprevious<CR>
nnoremap ]q :cnext<CR>
nnoremap [l :lprevious<CR>
nnoremap ]l :lnext<CR>
" search and replace
nnoremap <Space><Space> :'{,'}s/\<<C-r>=expand("<cword>")<CR>\>/
nnoremap <Space>% :%s/\<<C-r>=expand("<cword>")<CR>\>/
" global commands
nnoremap <Leader>g :g//#<Left><Left>
" windows
nnoremap <silent> <C-w>z :wincmd z<Bar>cclose<Bar>lclose<CR>
" background
nnoremap [b :<C-U>set background=<C-R>=&background == "dark" ? "light" : "dark"<CR><CR>
" grepping
function! Grep(...)
return system(join([&grepprg] + [expandcmd(join(a:000, ' '))], ' '))
endfunction
command! -nargs=+ -complete=file_in_path -bar Grep cgetexpr Grep(<f-args>)
command! -nargs=+ -complete=file_in_path -bar LGrep lgetexpr Grep(<f-args>)
cnoreabbrev <expr> grep (getcmdtype() ==# ':' && getcmdline() ==# 'grep') ? 'Grep' : 'grep'
cnoreabbrev <expr> lgrep (getcmdtype() ==# ':' && getcmdline() ==# 'lgrep') ? 'LGrep' : 'lgrep'
" searching
cnoremap <expr> <Tab> getcmdtype() == "/" \|\| getcmdtype() == "?" ? "<CR>/<C-r>/" : "<C-z>"
cnoremap <expr> <S-Tab> getcmdtype() == "/" \|\| getcmdtype() == "?" ? "<CR>?<C-r>/" : "<S-Tab>"
" listing
cnoremap <expr> <CR> <SID>CCR()
function! s:CCR()
command! -bar Z silent set more|delcommand Z
if getcmdtype() ==# ':'
let cmdline = getcmdline()
if cmdline =~# '\v\C^(dli|il)' | return "\<CR>:" . cmdline[0] . 'jump ' . split(cmdline, ' ')[1] . "\<S-Left>\<Left>\<Left>"
elseif cmdline =~# '\v\C^(cli|lli)' | return "\<CR>:silent " . repeat(cmdline[0], 2) . "\<Space>"
elseif cmdline =~# '\C^changes' | set nomore | return "\<CR>:Z|norm! g;\<S-Left>"
elseif cmdline =~# '\C^ju' | set nomore | return "\<CR>:Z|norm! \<C-o>\<S-Left>"
elseif cmdline =~# '\v\C(#|nu|num|numb|numbe|number)$' | return "\<CR>:"
elseif cmdline =~# '\C^ol' | set nomore | return "\<CR>:Z|e #<"
elseif cmdline =~# '\v\C^(ls|files|buffers)' | return "\<CR>:b"
elseif cmdline =~# '\C^marks' | return "\<CR>:norm! `"
elseif cmdline =~# '\C^undol' | return "\<CR>:u "
else | return "\<CR>" | endif
else | return "\<CR>" | endif
endfunction
" scratch buffer
command! SC vnew | setlocal nobuflisted buftype=nofile bufhidden=wipe noswapfile
" sudo write
command! SudoW exec 'silent! write !sudo tee % >/dev/null' | edit!
" portable git blame
command! -range GB echo join(systemlist("git -C " . shellescape(expand('%:p:h')) . " blame -L <line1>,<line2> " . expand('%:t')), "\n")
" location list :global
set errorformat^=%f:%l:%c\ %m
command! -nargs=1 Global lgetexpr filter(map(getline(1,'$'), {key, val -> expand("%") . ":" . (key + 1) . ":1 " . val }), { idx, val -> val =~ <q-args> })
nnoremap <Leader>G :Global
" create directories
nnoremap <Leader>m :!mkdir -p %:h<CR>
" plugins
let g:netrw_liststyle = 3
let g:netrw_localrmdir='rm -r'