-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
210 lines (178 loc) · 5.68 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
set nocompatible
" Set leader to spacebar, needs to be set before any mappings
let mapleader=" "
" Load plugins
if filereadable(expand('~/.vim/plugins.vim'))
source ~/.vim/plugins.vim
endif
" Load google-specific config on goob
if filereadable(expand('~/.vim/google.vim'))
source ~/.vim/google.vim
endif
" Colors
set t_Co=256 " always use 256 colors
let g:solarized_termcolors=256 " im serious about this
set background=dark
colorscheme hybrid " set color scheme (depends on flazz/vim-colorschemes)
" UI Config
set number " line numbers on
set relativenumber " note using plugin jeffkreeftmeijer/vim-numbertoggle
set showcmd " show incomplete commands at bottom right
set showmatch " briefly highlight matched bracket when pair completed
set ruler " display line and col numbers in bottom right
set wildmenu " tab complete in command line
set wildmode=list:longest,list:full
set lazyredraw " save some cycles: dont redraw during macros
set list listchars=tab:»·,trail:· " show trailing whitespace and tabs
set cursorline " highlight the line we are currently on
set colorcolumn=80 " draw line at 80 cols
if !has('nvim') && &ttimeoutlen == -1
set ttimeout
set ttimeoutlen=100
endif
" Whitespace
set tabstop=2
set shiftwidth=2
set softtabstop=2
set smarttab
set expandtab
set autoindent
" Windows
set splitright " Open new split panes to right
set splitbelow " and bottom, which feels more natural
" File writing
command! W w
set nowritebackup
set backupdir=/tmp//
set backupcopy=yes
set noswapfile
set autoread
set autowriteall
augroup autosave
" autowriteall doesn't capture tab changing, write all on lost focus
autocmd!
autocmd BufLeave * silent! wa
autocmd FocusLost * silent! wa
autocmd TabLeave * silent! wa
augroup END
augroup autoread
autocmd!
au FocusGained,BufEnter * :checktime
augroup END
" Undo
set undofile
set undolevels=1000 " max changes
set undoreload=10000 " max lines saved on buffer reload
set undodir=~/.vim/undodir
if empty(glob(&undodir))
call system('mkdir ' . &undodir)
endif
" Searching
set incsearch " Find the next match as we type the search
set ignorecase " Ignore case when searching...
set smartcase " ...unless we type a capital
" Other settings
set mouse=a " use the mouse
set exrc " enable per-directory .vimrc files
set secure " disable unsafe commands in local .vimrc files
set formatoptions+=j " remove comment prefixes when joining lines
set formatoptions-=o " dont add comment prefix on o/O
" Non-leader mappings
nnoremap ; :
inoremap <C-c> <esc>:x<CR>
nnoremap <C-c> :x<CR>
" Use <C-\> to clear the highlighting of :set hlsearch.
nnoremap <silent> <C-\> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
" Leader mappings (use :map <leader> to see all mappings in alphabetical order)
" Whitespace
nnoremap <leader>S :%s/\s\+$//<CR>
" Organizing
vnoremap <leader>s :sort<CR>
nnoremap <leader>s {jV}k:sort<CR>
" Window mgmt
nnoremap <leader>t :tabe<CR>
nnoremap <leader>sv :vs<CR>
nnoremap <leader>sh :sp<CR>
nnoremap <leader>- :exe "resize " . (winheight(0) * 2/3)<CR>
nnoremap <leader>+ :exe "resize " . (winheight(0) * 3/2)<CR>
nnoremap <leader>j <C-w>j
nnoremap <leader>k <C-w>k
nnoremap <leader>h <C-w>h
nnoremap <leader>l <C-w>l
" or with control keys
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
" Tab mgmt
nnoremap <leader>[ :tabN<CR>
nnoremap <leader>] :tabn<CR>
nnoremap <leader>{ :tabm -1<CR>
nnoremap <leader>} :tabm +1<CR>
nnoremap <leader>T :tabc<CR>
" File nav
nnoremap <leader>o :CtrlP<CR>
nnoremap <leader>bo :CtrlPBuffer<CR>
nnoremap <leader>d :e %:p:h<CR>
" Replace all
nnoremap <leader>r :%s/<c-r>=expand("<cword>")<cr>/<c-r>=expand("<cword>")<cr>
vnoremap <leader>r "sy:%s/<c-r>s/<c-r>s
" Replace in line
nnoremap <leader>lr :s/<c-r>=expand("<cword>")<cr>/
" For vimdiff
nnoremap <leader>1 :diffget LOCAL<cr>
nnoremap <leader>2 :diffget BASE<cr>
nnoremap <leader>3 :diffget REMOTE<cr>
" Copy/pasting from system registers
nnoremap <leader>p "+
vnoremap <leader>p "+
" Copy/pasting over ssh to osx
function! PropagatePasteBufferToOSX()
let @n=getreg('"')
call system('pbcopy-remote', @n)
echo "done"
endfunction
function! PopulatePasteBufferFromOSX()
let @" = system('pbpaste-remote')
echo "done"
endfunction
nnoremap <leader>bp :call PopulatePasteBufferFromOSX()<cr>
nnoremap <leader>bc :call PropagatePasteBufferToOSX()<cr>
vnoremap <leader>bc y:call PropagatePasteBufferToOSX()<cr>
" Edit/reload the vimrc file
nnoremap <leader>ve :e ~/.vimrc<CR>
nnoremap <leader>vs :so $MYVIMRC<CR>
augroup sourcereload
autocmd!
autocmd BufWritePost $MYVIMRC source $MYVIMRC
autocmd BufWritePost vimrc source $MYVIMRC
autocmd BufWritePost *.vim source $MYVIMRC
autocmd BufWritePost .tmux.conf :!tmux source-file ~/.tmux.conf
augroup END
" Using plug
nnoremap <leader>vi :so $MYVIMRC<CR>:PlugClean!<CR>:PlugInstall<CR>
nnoremap <leader>vp :e ~/.vim/plugins.vim<CR>
nnoremap <leader>vu :so $MYVIMRC<CR>:PlugClean!<CR>:PlugUpgrade<CR>:PlugUpdate<CR>
" Saving and Exiting
command! Q q
nnoremap <leader>q :q<CR>
nnoremap <leader>Q :qall!<CR>
nnoremap <leader>w :w<CR>
" Enable syntax highlighting
syntax enable
syntax on
" Spell-check Markdown files and Git Commit Messages
augroup spellchecking
autocmd!
autocmd FileType markdown setlocal spell
autocmd FileType gitcommit setlocal spell
autocmd FileType markdown syn match UrlNoSpell '\w\+:\/\/[^[:space:]]\+' contains=@NoSpell
augroup END
" Copilot
let b:copilot_enabled = v:true
" let g:copilot_proxy = 'http://localhost:8080'
" let g:copilot_proxy_strict_ssl = v:false
" let g:copilot_proxy = 'http://localhost:3128'
command! -nargs=? -complete=customlist,copilot#CommandComplete C Copilot <args>
" Turn plugins back on (needs to be last line)
filetype plugin indent on