-
Notifications
You must be signed in to change notification settings - Fork 110
/
vimrc
220 lines (172 loc) · 8.2 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
"" Based on tips from VIM Revisited (after dropping Janus)
"" http://mislav.uniqpath.com/2011/12/vim-revisited/
" Changelog
" 2019-04-02 Swapped Vundle for vim-plug. Needed post-install hooks
" 2015-09-24 Swapped Pathogen for Vundle. Simplicity!
" Tipped from: http://lepture.com/en/2012/vundle-vs-pathogen
" Resets all auto commands before adding them - important when sourcing twice
autocmd!
set nocompatible " be iMproved
set modeline
set modelines=5 " The number of lines to search for a modeline, must be non-0
filetype off " required!
" DISABLED due to CoC: Enable completion where available.
" " This setting must be set BEFORE ALE is loaded.
" let g:ale_completion_enabled = 1
source ~/.vim/plugins-config
filetype plugin indent on " load file type plugins + indentation
" To ignore plugin indent changes, instead use:
"filetype plugin on
syntax enable
set encoding=utf-8
"" GUI
" This is a default scheme that works well
" Override in ~/vimrc.local
colorscheme darkblue
set guifont=Monaco:h14
"" Clipboard - all yanking, deleting, etc will use the system clipboard
" Is much smoother default setting than having to do stuff like "+yy
" set clipboard=unnamedplus
"" check out http://superuser.com/questions/693528/vim-is-there-a-downside-to-using-space-as-your-leader-key
:let mapleader=","
"" Don't rely on Cmd working in vim. Learn to use <leader>c<space>
"" http://stackoverflow.com/questions/9450905/how-to-bind-vim-through-tmux-to-cmd-key/9451636#9451636
"" map <D-/> <plug>NERDCommenterToggle
set showcmd "" show leader commands
set ruler
"" Whitespace
set nowrap " don't wrap lines
set tabstop=4 shiftwidth=4 " a tab is four spaces
set expandtab " use spaces, not tabs (optional)
set backspace=indent,eol,start " backspace through everything in insert mode
"" Searching
set hlsearch " highlight matches
set incsearch " incremental searching
set ignorecase " searches are case insensitive...
set smartcase " ... unless they contain at least one capital letter
"" NVIM does not support popt / printoptions
if !has('nvim')
set printoptions=portrait:n
endif
"" Pasting text - toggle between paste and insert mode using F2
"" http://nvie.com/posts/how-i-boosted-my-vim/
set pastetoggle=<F2>
" Remember last position
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
"" File type settings
"" Set filetype text if unset
autocmd BufEnter * if &filetype == "" | setlocal ft=text | endif
" text files
autocmd Filetype text set wrap | set linebreak
autocmd Filetype markdown set wrap | set linebreak
" associate *.vss (VectorScript) with Pascal filetype
au BufRead,BufNewFile *.vss set filetype=pascal
" associate Processing files with Java
au BufRead,BufNewFile *.pde set filetype=java
" associate *.ts with TypeScript
au BufRead,BufNewFile *.ts set filetype=typescript
au BufRead,BufNewFile *.tsx set filetype=typescript
" associate *.kit with Html
au BufRead,BufNewFile *.kit set filetype=html
" Use nginx syntax highlighting
au BufRead,BufNewFile *.nginx set ft=nginx
au BufRead,BufNewFile */etc/nginx/* set ft=nginx
au BufRead,BufNewFile */usr/local/nginx/conf/* set ft=nginx
au BufRead,BufNewFile nginx.conf set ft=nginx
" Auto-reload vimrc on changes
autocmd! bufwritepost .vimrc source % " in $HOME
autocmd! bufwritepost vimrc source % " the linked file in dotfiles
autocmd! bufwritepost plugins-config source %
autocmd! bufwritepost coc-config source %
autocmd! bufwritepost ale-config source %
autocmd! bufwritepost coc-config source %
autocmd! bufwritepost coc-settings.json source %
autocmd! bufwritepost ctrlp-config source %
autocmd! bufwritepost plugins-config source %
autocmd! bufwritepost ycm-config source %
" Make vim work as a crontab editor: http://vim.wikia.com/wiki/Editing_crontab
au BufEnter /private/tmp/crontab.* setl backupcopy=yes
" Make NERDTree open automatically if no files were specified
" autocmd StdinReadPre * let s:std_in=1
" autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
" Silence NerdTree errors - might have been introduced by the above
" https://github.com/scrooloose/nerdtree/issues/162#issuecomment-107643011
" nmap <silent> <Leader>t :call g:WorkaroundNERDTreeToggle()<CR>
" function! g:WorkaroundNERDTreeToggle()
"try | NERDTreeToggle | catch | silent! NERDTree | endtry
" endfunction
" Open/Close NerdTree with Ctrl-N, but only in Normal mode
nmap <C-n> :NERDTreeToggle<CR>
" Make the local current directory reflect the currently open buffer
" Disabled on 2019-04-03: Breaks fugitive.vim :(
" autocmd BufEnter * lcd %:p:h
" Alternative from https://vim.fandom.com/wiki/Set_working_directory_to_the_current_file#Automatically_change_the_current_directory
" Doesn't work that well with NERDTree, since that will set the CWD relative
" to that buffer, regardless of the "parent" window
" set autochdir
" CDC = Change to Directory of Current file (for the local window)
" This works pretty well with NERDTree's CD (change tree root to CWD)
command! CDC lcd %:p:h
" Allow saving of files as sudo when I forgot to start vim using sudo.
" https://stackoverflow.com/a/7078429/200987
cmap w!! w !sudo tee > /dev/null %
" Tips mostly from nvie.com/
set showmatch " When in insert mode, this will momentarily flash the cursor back to the opening bracket
set matchtime=1 " just jump for 100 ms
set shiftwidth=4 " number of spaces to use for autoindenting
set shiftround " use multiple of shiftwidth when indenting with '<' and '>'
set ignorecase " ignore case when searching
set smartcase " ignore case if search pattern is all lowercase, case-sensitive otherwise
set smarttab " insert tabs on the start of a line according to shiftwidth, not tabstop
set hlsearch " highlight search terms
set incsearch " show search matches as you type
set history=1000 " remember more commands and search history
set undolevels=1000 " use many muchos levels of undo
set wildignore=*.swp,*.bak,*.pyc,*.class
set title " change the terminal's title
set visualbell " don't beep
set noerrorbells " don't beep
" Clear highlighted search text by just typing ",/"
nmap <silent> <leader>/ :nohlsearch<CR>
" Use sudo after you opened a file, in case you forgot
cmap w!! w !sudo tee % >/dev/null
" Show 'hidden' characters, like tab and newline: https://vi.stackexchange.com/a/430/1087
set listchars=eol:⏎,tab:␉·,trail:␠,nbsp:⎵
" Lucas F. Costa: http://lucasfcosta.com/2017/01/23/Quick-vIM-Tips-That-Will-Save-Your-Life.html
set relativenumber " Show relative line numbers
set number " Show current line number
" https://twitter.com/mantoni/status/880079687946522625
set suffixesadd+=.js " Makes gf work for relative files as well
" Disable mouse integration by default to make copy-paste easy. Toggle with F12
set mouse=
" These needs to be before later configuration for objects to be defined
source ~/.vim/ctrlp-config
source ~/.vim/coc-config
source ~/.vim/ale-config
" Elm settings - see https://github.com/elmcast/elm-vim
let g:elm_format_autosave = 1 "reformat on autosave
"let g:ycm_semantic_triggers.elm = ['.']
" js settings
let g:javascript_plugin_jsdoc = 1
" enable auto sort import on write
" see https://github.com/ruanyl/vim-sort-imports#available-cmd
let g:import_sort_auto = 1
" temporary fix for JSX: https://github.com/pangloss/vim-javascript/issues/955#issuecomment-356350901
let g:jsx_ext_required = 0
" auto-format JSX
" Disable using :RepoVimrcEdit and 'autocmd!'
" Should perhaps configure ALE to handle this in the ftplug/javascript file?
autocmd BufWritePre *.jsx Neoformat
" Understand JSONC (json with comments)
autocmd FileType json syntax match Comment +\/\/.\+$+
" Set up neomake as well: It is intended to replace the built-in :make command and provides functionality
" similar to plugins like syntastic and dispatch.vim. It is primarily used to run code
" linters and compilers from within Vim, but can be used to run any program.
" Set up fzf instead of Ctrl-P
" fzf and fzf.vim
if filereadable(expand("~/.vimrc.local"))
source ~/.vimrc.local
endif
" vi: ft=vim