-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
272 lines (222 loc) · 7.42 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
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" Init pathogen plugin
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
" Make Y move like D and C
noremap Y y$
" Use Q to format a paragraph
noremap Q gqap
" Set undo break before deleting with C-U
inoremap <C-U> <C-G>u<C-U>
" Allow backspacing over everything in insert mode
set backspace=indent,eol,start
" Buffers can be hidden without complaints
set hidden
set shiftwidth=4 " Set indentation step to four spaces
set expandtab " Turn tab key presses into spaces in insert mode
set softtabstop=4 " Insert four spaces with every tab press
set tabstop=8 " Let an actual tab character be repesented by
" eight spaces
set history=500 " Keep 500 lines of command line history.
set ruler " Show the cursor position all the time.
set showcmd " Display incomplete commands.
" Being oldfashioned here.
set noincsearch " Don't do incremental searching.
set nohlsearch " Don't highlight search results.
set nowrapscan " Don't wrap around file when searching.
" Don't use two spaces after a sentence when joining lines.
set nojoinspaces
" GUI options
" Must appear before syntax on.
" Autoselect, use icon, don't source menu.vim, left scrollbar.
set guioptions=aiML
" Switch syntax highlighting on.
syntax on
" Use solarized colorscheme with the GUI and URxvt.
if has("gui_running") || $COLORTERM=="rxvt-xpm" || $COLORTERM=="gnome-terminal"
set t_Co=16
set background=dark
colorscheme solarized
else
colorscheme default
endif
" Use lots of undo.
set undolevels=1000
" Use an undodir if persistant undo is available.
if has("persistent_undo")
set undodir=~/.vim/undodir
set undofile
set undoreload=10000
else
" Keep a backup file
set backup
endif
" Tab-completion on the command line.
set wildmenu
set wildmode=list:longest
"use terminal title.
set title
set titleold=[terminal]
"Fix for xcape
inoremap <C-k> <Esc>k
" Navigate quickfix list with PageUp and PageDown keys
nnoremap <silent> <PageDown> :cn<CR>
nnoremap <silent> <PageUp> :cN<CR>
" Home opens the first error, End opens the last
nnoremap <silent> <Home> :cr<CR>
nnoremap <silent> <End> :cla<CR>
" Left and right switches matching tags.
" Up and Down moves you up and down the tag-stack.
nnoremap <silent> <Right> :tn<CR>
nnoremap <silent> <Left> :tN<CR>
nnoremap <silent> <Down> :po<CR>
nnoremap <silent> <Up> :ta<CR>
" I prefer vertical splitting over horizontal
let s:verticalMode=0
fun! s:toggleVerticalMode()
if !s:verticalMode
set splitright
set winwidth=80
cabbrev help vert help
cabbrev sp vsp
cabbrev hsp sp
set diffopt+=vertical
let s:verticalMode=1
else
set nosplitright
set winwidth=20
unabbrev help
unabbrev sp
unabbrev hsp
set diffopt-=vertical
let s:verticalMode=0
endif
endfun
command! ToggleVerticalMode call s:toggleVerticalMode()
if &columns > 150
ToggleVerticalMode
endif
" R toggles relative number
fun! s:toggleRelativeNumber()
if &nu
set rnu
else
set nu
endif
endfun
command! ToggleRelativeNumber call s:toggleRelativeNumber()
noremap R :ToggleRelativeNumber<CR>
" F2 toggles paste
set pastetoggle=<F2>
" F3 toggles mouse and numbers off
" This is useful when Vim cannot access
" the X clipboard
set nu mouse=a
fun! s:toggleMouse ()
if &mouse=='a'
set nonu mouse=
echom "Mouse and numbers disabled"
else
set nu mouse=a
echom "Mouse and numbers enabled"
endif
endfun
command! InvMouse call s:toggleMouse()
nnoremap <silent> <F3> :InvMouse<CR>
inoremap <silent> <F3> <C-o>:InvMouse<CR>
" F4 toggles list
set list listchars=tab:→\ ,eol:↩,trail:\ ,extends:…,precedes:…
nnoremap <silent> <F4> :setlocal invlist<CR>
inoremap <silent> <F4> <C-o>:setlocal invlist<CR>
" F5 toggles using Swedish special characters when typing
" on an American keyboard (Affects insert mode only)
fun! s:svenska()
if &kmp=="swedish"
set kmp=
else
set kmp=swedish
endif
endfun
command! Svenska call s:svenska()
nnoremap <silent> <F5> :Svenska<CR>
inoremap <silent> <F5> <C-o>:Svenska<CR>
" F6 toggles light/dark colors
fun! s:toggleColors()
if &background=='light'
set background=dark
else
set background=light
endif
endfun
command! InvColors call s:toggleColors()
nnoremap <F6> :InvColors<CR>
" Statusline
set laststatus=2 " Allways show
set statusline=%3n\ " Buffer number
set statusline+=%{&ma?&ro?'=':'':'-'} " Nomodifiable: -, Readonly: =
set statusline+=%{&mod?'+':'\ '}\ " Modified: +
set statusline+=\"%f\"\ %L\ lines%<%= " Filename, nr lines
set statusline+=ts=%{&ts}\ " Indention settings
set statusline+=%{&sts?'sts='.&sts.'\ ':''} " Indention settings
set statusline+=sw=%{&sw}\ %{&et?'et\ ':''}\|\ " Indention settings
set statusline+=%{strlen(&ft)?&ft.'\ \|\ ':''} " Filetype
set statusline+=%{strlen(&fenc)?&fenc.'\ ':''} " Encoding
set statusline+=%{&ff=='unix'?'^n':&ff=='dos'?'^r^n':'^r'} "Lineendings
set statusline+=\ \|\ %4l,\ %2c\ " Row, Col
" When writing prose, it is useful to put undo breaks after each sentence
command! Prose inoremap <buffer> . .<C-G>u|
\ inoremap <buffer> ! !<C-G>u|
\ inoremap <buffer> ? ?<C-G>u|
\ setlocal spell spelllang=sv,en
\ nolist nowrap tw=74 fo=t1 nonu|
\ augroup PROSE|
\ autocmd InsertEnter <buffer> set fo+=a|
\ autocmd InsertLeave <buffer> set fo-=a|
\ augroup END
command! Code silent! iunmap <buffer> .|
\ silent! iunmap <buffer> !|
\ silent! iunmap <buffer> ?|
\ setlocal nospell list nowrap
\ tw=74 fo=cqr1 showbreak=… nu|
\ silent! autocmd! PROSE * <buffer>
" Code is default mode
Code
" I use this to correct my spelling mistakes
nnoremap \s ea<C-X><C-S>
" Turn hard wrapped text into soft wrapped.
" This command will join all lines within a range that are not separated
" by empty lines. Automatic word wrap must be off (set fo-=a).
" Useful if you need to copy and paste into a word processor.
command! -range=% SoftWrap
\ <line2>put _ |
\ <line1>,<line2>g/.\+/ .;-/^$/ join |normal $x
" Some GPG commands
" Sign range
command! -range=% Sig <line1>,<line2>!gpg -ats
" Encrypt and sign range
command! -range=% Enc <line1>,<line2>!gpg -atse
" Decryt/Verify range
command! -range=% Dec <line1>,<line2>!gpg -atd
" Strip range of leading ">"
command! -range=% Str <line1>,<line2>s/^> *//
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
filetype plugin indent on
augroup vimrcEx
au!
" When editing a file, always jump to the last known cursor position.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Lets be faithful to out line editor heritage
autocmd WinEnter * set cursorline
autocmd WinLeave * set nocursorline
augroup END
set cursorline
else
set autoindent " always set autoindenting on
endif " has("autocmd")