-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
301 lines (239 loc) · 9.08 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
set nocompatible "use vim defaults
filetype off
let mapleader=","
let g:netrw_home="~/.vim/backup"
set encoding=utf-8
set fileencoding=utf-8
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" PLUGINS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
call plug#begin('~/.vim/plugged')
Plug 'altercation/vim-colors-solarized' " solarized theme
Plug 'mattn/gist-vim' " create gists
Plug 'mattn/webapi-vim' " dependency: gist-vim
Plug 'tpope/vim-endwise' " auto close blocks
Plug 'tpope/vim-fugitive' " git helpers
Plug 'tpope/vim-eunuch' " unix shell
Plug 'roxma/vim-tmux-clipboard' " tmux clipboard
Plug 'airblade/vim-gitgutter' " git diff in sign col
Plug 'scrooloose/nerdtree' " source tree file
Plug 'nvim-telescope/telescope.nvim' " search in files
Plug 'nvim-telescope/telescope-live-grep-args.nvim' " grep in files
Plug 'kdheepak/lazygit.nvim' " lazygit
"Plug 'sheerun/vim-polyglot' " Syntax highlight
" Copilot
Plug 'nvim-lua/plenary.nvim'
Plug 'zbirenbaum/copilot.lua'
Plug 'CopilotC-Nvim/CopilotChat.nvim'
call plug#end()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Commands
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
filetype plugin indent on
if &t_Co > 2 || has("gui_running")
set hlsearch
endif
autocmd BufWritePre * :%s/\s\+$//e
autocmd BufNewFile,BufRead *.slim setlocal filetype=slim
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" COLORS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax enable
set t_Co=256
set background=dark
colorscheme solarized
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" FOLDING
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set foldmethod=indent
set foldnestmax=10
set nofoldenable
set foldlevel=1
autocmd InsertEnter * if !exists('w:last_fdm') | let w:last_fdm=&foldmethod | setlocal foldmethod=manual | endif
autocmd InsertLeave,WinLeave * if exists('w:last_fdm') | let &l:foldmethod=w:last_fdm | unlet w:last_fdm | endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CONFIGS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Tab spacing/size
set tabstop=2 " number of spaces on tab
set softtabstop=2 " number of spaces on tab
set shiftwidth=2 " number of spaces to indent
set expandtab " convert tabs to spaces
set smarttab " insert tabs on the start of a line according to shiftwidth
set backspace=indent,eol,start
set listchars=tab:▸\ ,eol:¬,trail:·,precedes:«,extends:»
set textwidth=120
set linebreak
set showbreak=…
" Screen offset
set sidescroll=8
set scrolloff=8
set formatprg=par\ -TbgqRw80
set autoindent
set smartindent
set ignorecase " ignore case when searching
set smartcase " ignore case if search pattern is lowercase
set incsearch " show search matches as you type
set showmatch " highlight matching [{()}]
set matchtime=2
set ruler " show cursor pos on status bar
set number " show line number
set relativenumber " show relative line number
set autoread " auto reload file if changed outside vim
set wildmenu " show list of matches when tab completing
set wildmode=list:longest
set shortmess=atI " shorten messages
set timeoutlen=500
set wrap
set wrapmargin=120
set visualbell " no crazy beeping
set hidden
set title
set cc=+1
command! -nargs=* Wrap set wrap linebreak nolist
set backupdir=~/.vim/backup,~/tmp,/var/tmp,/tmp
set directory=~/.vim/backup,~/tmp,/var/tmp,/tmp
set completeopt=menu,menuone,longest
set pumheight=10
set wildignore+=*/.hg/*,*/.svn/*,*.o,moc_*.cpp,*.exe,*.qm,.gitkeep,.DS_Store
" Toggle paste mode with <lead>p
set pastetoggle=<leader>p
function! PasteCB()
set paste
set nopaste
endfunction
" Save/quit typos
cab W w| cab Q q| cab Wq wq| cab wQ wq| cab WQ wq| cab Bd bd| cab Wa wa| cab WA wa| cab X x
autocmd CursorHold * checktime
" Keep line index when reopening a file
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
" Sudo to write
cnoremap w!! w !sudo tee % >/dev/null
" set winwidth=84
" set winheight=10
" set winminheight=10
" set winheight=999
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" WINDOW MANAGEMENT "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Resize
noremap <Up> <C-w>+
noremap <Down> <C-w>-
noremap <Left> <C-w>>
noremap <Right> <C-w><
" Move around
noremap <C-j> <C-w>j
noremap <C-k> <C-w>k
noremap <C-h> <C-w>h
noremap <C-l> <C-w>l
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" FUNCTIONS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! OpenTestAlternate()
let new_file = AlternateForCurrentFile()
exec ':vsp ' . new_file
endfunction
function! AlternateForCurrentFile()
let current_file = expand("%")
let new_file = current_file
let in_spec = match(current_file, '^spec/') != -1
let going_to_spec = !in_spec
let in_app = match(current_file, '\<business\>') != -1 || match(current_file, '\<controllers\>') != -1 || match(current_file, '\<models\>') != -1 || match(current_file, '\<views\>') != -1 || match(current_file, '\<helpers\>') != -1
let in_lib = match(current_file, '^lib/') != -1
if going_to_spec
if in_app
let new_file = substitute(new_file, '^app/', '', '')
elseif in_lib
let new_file = substitute(new_file, '^lib/', '', '')
endif
let new_file = substitute(new_file, '\.rb$', '_spec.rb', '')
if in_lib
let new_file = 'spec/lib/' . new_file
else
let new_file = 'spec/' . new_file
endif
else
let new_file = substitute(new_file, '_spec\.rb$', '.rb', '')
let new_file = substitute(new_file, '^spec/', '', '')
if in_app
let new_file = 'app/' . new_file
elseif in_lib
let new_file = 'lib/' . new_file
endif
endif
return new_file
endfunction
nnoremap <leader>. :call OpenTestAlternate()<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" PLUGINS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""""
" Gist "
""""""""""""
let g:gist_open_browser_after_post = 1
let g:gist_post_private = 1
let g:gist_detect_filetype = 1
let g:gist_clip_command = 'xclip -selection clipboard'
let g:github_token = $GITHUB_TOKEN
"""""""""""""
" Telescope "
"""""""""""""
nnoremap <leader>ff <cmd>Telescope find_files<cr>
"nnoremap <leader>fg <cmd>Telescope live_grep<cr>
nnoremap <leader>fg :lua require("telescope").extensions.live_grep_args.live_grep_args()<cr>
nnoremap <leader>fb <cmd>Telescope buffers<cr>
nnoremap <leader>fh <cmd>Telescope help_tags<cr>
nnoremap <leader>fF :execute 'Telescope find_files default_text=' . expand('<cword>')<cr>
nnoremap <leader>fG :execute 'Telescope live_grep default_text=' . expand('<cword>')<cr>
"""""""""""""
" NERDTree "
"""""""""""""
autocmd FileType nerdtree cnoreabbrev <buffer> bd <nop>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" KeyBinds
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Open vimrc with <lead>v
nnoremap <leader>v :edit ~/.vimrc<CR>
" Reload vimrc with <lead>sv
nnoremap <leader>sv :source $MYVIMRC<CR>
" Clear buffer with <lead>c
nnoremap <leader>c :bufdo :bd<CR>
" Navigate on panes with tab
nnoremap <Tab> <c-w>w
" Open NERDTree with <C-n>
nnoremap <C-n> :NERDTreeToggle<CR>
" Previous tab with <F3>
nnoremap <F3> :tabprevious<CR>
" Next tab with <F4>
nnoremap <F4> :tabnext<CR>
" Copy selection to clipboard with <C-y>
vnoremap <C-y> "+y
" Open Copilot with <lead>gc
nnoremap <leader>gc :CopilotChat<CR>
" %% as current dir
cnoremap %% <C-R>=expand("%:h")."/"<CR>
" <lead>cb as buffer delete
cnoremap cb 1,100bdelete
" %f as current file
cnoremap %f <C-R>=expand("%")<CR>
" Clear the search buffer when hitting return
nnoremap <cr> :silent! nohlsearch<cr>|silent! redraw!
" Move to start of line with <lead><lead>
nnoremap <leader><leader> ^
" Move to end of line with \\
nnoremap \\ $
" Switch buffers with <leader>ea
nnoremap <leader>ea :b#<CR>
" Toggle fold with <space>
nnoremap <space> za
" Toggle invisible characters
nnoremap <leader>l :set list!<CR>
" Use <C-l> to insert " => "
imap <c-l> <space>=><space>
" Use <lead>e to open a file in new tab
map <leader>e :edit %%
" Map jj to <esc>
inoremap jj <esc>