forked from millyrowboat/dotvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.vim
300 lines (227 loc) · 9.09 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
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
"============================================================================"
"
" N E O V I M
"
"============================================================================"
" Forked with love from Steve Occhipinti (github.com/stevenocchipinti)
" https://github.com/millyrowboat/dotvim "
"============================================================================"
call plug#begin('~/.config/nvim/plugged')
Plug 'scrooloose/nerdtree'
Plug 'tpope/vim-commentary'
Plug 'itchyny/lightline.vim'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'vim-scripts/matchit.zip'
Plug 'editorconfig/editorconfig-vim'
Plug 'godlygeek/tabular'
Plug '/usr/local/opt/fzf'
Plug 'junegunn/fzf.vim'
" Technology specific plugins
Plug 'w0rp/ale'
Plug 'prettier/vim-prettier'
Plug 'wincent/terminus'
Plug 'sheerun/vim-polyglot'
Plug 'neoclide/coc.nvim', {'do': { -> coc#util#install()}}
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' }
Plug 'rainglow/vim'
Plug 'ryanoasis/vim-devicons'
call plug#end()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" STANDARD VIM SETTINGS "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set ts=2 sw=2 " Use 4 spaces for tabs
set expandtab " Use spaces instead of tab characters
set nowrap " (Dont) Wrap the display lines (not actual text)
set nu " Show line numbers
set splitright " Open vertical splits on the right
set splitbelow " Open the horizontal split below
set ruler " Show row and column in status bar
set showcmd " Show partial commands (such as 'd' when typing 'dw')
set ignorecase " Case insensitive search by default
set smartcase " Use case sensitive search in a capital letter is used
set nohlsearch " Don't highlight searches, useful for jumping around
set scrolloff=3 " Number of lines to always show at at the top & bottom
set colorcolumn=81,91 " Highlight the 81st column (shorthand = :set cc=81)
set cursorline " Highlight the line which the cursor is on
set nojoinspaces " Use 1 space after "." when joining lines instead of 2
set shiftround " Indent to the closest shiftwidth
set secure " Make sure those project .vimrc's are safe
set list " Show `listchars` characters
set listchars=tab:├─,trail:·
set showbreak=⤿
set hlsearch " Search highlighting
set number
set linespace=3
set termguicolors
" Make vim remember undos, even when the file is closed!
set undofile " Save undo's after file closes
set undodir=~/.vim/undo " where to save undo histories
set undolevels=1000 " How many undos
set undoreload=10000 " number of lines to save for undo
" COLOR!
colorscheme onedark
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" NEOVIM SPECIFIC (mostly bugfixes) "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("nvim")
" Live search and replace!
set inccommand=nosplit
" Use pipe in insert-mode and a block in normal-mode
let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1
" BUG: netrw is really slow
" No workaround yet except to use another file explorer
" BUG: ctrl-l doesn't repaint the screen when its messed up by resizing
" Temp workaround for <C-l> -- https://github.com/neovim/neovim/issues/3929
map <C-l> :mode
" BUG: Interactive shell commands don't work with the terminal anymore
" Temp workaround for :W -- https://github.com/neovim/neovim/issues/1716
command! W w !sudo -n tee % > /dev/null || echo "Press <leader>w to authenticate and try again"
map <leader>w :new:term sudo true
else
" To use different cursor modes in iTerm2
" Ref: http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
" When you dont have write access, :W will write with sudo
" Without this, you could use ':w !sudo tee %'
command! W w !sudo tee % > /dev/null
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CUSTOM VIM FUNCTIONALITY "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Shortcut for spellcheck
map <leader>z :set spellz=
map <leader>Z :set nospell
" :Q is an accidental error for :q
cnoreabbrev Q q
" Set ts and sw
function! ToggleTS()
if &l:sw == 2
set ts=4 sw=4
else
set ts=2 sw=2
endif
echo "Set to " . &l:sw
let g:airline_section_y='Spaces: ' . &l:sw
:AirlineRefresh
endfunction
map <leader>2 :call ToggleTS()<CR>
" Q is another common accidental error to launch :ex mode - which I don't use
nnoremap Q <nop>
" Easier way to copy and paste from the global clipboard
map <leader>p "+p
map <leader>y "+y
" Y should act like C and D!
map Y y$
" Easier duplication
"map <leader>' <S-Y>
" Easier way to make a blank line but not go into insert mode
map <leader>o o
map <leader>O O
" Easier way to toggle highlighted search
map <leader>h :set hls!<bar>set hls?
" Easily move between windows with Ctrl-hjkl
set splitbelow
set splitright
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Keeps highlighting on till you turn it off with ,/
nmap <silent> ,/ :nohlsearch<CR>
" insert a new line at the end of the file using leader A
map <leader>A Go
" Move cursor to matched string when searching
set incsearch
" Shortcuts for debugging
autocmd FileType javascript map <leader>d odebugger;
autocmd FileType javascript map <leader>D Odebugger;
autocmd BufEnter *.rb,*.js syn match error contained "\<debugger\>"
" Filetype specific
au BufRead,BufNewFile *.sbt set filetype=scala
autocmd BufNewFile,BufRead *.markdown,*.textile setlocal filetype=octopress
autocmd FileType octopress,markdown map <leader>= yyp:s/./=/g
autocmd FileType octopress,markdown map <leader>- yyp:s/./-/g
autocmd FileType octopress,markdown,gitcommit setlocal spell
autocmd FileType octopress,markdown,gitcommit setlocal textwidth=80
autocmd BufRead,BufNewFile *.njk set filetype=html
" Set a nicer foldtext function
set foldtext=MinimalFoldText()
function! MinimalFoldText()
let line = getline(v:foldstart)
let n = v:foldend - v:foldstart + 1
set fillchars=fold:\
return line . " ⏎ " . n
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CUSTOM EXTERNAL FUNCTIONALITY "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Format JSON - filter the file through Python to format it
map =j :%!python -m json.tool
" Remove un-needed whitespace
map <silent> =w :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar>:nohl<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" PLUGIN CONFIGURATION "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" NETRW (builtin plugin)
let g:netrw_banner=0
let g:netrw_list_hide = '\(^\|\s\s\)\zs\.\S\+,\(^\|\s\s\)ntuser\.\S\+'
autocmd FileType netrw set nolist
" NERDTREE PLUGIN - (mnemonic: Files)
nmap <leader>f :NERDTreeToggle
nmap <leader>F :NERDTreeFind
" nerdtree - show dotfiles
let NERDTreeShowHidden=1
let NERDTreeIgnore=['^\..*\.swp$', '\~$']
" ALE Plugin
let g:ale_linters = {
\ 'javascript': ['eslint', 'flow', 'prettier']
\}
" Use eslint to fix JS errors
let g:ale_fixers = {
\ 'javascript': ['prettier']
\}
" " Fix files automatically on save
let g:ale_fix_on_save = 1
" Prettier config globals
let g:ale_javascript_prettier_options = '--no-semi true --arrow-parens always'
" VIM-JSX
let g:jsx_ext_required = 0
" VIM-JAVASCRIPT
let g:javascript_plugin_flow = 1
" VIM-CSS3-SYNTAX
augroup VimCSS3Syntax
autocmd!
autocmd FileType css,javascript.jsx setlocal iskeyword+=-
augroup END
" AIRLINE
let g:airline_left_sep=''
let g:airline_right_sep=''
" STARTIFT
let g:startify_session_persistence = 1
"" fzf
" Use ripgrep instead of default find command to traverse file system while respecting .gitignore
let $FZF_DEFAULT_COMMAND = '
\ rg --column --line-number --files --no-ignore --hidden --follow
\ --glob "!{.git,node_moduels}/*" '
" --column : show column numbers
" --line-number : show line numbers
" --files : search each file that would be searched (but don't search)
" --hidden : search hidden files and directories
" --follow : follow symlinks
" --glob: include or exclude files for searching that match the specified glob
" Map Ctrl P to :Files
nnoremap <silent> <C-P> :Files<CR>
" Prettier
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue Prettier
let g:prettier#config#tab_width = 2
"
"
"COC
source $HOME/.config/nvim/coc.vim
" MARKDOWN PREVIEW
nmap <C-m> <Plug>MarkdownPreview