-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
210 lines (183 loc) · 6.29 KB
/
.vimrc
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
let g:gutentags_cache_dir = "~/.nvim/tags"
""BEHAVIOUR
syntax enable
noremap <F12> <Esc>:syntax sync fromstart<CR>
inoremap <F12> <C-o>:syntax sync fromstart<CR>
"Open file at same line as when closed
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal! g'\"" | endif
if has('macunix')
let g:netrw_browsex_viewer= "open"
endif
filetype indent plugin on
set backspace=indent,eol,start
set modeline
set tabstop=4
set shiftwidth=2
set expandtab
"set softtabstop=4
set splitright
nnoremap n nzz
nnoremap N Nzz
set mouse=r
tnoremap <Esc> <C-\><C-n>
autocmd! FileType fzf tnoremap <buffer> <esc> <c-c>
set undofile
set undodir=~/.vim/undodir
set directory=~/.vim/swp
set backupdir=~/.vim/backup
""TOOLS
"Format JSON
command! -range -nargs=0 -bar JsonTool <line1>,<line2>!python -m json.tool
command Bd bp\|bd \#
"in case sudo is forgotten
cmap w!! %!sudo tee > /dev/null %
"F5 adds a timestamp
map <F5> o<CR><ESC>:put =strftime('%c')<CR>==o
fun! RangerChooser()
exec "silent !ranger --choosefile=/tmp/chosenfile " . expand("%:p:h")
if filereadable('/tmp/chosenfile')
exec 'edit ' . system('cat /tmp/chosenfile')
call system('rm /tmp/chosenfile')
endif
redraw!
endfun
map <Leader>x :call RangerChooser()<CR>
""VINEGAR
"nmap - <Plug>VinegarVerticalSplitUp
nmap - :Lexplore<CR>
let g:netrw_preview = 1
let g:netrw_winsize = 15
""GIT
nnoremap <Leader>gs :Git<CR>
nnoremap <Leader>ga :Gwrite<CR>
nnoremap <Leader>gc :Git commit -v -q<CR>
nnoremap <Leader>gd :Gitdiffsplit<CR>
nnoremap <Leader>go :Git checkout <Space>
nnoremap <Leader>gb :Git branch <Space>
nnoremap <Leader>gg :Ggrep <Space>
cnoreabbrev Gblame Gblame -w
autocmd BufWritePost * execute 'GitGutterAll'
autocmd Filetype gitcommit setlocal spell textwidth=72
hi def link gitcommitOverflow Error
""SEARCH
set ignorecase
set smartcase
set hlsearch
set incsearch
set wildmenu
set wildmode=longest,list,full
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
nnoremap <Leader><Leader> :Rg<CR>
nnoremap <Leader>f :FZF<CR>
nnoremap <Leader>c :Commits<CR>
nnoremap <Leader>: :History:<CR>
nnoremap <Leader>b :Buffers<CR>
nnoremap <Leader>t :Tags<CR>
"let g:fzf_commits_log_options = 'log1'
nmap <leader><tab> <plug>(fzf-maps-n)
xmap <leader><tab> <plug>(fzf-maps-x)
omap <leader><tab> <plug>(fzf-maps-o)
"Insert mode completion
imap <c-x><c-k> <plug>(fzf-complete-word)
imap <c-x><c-f> <plug>(fzf-complete-path)
imap <c-x><c-j> <plug>(fzf-complete-file-ag)
imap <c-x><c-l> <plug>(fzf-complete-line)
if executable('rg')
set grepprg=rg\ --vimgrep
set grepformat=%f:%l:%c:%m
elseif executable('ag')
set grepprg=ag\ --vimgrep
set grepformat=%f:%l:%c:%m,%f:%l:%m
elseif executable('ack')
set grepprg=ack\ --nogroup\ --nocolor\ --ignore-case\ --column
set grepformat=%f:%l:%c:%m,%f:%l:%m
endif
" Project selector
function! s:projects_sink(lines)
if len(a:lines) < 1
return
endif
let dir = a:lines[0]
call fzf#vim#files(dir, {})
startinsert
endfunction
function! ProjectileProject()
let projects = 'find ~/code ~/code/infrastructure-modules/* ~/code/*/modules ~/code/infrastructure-live -maxdepth 1 -mindepth 1 -type d -not -name .git -not -name .github'
return fzf#run(fzf#wrap('projects', {'source': projects, 'sink*': function('s:projects_sink')}))
"return fzf#run('files', {'source': projects, 'sink*': 'cd'})
endfunction
nnoremap <Leader>p :call ProjectileProject()<CR>
function! EnteringBuffer()
if filewritable(expand('%:p:h')) != 2
return
endif
if &filetype == 'fugitive'
return
endif
exe 'cd %:p:h'
let top_level = system("git rev-parse --show-toplevel")
if v:shell_error == 0
exe 'cd' top_level
elseif v:shell_error == 128
if expand('%:p:h') == expand('~') || match(expand('%:p:h'), expand('~/.config')) == 0
let g:gitgutter_git_args = '--git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
endif
elseif v:shell_error != 128
echom v:shell_error
endif
endfunction
autocmd BufEnter * call EnteringBuffer()
"set autochdir
""THEME
" Set for transparent terminals
"highlight Normal guibg=none ctermbg=none
"set statusline=%F%m%r%h%w%=%y[%l,%c][%L][%{&ff}][%p%%]
set statusline=%<%f\ %h%m%r(%{FugitiveHead()})%{tagbar#currenttag('[%s]','')}%=%y[%l,%c][%L][%{&ff}][%p%%]
""NOTES
"Diary shortcut
nnoremap <Leader>w<Leader>w :vsplit ~/notes/diary/`date +\%Y-\%W`.md<CR>
"Search all Markdown headings
nnoremap <Leader>n :NV ^#<CR>
let g:markdown_fenced_languages = ['python', 'ruby', 'vim', 'sh', 'go', 'lua']
"TODO Shortcuts for searching todo.txt
nnoremap <Leader>a :vimgrep "(A)" ~/notes/todo.txt<CR>
au filetype todo setlocal omnifunc=todo#Complete
au filetype todo imap <buffer> + +<C-X><C-O>
au filetype todo imap <buffer> @ @<C-X><C-O>
let g:nv_default_extension = '.md'
let g:nv_keymap = {
\ 'ctrl-s': 'split ',
\ 'ctrl-v': 'vertical split ',
\ 'ctrl-t': 'tabedit ',
\ }
let g:nv_create_note_key = 'ctrl-x'
let g:nv_create_note_window = 'vertical split'
let g:nv_show_preview = 1
let g:nv_wrap_preview_text = 0
let g:nv_preview_width = '40%'
let g:nv_preview_direction = 'right'
let g:nv_use_short_pathnames = 1
let g:nv_expect_keys = []
"Navigate notes with `gf`
autocmd BufRead,BufNewFile ~/notes/* setlocal path+=~/notes/**
set suffixesadd+=.md
""LATEX
let g:tex_flavor='latex'
let g:Tex_DefaultTargetFormat = 'pdf'
let g:Tex_CompileRule_pdf = 'latexmk -pdf -pvc $*'
set iskeyword+=:
autocmd FileType tex setlocal makeprg=pdflatex\ --shell-escape\ '%'
""TERRAFORM TERRAGRUNT
nnoremap <Leader>rp :call AtlantisPlan()<CR>
"Only works when in the infrastructure-live root
command! Terragrunt vsplit | term cd %:p:h && aws-vault exec '%:s?/.*??-ops' -- terragrunt plan
command! TerragruntApply vsplit | term cd %:p:h && aws-vault exec '%:s?/.*??-ops' -- terragrunt apply
command! -range TFLocalModules <line1>,<line2>s^\vsource.*/([a-zA-Z1-9_-]+)\.git//([a-zA-Z1-9/-]+)\?ref=.*^source = "/Users/dancorne/code/\1//\2"^e | norm!``
command! -range -nargs=1 TFModuleVersion <line1>,<line2>s^\v(source.*)\?ref=.*^\1?ref=<args>"^e | norm!``
command! AtlantisPlan :execute "!gh pr view --web | Gpush | sleep 5 | \!gh run-plan"<CR>