-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
333 lines (279 loc) · 9.36 KB
/
Copy pathvimrc
File metadata and controls
333 lines (279 loc) · 9.36 KB
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugin manager
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let s:prefix = has('nvim') ? 'nvim' : 'vim'
let g:vim_dir = printf('$HOME/.%s', s:prefix)
let vim_plug_file=expand(g:vim_dir . "/autoload/plug.vim")
if !filereadable(vim_plug_file)
echo "Installing vim-plug"
echo ""
silent exec "!mkdir -p " . g:vim_dir . "/autoload"
silent exec "!curl -fLo " . vim_plug_file . " https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
endif
call plug#begin()
Plug 'bronson/vim-trailing-whitespace', { 'on': 'FixWhitespace' }
Plug 'christoomey/vim-tmux-navigator'
Plug 'junegunn/vim-plug'
Plug 'vimwiki/vimwiki'
Plug 'mbbill/undotree', { 'on': 'UndotreeToggle' }
Plug 'romainl/Apprentice'
call plug#end()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
filetype plugin indent on
" show numberlines
set nu
" don't highlight current line as it is really slow
set nocursorline
set nocursorcolumn
set scrolljump=5
" hide buffers instead of closing them
set hidden
" Load matchit.vim, but only if the user hasn't installed a newer version.
if !exists('g:loaded_matchit') && findfile('plugin/matchit.vim', &rtp) ==# ''
runtime! macros/matchit.vim
endif
" syntax highlighting
syntax enable
" colorscheme
set background=dark
colorscheme apprentice
set t_ut=
" When opening a new line and no filetype-specific indenting is enabled, keep
" the same indent as the line you're currently on. Useful for READMEs, etc.
set autoindent
" smart tab handling for indenting
set smarttab
" copy the previous indentation on autoindenting
set copyindent
if v:version >= 704 && has('patch338')
set breakindent
endif
" remember copy registers after quitting in the .viminfo file -- 20 jump links, regs up to 500 lines'
set viminfo='20,\"500
set scrolloff=5
" Show partial commands in the last line of the screen
set showcmd
" Start highlighting search as soon as you begin typing
" Use case insensitive search, except when using capital letters
set hlsearch
set incsearch
set ignorecase
set smartcase
" Display the cursor position on the last line of the screen or in the status
" line of a window
set ruler
" Always display the status line, even if only one window is displayed
set laststatus=2
" Word wrap without breaking words in the middle
set wrap
set formatoptions=l
" Syntax highlight shell scripts as per POSIX,
" not the original Bourne shell which very few use.
let g:is_posix = 1
" Set the command window height to 2 lines, to avoid many cases of having to
" press <Enter> to continue
set cmdheight=2
" Better command-line completion
set wildmenu
" open new splits to the right and below
set splitright
set splitbelow
"Don't display warning about found swap file
set shortmess+=A
" Look for tags in directory above
set tags=./tags;/
" enable mouse in all modes
set mouse=a
"Default indenting
set expandtab
set shiftwidth=4
set softtabstop=4
set tabstop=4
" No swap files, thanks
set noswapfile
" Create backup/undo dirs
let backupdir = expand('~/.vim/backup')
if !isdirectory(backupdir)
call mkdir(backupdir)
endif
let undodir = expand('~/.vim/undo')
if !isdirectory(undodir)
call mkdir(undodir)
endif
" Force backups to be copied from original, not renamed
set backupcopy=yes
"""""""""""""""""""
" Persistent Undo "
"""""""""""""""""""
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
" use fzf as fuzzy search
set rtp+=~/.fzf
" String to put at the start of lines that have been wrapped "
set linebreak
let &showbreak='↪ '
" Don't update the display while executing macros
set lazyredraw
set showmatch " show matching brackets
set matchtime=2 " reduce blinking time
set list listchars=tab:»•,trail:•,extends:>,precedes:<
" Allow backspacing over lines and stuff
set backspace=indent,eol,start
" Automatically reload file in vim if it was changed outside of vim
set autoread
" Yank to clipboard
set clipboard+=unnamedplus
" Better handling of large files (no idea why this works though)
set synmaxcol=180
if has('gui_running')
set guifont=Inconsolata\ 11
set guioptions-=m " remove menu bar
set guioptions-=T " remove toolbar
set guioptions-=r " remove right-hand scroll bar
set guioptions-=L " remove left-hand scroll bar
set guicursor=a:blinkon0
endif
" ignore files
set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz,*.py[co],*.pyc,*.jpg,*.mp3,*.wav,*.pdf
augroup resize
autocmd!
" let terminal resize scale the internal windows
autocmd VimResized * :wincmd =
augroup END
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Keybinds
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" set leader key
let mapleader=" "
" opening new splits
nnoremap <leader>v :split<CR>
nnoremap <leader>h :vsplit<CR>
" navigating splits
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" Make Y behave similar to D and C
nnoremap Y y$
" Keep search matches in the middle of the window.
nnoremap n nzzzv
nnoremap N Nzzzv
" Wrapped lines goes down/up to next row, rather than next line in file.
nnoremap <expr> k (v:count == 0 ? 'gk' : 'k')
nnoremap <expr> j (v:count == 0 ? 'gj' : 'j')
" Use jk to exit insert mode
imap jk <ESC>
" use arrows to resize window
noremap <up> <C-W>+
noremap <down> <C-W>-
noremap <left> 3<C-W><
noremap <right> 3<C-W>>
" Easier pasting from clipboard
nnoremap <leader>p "+p
" (c)opy (e)verything to clipboard
nnoremap <leader>ce ggVG"+y
" save read only file
cnoremap w!! w !sudo tee % >/dev/null
" I've had enough
:command W w
:command Q q
iabbrev date- <c-r>=strftime("%Y-%m-%d")<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Custom functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Use TAB to complete when typing words, else inserts TABs as usual.
"Uses dictionary and source files to find matching words to complete.
"See help completion for source,
"Note: usual completion is on <C-n> but more trouble to press all the time.
"Never type the same word twice and maybe learn a new spellings!
"Use the Linux dictionary when spelling is in doubt.
"Window users can copy the file to their machine.
function! Tab_Or_Complete()
if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
return "\<C-N>"
else
return "\<Tab>"
endif
endfunction
:inoremap <Tab> <C-R>=Tab_Or_Complete()<CR>
:set dictionary="/usr/dict/words"
" Don't move on * From sjl dotfiles
nnoremap <silent> * :let stay_star_view = winsaveview()<cr>*:call winrestview(stay_star_view)<cr>
" sudo apt-get install wmctrl for this to work
" function Maximize_Window()
" silent !wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz
" endfunction
" au GUIEnter * call Maximize_Window()
" jump to last known cursos position when reopening a buffer
function! s:JumpToLastKnownCursorPosition()
if line("'\"") <= 1 | return | endif
if line("'\"") > line("$") | return | endif
" Ignore git commit messages and git rebase scripts
if expand("%") =~# '\(^\|/\)\.git/' | return | endif
execute "normal! g`\"" |
endfunction
augroup bufread
autocmd!
autocmd BufReadPost * call s:JumpToLastKnownCursorPosition()
augroup END
" disable unnecessary default plugins
let g:loaded_gzip = 1
let g:loaded_tar = 1
let g:loaded_tarPlugin = 1
let g:loaded_zip = 1
let g:loaded_zipPlugin = 1
let g:loaded_rrhelper = 1
let g:loaded_2html_plugin = 1
let g:loaded_vimball = 1
let g:loaded_vimballPlugin = 1
let g:loaded_getscript = 1
let g:loaded_getscriptPlugin = 1
let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
let g:loaded_netrwSettings = 1
let g:loaded_netrwFileHandlers = 1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugins
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" vimwiki
let vimwikidir = expand('~/Dropbox/vimwiki')
if !isdirectory(vimwikidir)
call mkdir(vimwikidir)
endif
let g:vimwiki_list = [{'path': '~/Dropbox/vimwiki'}]
" augroup statusline
" autocmd!
" autocmd BufWinEnter,WinEnter,VimEnter * let w:getcwd = getcwd()
" augroup END
" function! StatuslineTag()
" if exists('b:git_dir')
" let dir = fnamemodify(b:git_dir[:-6], ':t')
" return dir." branch:".fugitive#head(7)
" else
" return fnamemodify(getwinvar(0, 'getcwd', getcwd()), ':t')
" endif
" endfunction
" let &statusline = " %{StatuslineTag()} "
" let &statusline .= "\ue0b1 %<%f "
" let &statusline .= "%{&readonly ? \"\ue0a2 \" : &modified ? '+ ' : ''}"
" let &statusline .= "%=\u2571 %{&filetype == '' ? 'unknown' : &filetype} "
" let &statusline .= "\u2571 %l:%2c \u2571 %p%% "
" %< Where to truncate
" %n buffer number
" %F Full path
" %m Modified flag: [+], [-]
" %r Readonly flag: [RO]
" %y Type: [vim]
" fugitive#statusline()
" %= Separator
" %-14.(...)
" %l Line
" %c Column
" %V Virtual column
" %P Percentage
" %#HighlightGroup#
set statusline=%<[%n]\ %F\ %m%r%y\ %{exists('g:loaded_fugitive')?fugitive#head(7):''}\ %=%-14.(%l,%c%V%)\ %P