-
Notifications
You must be signed in to change notification settings - Fork 1
/
dot.vimrc
213 lines (171 loc) · 7.61 KB
/
dot.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
"##
"## dotfiles -- Essential Unix Dot-Files
"## Copyright (c) 1995-2020 Dr. Ralf S. Engelschall <[email protected]>
"## Distributed under MIT <https://opensource.org/licenses/MIT> license.
"##
"## ~/.vimrc: vim(1) configuration
"##
" we require Vim and do not have to be Vi compatible
version 8.0
set nocompatible
" ==== TERMINAL HANDLING ===================================================
" avoid "Thanks for Flying Vim" titles in terminals
set notitle
" ==== COMMAND-LINE & STATUS-LINE ==========================================
" tell command-line more Bash-style editing
cnoremap <C-A> <Home>
" display a status line plus a single-line command-line and always
" tell me where I'm inside the file. Also enable TAB completion (wildmenu)
set laststatus=2
set cmdheight=1
set wildmenu
set ruler
set statusline=%<%f\ %h%m%r%=%{StatusLineCounts()}\ \ %-14.(%l,%c%V%)\ %P
" determine the word and character count of the buffer or current selection
function! StatusLineCounts()
" fetch output of g<CTRL-g>
let position = getpos(".")
let s:old_status = v:statusmsg
exe ":silent normal g\<c-g>"
let stat = v:statusmsg
let v:statusmsg = s:old_status
call setpos('.', position)
" possible outputs (for regular and selected situations):
" Col X of X; Line X of X; Word X of X; Byte X of X
" Selected X of X Lines; X of X Words; X of X Bytes
let s:word_count = 0
let s:char_count = 0
if stat =~# '^Col \d\+ of \d\+; Line \d\+ of \d\+; Word \d\+ of \d\+; Byte \d\+ of \d\+$'
let s:word_count = str2nr(split(stat)[11])
let s:char_count = str2nr(split(stat)[15])
elseif stat =~# '^Selected \d\+ of \d\+ Lines; \d\+ of \d\+ Words; \d\+ of \d\+ Bytes$'
let s:word_count = str2nr(split(stat)[5])
let s:char_count = str2nr(split(stat)[9])
end
return (s:word_count . "w," . s:char_count . "c")
endfunction
" show command and modes
set showcmd
set showmode
" don't beep for every silly command and write shorter messages.
set noerrorbells
set terse
" ==== SUB-WINDOW AND TAB HANDLING ========================================
" Always expand windows to the maximum height, but expand only to the
" minimum width of 100 characters per line. Also, create new windows
" below current one.
set winheight=9999
set winwidth=100
set splitbelow
" configure additional window key-handling
map <C-w>- :new<CR>
map <C-w>\| :vnew<CR>
map <C-w>c :new<CR>
map <C-w>x :close<CR>
" configure "tabs" coloring
highlight TabLine term=reverse cterm=reverse ctermfg=none ctermbg=none
highlight TabLineFill term=reverse cterm=reverse ctermfg=none ctermbg=none
highlight TabLineSel term=bold cterm=bold ctermfg=White ctermbg=Red
" configure "tabs" key-handling
" Notice 1: CTRL-E similar to CTRL-W for sub-windows
" Notice 2: CTRL-E is directly beside CTRL-W on keyboard
" Notice 2: CTRL-T is unconvenient for pressing with just the fingers on left hand
map <C-e>c :tabnew<CR>
map <C-e>n :tabnew<CR>
map <C-e>o :tabonly<CR>
map <C-e>x :tabclose<CR>
map <C-e><LEFT> :tabprevious<CR>
map <C-e><RIGHT> :tabnext<CR>
map <S-TAB> :tabnext<CR>
" ==== SHELL SUPPORT ======================================================
" always use my login shell (GNU Bash) for sub-shells
set shell=$SHELL
" ==== FILE HANDLING =======================================================
" read/write a .viminfo file, but don't store more than 50 lines of registers
set viminfo='20,\"50
" no automatic writing of files,
" i.e. I KNOW WHAT I DO! Well, at least most of the time ;-)
set noautowrite
" create ".bak" files only while saving. If current dir is not
" allowed to create the file, save it under the backup dir instead
set nobackup
set writebackup
" write swap files "*.swp" to this dir if not allowed at the current one
set directory=$HOME/tmp,/tmp
" ==== BUFFER EDITING ======================================================
" check first 6 lines for Vi set commands (e.g. 'vi:set tabstop=4 shiftwidth=4').
set modeline
set modelines=6
" always insert TABs as SPACEs (only exception are Makefile files)
" but preserve already existing tabs in order to not destroy existing content
set expandtab
autocmd BufRead Makefile,Makefile.*,GNUMakefile set noexpandtab
" by default do not enable line-folding
set nofoldenable
" allow us to backspace back over lines in insert mode and also
" to go back over the starting point.
set backspace=2
" allow virtual editing (moving cursor where no content is) in Visual block mode
set virtualedit=block
" do not wrap lines (neither implicitly on display nor explicitly
" during editing), except for real text files. Also, shift a minimum
" of 4 chars left/right if we go over the right/left border.
set textwidth=9999
autocmd BufRead *.txt set textwidth=78
set nowrap
set shiftwidth=4
" always indent new lines the same as the last one.
" also, use a C-programmer-style smart tab editing.
set autoindent
set smartindent
set tabstop=4
" do incremental search with smart case sensitivity
set incsearch
set smartcase
" make "Y" analogous to "C" and "D" for better orthogonality
map Y y$
" backward compatibility to some smarter Vim 4.x keystrokes
noremap Q gq
noremap gQ Q
" CTLR-] is nearly impossible on german keyboards
map gt <C-]>
map gb <C-T>
" Vim and other tools inside an xterm think Delete key is <backspace>
" and Backspace key is <delete> but we cannot just swap them. In
" Vim this swapping doesn't work and via xmodmap other X11 applications
" would be affected, too. So we the following: We map Delete to CTRL-D
" for the XTerms via xrdb and then remap the keys here in Vim.
imap lxi
" ==== SYNTAX HIGHLIGHTING ================================================
" enable syntax highlighting
syntax on
" reconfigure syntax highlighting to be very conservative in coloring
highlight Statement ctermbg=None ctermfg=DarkBlue cterm=Bold
highlight Keyword ctermbg=None ctermfg=DarkBlue cterm=Bold
highlight Type ctermbg=None ctermfg=DarkBlue cterm=Bold
highlight Constant ctermbg=None ctermfg=DarkRed cterm=None
highlight Identifier ctermbg=None ctermfg=None cterm=None
highlight Comment ctermbg=None ctermfg=DarkGrey cterm=None
highlight PreProc ctermbg=None ctermfg=DarkRed cterm=None
highlight Special ctermbg=None ctermfg=DarkRed cterm=None
highlight Ignore ctermbg=None ctermfg=White cterm=Bold
highlight Underlined ctermbg=None ctermfg=None cterm=Underline
highlight Error ctermbg=DarkRed ctermfg=White cterm=Bold
highlight Todo ctermbg=DarkRed ctermfg=White cterm=Bold
highlight Constant ctermbg=None ctermfg=DarkRed cterm=None
highlight Title ctermbg=None ctermfg=DarkBlue cterm=None
highlight MatchParen ctermbg=None ctermfg=DarkRed cterm=None
highlight Pmenu ctermbg=White ctermfg=None cterm=None
highlight PmenuSel ctermbg=Black ctermfg=White cterm=None
highlight PmenuSbar ctermbg=Black ctermfg=White cterm=None
highlight DiffAdd ctermbg=DarkBlue ctermfg=White cterm=None
highlight DiffDelete ctermbg=DarkRed ctermfg=White cterm=None
highlight DiffChange ctermbg=Yellow ctermfg=Black cterm=None
highlight DiffText ctermbg=Yellow ctermfg=DarkRed cterm=Bold
highlight htmlItalic ctermbg=None ctermfg=DarkRed cterm=None
highlight htmlBold ctermbg=None ctermfg=DarkRed cterm=Bold
" ==== LOCAL CONFIGURATION ================================================
" include optional local configuration
if filereadable(expand("~/.dotfiles/vimrc"))
source ~/.dotfiles/vimrc
endif