-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
158 lines (121 loc) · 3.71 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
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" "
" Many things here stolen from http://amix.dk/vim/vimrc.html "
" "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if filereadable($HOME . "/.vim/autoload/pathogen.vim")
call pathogen#infect()
endif
" UTF-8 is the future
set encoding=utf-8
setglobal fileencoding=utf-8
set nobomb
set fileencodings=ucs-bom,utf-8,iso-8859-1
" Default to unix EOLs, but handle others gracefully
set ffs=unix,dos,mac
" Don't try to redraw in the middle of a macro
set lazyredraw
" 256 colors and syntax highlighting
set t_Co=256
colorscheme space-vim-dark
syntax on
" Turn on line numbering and position indicators...
set number numberwidth=6
set ruler
" And enable mouse support to prevent copying line numbers, etc
set mouse=a
" Display last line even if too long; use <xx>
set display=lastline,uhex
" Display invisible characters
set listchars=tab:↹·,extends:⇉,precedes:⇇,nbsp:␠,trail:␠,nbsp:␣
" Use 'tabs are actually 4 spaces' and intelligent indenting
set tabstop=8
set softtabstop=2
set shiftwidth=2
set shiftround
set expandtab
set smarttab
set autoindent
set smartindent
" But also make smartindent not terrible for Python comments
inoremap # X#
" Make backspace work nicely
set backspace=indent,eol,start
" Incremental search with intelligent case-sensitivity
set incsearch
set ignorecase smartcase
" When moving the screen, keep some context
set scrolloff=2
" Tab completion when in insert mode and not indenting
function! CleverTab()
if strpart( getline('.'), col('.')-2, 1 ) =~ '^\s*$'
return "\<Tab>"
else
return "\<C-N>"
endfunction
inoremap <Tab> <C-R>=CleverTab()<CR>
" Modeline support
set modeline
set modelines=3
" File type detection
filetype on
filetype plugin on
" Ignore compiled files when completing paths
set wildignore=*.o,*~,*.pyc,*.pyo,*.class,*.hi
" Persistent undo
set undodir=~/.vim/undo
set undofile
" Readable wrapping
set wrap linebreak
" KEYBINDINGS
""""""""""""""""""""""""""""""""""""""""""""""""""
" Unbind the arrow keys (old habits die hard)
noremap <left> <C-w><left>
noremap <up> <C-w><up>
noremap <down> <C-w><down>
noremap <right> <C-w><right>
" Bind jk/kj in insert to <esc>
inoremap jk <esc>
inoremap kj <esc>
" Use the comma key for extra key combos
let mapleader = ","
let g:mapleader = ","
" ,m = remove carriage returns
noremap <leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
" ,ss = toggle spell check
noremap <leader>ss :setlocal spell!<cr>
" ,80 = set window width to 80 (plus room for gutter)
noremap <leader>80 :vertical resize 86<cr>
" ABBREVIATIONS (Mostly typo fixes)
""""""""""""""""""""""""""""""""""""""""""""""""""
iabbrev waht what
iabbrev adn and
iabbrev tehn then
iabbrev taht that
iabbrev tahn than
" Also expand %% in command mode to same dir as current file
cabbr <expr> %% expand('%:.:h')
" TRIGGERED ACTIONS
""""""""""""""""""""""""""""""""""""""""""""""""""
" These are grouped to prevent duplication when sourcing
augroup vimrc
autocmd!
" Remember info about open buffers on close...
set viminfo^=%
" and return to last edit position when opening files
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Delete trailing whitespace on save in .py files
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
autocmd BufWrite *.py :call DeleteTrailingWS()
" Force .md to be markdown
autocmd BufNewFile,BufReadPost *.md set filetype=markdown
" Automatically reload .vimrc when it is saved
autocmd BufWritePost $MYVIMRC source $MYVIMRC
augroup END