-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.vim
228 lines (181 loc) · 6.98 KB
/
init.vim
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
call plug#begin()
" General
Plug 'tpope/vim-sensible'
" Text editing
Plug 'ervandew/supertab'
Plug 'tpope/vim-endwise'
Plug 'tpope/vim-surround'
Plug 'scrooloose/nerdcommenter'
Plug 'raimondi/delimitmate'
"Search and replace
Plug 'ctrlpvim/ctrlp.vim'
Plug 'google/vim-searchindex'
" Linters
Plug 'w0rp/ale'
Plug 'jparise/vim-graphql'
" Language Support
Plug 'sheerun/vim-polyglot'
" Git
Plug 'tpope/vim-fugitive'
Plug 'shumphrey/fugitive-gitlab.vim'
Plug 'tpope/vim-rhubarb'
Plug 'airblade/vim-gitgutter'
" Themes
" Plug 'nanotech/jellybeans.vim'
" Plug 'vim-airline/vim-airline-themes'
" Layout
Plug 'vim-airline/vim-airline'
Plug 'justincampbell/vim-eighties' " sensible buffer resizing
Plug 'scrooloose/nerdtree'
" Testing
Plug 'janko-m/vim-test'
" File editing
Plug 'pbrisbin/vim-mkdir'
Plug 'henrik/rename.vim'
" Ruby Stuff
Plug 'tpope/vim-bundler'
Plug 'tpope/vim-rails'
" Code Completion
Plug 'github/copilot.vim'
call plug#end()
" ------------------------------------------------------------------------------
" General Settings
" ------------------------------------------------------------------------------
set nocompatible " Disable Vi comptability
let mapleader = ","
set encoding=utf8
set nobackup " Disable backups.
set nowritebackup
set noswapfile
set updatetime=500 " Refresh vim-gitgutter more often
set clipboard+=unnamedplus " Copy into system clipboard
" Quicker window movement
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
" Move to previous buffer with gb
nnoremap gb <C-^>
" NERDTree
nnoremap <Leader>nt :NERDTreeToggle<CR>
nnoremap <Leader>nf :NERDTreeFind<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" ------------------------------------------------------------------------------
" Text Editing
" ------------------------------------------------------------------------------
filetype on " Enable filetype detection
filetype indent on " Enable filetype-specific indenting
filetype plugin on " Enable filetype-specific plugins
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
" Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDDefaultAlign = 'left'
" ------------------------------------------------------------------------------
" Spell Checking
" ------------------------------------------------------------------------------
set spelllang=en_gb,en_us
augroup customSpellChecking
autocmd!
autocmd FileType markdown setlocal spell
autocmd FileType gitcommit setlocal spell
autocmd FileType text setlocal spell
augroup END
set complete+=kspell
" ------------------------------------------------------------------------------
" White Space
" ------------------------------------------------------------------------------
set tabstop=2 " Set tab to equal 4 spaces.
set softtabstop=2 " Set soft tabs equal to 4 spaces.
set shiftwidth=2 " Set auto indent spacing.
set shiftround " Shift to the next round tab stop.
set expandtab " Expand tabs into spaces.
set list listchars=tab:»·,trail:·,nbsp:· " Show leading whitespace
set nojoinspaces " Use one space, not two, after punctuation.
" ------------------------------------------------------------------------------
" Search and Replace
" ------------------------------------------------------------------------------
set ignorecase " Enable case insensitive search.
set smartcase " Disable case insensitivity if mixed case.
" ------------------------------------------------------------------------------
" Ag/grep
" ------------------------------------------------------------------------------
if executable('ag')
" If ag is available, we should use it because it's much faster than grep!
let g:ctrlp_user_command = "ag %s -l --nocolor -g ''"
set grepprg=ag\ --nogroup\ --nocolor
" bind \ (backward slash) to grep shortcut
command -nargs=+ -complete=file -bar Ag silent! grep! <args>|cwindow|redraw!
nnoremap \ :Ag<SPACE>
endif
" bind K to grep word under cursor
nnoremap K :grep! "\b<C-R><C-W>\b"<CR>:cw<CR>
" ------------------------------------------------------------------------------
" Status Line
" ------------------------------------------------------------------------------
set laststatus=2 " Always display the status line
" ------------------------------------------------------------------------------
" Presentation
" ------------------------------------------------------------------------------
" colorscheme jellybeans
" let g:airline_theme='jellybeans'
" Numbers
set number
" ------------------------------------------------------------------------------
" Line Length
" ------------------------------------------------------------------------------
set textwidth=80
set colorcolumn=+1
augroup setPythonTextOptions
autocmd!
" The Black Python code formatter uses 88 as its default line-length.
autocmd FileType python setlocal textwidth=88
" Disable 'Auto-wrap text using textwidth' because python is whitespace aware
autocmd FileType python setlocal formatoptions-=t
augroup END
" ------------------------------------------------------------------------------
" Linter Config
" ------------------------------------------------------------------------------
let g:ale_sign_column_always = 1
let g:airline#extensions#ale#enabled = 1
" ------------------------------------------------------------------------------
" Code fixers
" ------------------------------------------------------------------------------
" Configure fixers on a filetype basis. Most of these fixers do not come
" pre-installed so you will need to install them individually. E.g.
"
" gem install rubocop
" npm install --global prettier
" pip install black
" etc.
let g:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
\ 'ruby': ['rubocop'],
\ 'elixir': ['mix_format'],
\ 'javascript': ['prettier'],
\ 'python': ['black'],
\ 'json': ['prettier'],
\ 'yaml': ['prettier'],
\ 'graphql': ['prettier'],
\ 'html': ['prettier'],
\ 'terraform': ['terraform'],
\ 'markdown': ['prettier']
\ }
" Activate the above fixers
nnoremap <leader>f :ALEFix<CR>
" ------------------------------------------------------------------------------
" Testing
" ------------------------------------------------------------------------------
" When using neovim use "neovim" test strategy and remap <C-\><C-n> to <C-o> to
" allow you to enter normal mode easier and scroll through test output.
if has('nvim')
let test#strategy = "neovim"
tmap <C-o> <C-\><C-n>
end
nmap <silent> <leader>t :TestNearest<CR>
nmap <silent> <leader>T :TestFile<CR>
nmap <silent> <leader>l :TestLast<CR>
nmap <silent> <leader>g :TestVisit<CR>
" Local config
if filereadable($HOME . "/.vimrc.local")
source ~/.vimrc.local
endif