-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
213 lines (190 loc) · 7.74 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
" Use Vim-Plug plugin manager.
"
" @see: https://github.com/junegunn/vim-plug
" Automatic installation.
"
" @see: https://github.com/junegunn/vim-plug/wiki/tips#automatic-installation
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" Plugins.
call plug#begin()
" Full path fuzzy file, buffer, mru (Most Recently Used), tag, ... finder.
Plug 'ctrlpvim/ctrlp.vim'
" Highlight choices and jump directly to the target.
Plug 'easymotion/vim-easymotion'
" Adhere to .editorconfig.
Plug 'editorconfig/editorconfig-vim'
" Use <Tab> for insert completion (:help ins-completion).
Plug 'ervandew/supertab'
" Text alignment.
Plug 'godlygeek/tabular'
" File system explorer.
Plug 'scrooloose/nerdtree'
" Git actions.
Plug 'tpope/vim-fugitive'
" Autodetect indentation.
Plug 'tpope/vim-sleuth'
" Mappings to easily delete, change and add surroundings in pairs.
Plug 'tpope/vim-surround'
" Git status flags in NERDTree.
Plug 'Xuyuanp/nerdtree-git-plugin'
call plug#end()
colorscheme peachpuff
set autoindent " Copy indent from current line when starting a new line.
set autoread " Automatically read external file changes.
set backspace=indent,eol,start " Improved backspace behavior.
set complete-=i " Use tags instead of include scans.
set display+=lastline " Display the last line.
set expandtab " Spaces over tabs.
set fileformats+=mac " EOL formats to try.
set fixendofline " Add EOL at end of file if missing.
set foldmethod=indent " Fold on indent.
set foldnestmax=3 " Maximum nesting of folds.
set formatoptions-=t " Prevent Vim from automatically reformatting when typing on existing lines.
set hidden " Open a new file without writing changes.
set history=1000 " Reasonable history size.
set hlsearch " Highlight all matches from previous search pattern.
set ignorecase " Ignore case.
set incsearch " Show pattern matches when searching.
set laststatus=2 " Always display a status line.
set linebreak " Break lines at word boundary.
set modeline " Honor document modelines.
set noerrorbells " Disable error messages.
set nofoldenable " Ensure all folds are open.
set noswapfile " Don't create swap files.
set nrformats-=octal " Bases for inc/decrementing character sequences.
set number " Display line numbers.
set ruler " Cursor and file position.
set scrolloff=8 " Lines to pad above and below cursor.
set shiftwidth=2 " Number of spaces to use for in/outdent.
set showbreak=" " " String to put at the start of lines that have been wrapped.
set showcmd " Show (partial) command in the last line of the screen.
set showmode " Show the current mode.
set shortmess+=I " Ensure the intro message is disabled when starting Vim.
set shortmess-=S " Display match count with string search.
set sidescroll=1 " Minimal number of columns to scroll horizontally.
set sidescrolloff=15 " Minimal number of screen columns to pad around the cursor.
set smartcase " Override ignorecase if search pattern contains upper case letters.
set smarttab " Tab behavior matches shiftwidth.
set switchbuf=usetab " Jump to the first open window or tab.
set tabpagemax=50 " Maximum number of tab pages to open.
set tabstop=2 " Visual display of tabs.
set textwidth=0 " Prevent Vim from automatically inserting line breaks in newly entered text.
set title " Display a document title.
set undofile " Name of the undo file.
set viminfo='100,f1 " Save up to 100 marks, enable capital marks.
set visualbell " Use visual bell instead of beeping.
set wildmenu " Enhanced command-line completion.
set wildmode=longest,full " String completion mode.
set winheight=5 " Window height.
set winminheight=5 " Minimum window height.
set winwidth=79 " Minimum window width.
set wrap " Break lines at a word boundary.
set wrapmargin=0 " Prevent Vim from automatically inserting line breaks in newly entered text.
" https://vi.stackexchange.com/a/10125
filetype plugin indent on
" Set leader to spacebar.
let mapleader = "\<Space>"
" Backup and undo directory configuration.
let s:dir = '~/Library/Vim'
let &backupdir = expand(s:dir) . '/backup//'
let &undodir = expand(s:dir) . '/undo//'
if !isdirectory(expand(s:dir))
call system("mkdir -p " . expand(s:dir) . "/{backup,undo}")
end
" Use Q to intelligently close a window in a buffer. Kill the buffer with a
" single window.
function! CloseWindowOrKillBuffer()
let number_of_windows_to_this_buffer = len(filter(range(1, winnr('$')), "winbufnr(v:val) == bufnr('%')"))
if matchstr(expand("%"), 'NERD') == 'NERD'
wincmd c
return
endif
if number_of_windows_to_this_buffer > 1
wincmd c
else
bdelete
endif
endfunction
nnoremap <silent> Q :call CloseWindowOrKillBuffer()<CR>
" Recover from accidental Ctrl-U.
"
" @see: https://vim.fandom.com/wiki/Recover_from_accidental_Ctrl-U
inoremap <c-u> <c-g>u<c-u>
inoremap <c-w> <c-g>u<c-w>
" Move by visible lines with ':set wrap'.
"
" @see: https://vim.fandom.com/wiki/Move_cursor_by_display_lines_when_wrapping
nnoremap j gj
nnoremap k gk
vnoremap j gj
vnoremap k gk
nnoremap <Down> gj
nnoremap <Up> gk
vnoremap <Down> gj
vnoremap <Up> gk
inoremap <Down> <C-o>gj
inoremap <Up> <C-o>gk
" BEGIN CtrlP configuration.
nnoremap <Leader>o :CtrlP<CR>
let g:ctrlp_regexp = 1
" END CtrlP configuration.
" Unhighlight the last search string.
nnoremap <Leader>/ :nohlsearch<CR>
" Ensure match count is always displayed.
nnoremap n nzzhn
nnoremap N Nzzhn
" Remove trailing whitespace on write.
autocmd BufWritePre * :%s/\s\+$//e
" Improved pasting experience for macOS.
"
" @see: https://stackoverflow.com/a/7053522
if has('mac')
let &t_ti = &t_ti . "\e[?2004h"
let &t_te = "\e[?2004l" . &t_te
function XTermPasteBegin(ret)
set pastetoggle=<Esc>[201~
set paste
return a:ret
endfunction
map <expr> <Esc>[200~ XTermPasteBegin("i")
imap <expr> <Esc>[200~ XTermPasteBegin("")
vmap <expr> <Esc>[200~ XTermPasteBegin("c")
cmap <Esc>[200~ <nop>
cmap <Esc>[201~ <nop>
endif
" BEGIN NERDTree configuration.
nmap <Leader>n :NERDTreeToggle<CR>
noremap <Leader>n :NERDTreeToggle<cr>
noremap <Leader>f :NERDTreeFind<cr>
" END NERDTree configuration.
" Allow adding cronjobs in macOS with Vim.
"
" @see: https://superuser.com/a/750528
if $VIM_CRONTAB == "true"
set nobackup
set nowritebackup
endif
" BEGIN EasyMotion configuration.
" Disable default mappings
let g:EasyMotion_do_mapping = 0
" Jump to anywhere you want with minimal keystrokes, with just one key binding.
" `s{char}{label}`
" nmap s <Plug>(easymotion-overwin-f)
" or
" `s{char}{char}{label}`
" Need one more keystroke, but on average, it may be more comfortable.
nmap s <Plug>(easymotion-overwin-f2)
" Turn on case insensitive feature
let g:EasyMotion_smartcase = 1
" JK motions: Line motions
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
" END EasyMotion configuration.
" Load work assets.
if !empty(glob("$HOME/.work/vim/*.vim"))
source $HOME/.work/vim/*.vim
endif