-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvimrc
277 lines (218 loc) · 7.34 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
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
" Plugins {{{
set nocompatible " Needed for pathogen to work
runtime pack/plugin-bundle/start/vim-pathogen/autoload/pathogen.vim
call pathogen#infect()
call pathogen#helptags()
let g:ale_linters = {'python': ['jedils', 'pylint']}
let g:ale_floating_preview = 1
let g:ale_floating_window_border = ['│', '─', '╭', '╮', '╯', '╰']
nmap <leader>gd :ALEGoToDefinition<CR>
nmap <leader>gr :ALEFindReferences<CR>
autocmd Filetype python nmap K :ALEHover<CR>
" autoclose preview window (the place the help text is shown when
" autocompleting python methods)
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|'
let g:airline_theme='wombat'
let g:showmarks_enable=0
let g:ctrlp_user_command = {
\ 'types': {
\ 1: ['.git', 'cd %s && git ls-files -co --exclude-standard'],
\ },
\ 'fallback': 'find %s -type f'
\ }
" This searches Files, Buffers and MRU files at the same time. For whatever
" reason, regular CtrlP mode will miss a lot of files in the root directory
" (e.g. Makefiles). Searching MRU files seems to work a lot better than regular
" file searching.
let g:ctrlp_cmd = 'CtrlPMixed'
let g:tex_flavor='latex'
let g:netrw_altfile = 1
" this ensures the netrw buffer gets closed when you open a file from it
" See: https://github.com/tpope/vim-vinegar/issues/13
let g:netrw_fastbrowse = 0
" }}}
" Spaces & Tabs {{{
" Use spaces instead of tabs
set expandtab
set shiftwidth=4 " Used when indenting with << or >>
set tabstop=4 " How many columns a tab counts for
set softtabstop=4 " How many columns vim uses when you hit tab in insert mode.
" }}}
" UI {{{
" Send more characters to the screen for redrawing, instead of using
" insert/delete line commands
set ttyfast
" If there are more than 3 lines to scroll, redraw the screen. Good for when
" redrawing is fast, but scrolling is slow in a terminal.
set ttyscroll=3
" Don't redraw the screen when executing macros, registers and other commands
" that have not been typed.
set lazyredraw
" Show < and > when the line continues offscreen.
" NOTE: precedes only seems to work when `list` is set, but I'm not sure if I
" want to do that.
set listchars=extends:>,precedes:<
set cursorline
" }}}
" Layout {{{
set ruler " Show the current position
set number
set colorcolumn=80
set wildmenu
" Set 3 lines to the cursor - when moving vertically using j/k
set scrolloff=3
" Leave 5 column on each side of the cursor when moving horizontally
set sidescrolloff=5
" Show as much of a really long line as possible instead of @
set display+=lastline
" Always show the status line
set laststatus=2
" Use 79 columns as the limit for the width of text
" You can use `gq' to realign text.
set textwidth=79
" Auto-wrap comments and allow formatting of comments with "gq"
set formatoptions=cqlj
set showcmd
" }}}
" Colours {{{
colorscheme wombat
" this is because there seems to be problems in tmux with the background not
" being completely painted.
" See https://vi.stackexchange.com/questions/238/tmux-is-changing-part-of-the-background-in-vim
if &term =~ '256color'
" disable Background Color Erase (BCE)
set t_ut=
endif
" }}}
" Maps and Movement {{{
" Use w!! to write as root (when you forgot to sudo vim filename)
cmap w!! w !sudo tee % >/dev/null<CR>:e!<CR><CR>
" Shortcut to clear search highlights
nmap <silent> <BS> :nohlsearch<CR>
" Let j/k behave like other editors (if a line is split, don't skip
" to the next line)
" Only have it work in normal mode!
nmap j gj
nmap k gk
" set gundo to use F5
nnoremap <leader>u :UndotreeToggle<CR>
" edit all buffers using current files (reload)
map <Leader>ge :windo e!<CR>
" switch buffers with Tab and S-Tab
nnoremap <Tab> :bnext<CR>
nnoremap <S-Tab> :bprevious<CR>
nnoremap <Leader>q :q<CR>
nnoremap <leader>w :w<CR>
nnoremap <silent> <leader>o :call append(line('.'), '')<CR>
nnoremap <silent> <leader>O :call append(line('.') - 1, '')<CR>
" Use SS in visual mode to add spaces around selection
vnoremap <silent> SS :<C-U>call AddSpacesAround()<CR>
function! AddSpacesAround() range
let m = visualmode()
if m ==# 'v' || m ==# "\<C-V>"
execute "normal gvs\<space>\<space>\<esc>P"
elseif m ==# 'V'
call append(line("'<")-1, '')
call append(line("'>"), '')
endif
endfunction
" use \s for spellcheck
nnoremap \s a<C-X><C-S>
" Use mouse for scrolling
set mouse=a
nmap <LeftMouse> <nop>
imap <LeftMouse> <nop>
vmap <LeftMouse> <nop>
" Center the search result
map N Nzz
map n nzz
" Scroll horizontally by 1 column at a time (default is 0 which means to center
" the cursor when moving past the edge of the screen)
set sidescroll=1
" Use ctrl-{hjkl} to switch panes
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>
" Use up/down/left/right in Visual moe to move text around
vmap <unique> <up> <Plug>SchleppUp
vmap <unique> <down> <Plug>SchleppDown
vmap <unique> <left> <Plug>SchleppLeft
vmap <unique> <right> <Plug>SchleppRight
" `gp' will select pasted text
nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'
" Keep selected text when changing indentation
vnoremap < <gv
vnoremap > >gv
" }}}
" Search {{{
set incsearch
set ignorecase
set smartcase
set hlsearch
" }}}
" Syntax & Indent {{{
syntax enable
set autoindent
filetype plugin indent on
" Don't highlight syntax past this column
set synmaxcol=196
set backspace=indent,eol,start
function Reindent2to4() range
setlocal tabstop=2 softtabstop=2 noexpandtab
execute (a:firstline + 1) . "," . a:lastline . 'retab!'
setlocal tabstop=4 softtabstop=4 expandtab
execute (a:firstline + 1) . "," . a:lastline . 'retab'
endfunction
command -range=% Reident2to4 <line1>,<line2>call Reindent2to4()
" }}}
" Behaviour {{{
" Set how many lines of history VIM has to remember
set history=500
" Don't add two spaces after . ? and !
set nojoinspaces
" Ignore compiled files
set wildignore=*.o,*~,*.pyc,*.class
" macOS has('unix') but Linux doesn't has('macunix') so this is the simplest
" way of handling the check
if !has('macunix')
" Use the GNOME system clipboard when yanking and pasting
" NOTE: unnamed is X11, unnamedplus is GNOME
set clipboard^=unnamedplus
endif
" allows hiding modified buffers (useful for using Tab to switch buffers)
set hidden
set nopaste
set confirm
set modelines=1
" Use Unix as the standard file type
set ffs=unix,dos,mac
" Save swap file every 10 characters types
set updatecount=10
" Don't auto-insert completion options, and show a menu even if there's only
" one item
set completeopt=menuone,noinsert
" }}}
" Misc {{{
" shortcut to cd to the current file's dir
" Might be nicer to make a cmap, though
" cmap cd %:h<CR>
command Cdh silent cd %:h
" HTML indent levels because it seems that Vim will load ftplugin/html.vim
" even when ft=php
autocmd FileType html setlocal shiftwidth=2 softtabstop=2
autocmd FileType htmldjango setlocal shiftwidth=2 softtabstop=2
" Don't fold the top level; only fold stuff below (e.g. don't fold classes, but
" fold methods within classes)
set foldlevel=1
set pastetoggle=<leader>p
function RandomLine()
:py3 import vim, random;
\ vim.current.window.cursor = (random.randint(1, len(vim.current.buffer)+1), 0)
endfunction
"}}}
" vim:foldmethod=marker:foldlevel=0