-
Notifications
You must be signed in to change notification settings - Fork 1
/
.vimrc
197 lines (150 loc) · 5.65 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
" Want vim not vi
set nocompatible
" Setup pathogen as our package manager
execute pathogen#infect()
" Generate help tags from pathogen packages
Helptags
" Automatic global session persistence, but only for when there are no parameters to the vim command
" The order of autocmds matters, we need load a new session, then run subsequent autocmds
function! SaveSession()
execute "mksession! /tmp/Session.vim"
echo "Saved session."
endfunction
function! LoadSession()
if (filereadable("/tmp/Session.vim"))
execute "source /tmp/Session.vim"
echo "Loaded session."
else
echo "No session available."
endif
endfunction
autocmd VimEnter * if argc() == 0 | call LoadSession() | endif
autocmd VimLeavePre * if argc() == 0 | call SaveSession() | endif
" Consider the background as dark
set background=dark
" Choose the colour scheme
colorscheme solarized
" Indent guides
let g:indent_guides_auto_colors = 0
let g:indent_guides_guide_size = 1
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd guibg=#262626 ctermbg=236
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=#262626 ctermbg=236
autocmd VimEnter * :IndentGuidesEnable
" Enable syntax highlighting
syntax on
" Vim takes control of the mouse, but holding shift will switch back to default mouse handling
set mouse=a
" Show number line
set number
" Relative number lines
set relativenumber
" Indent breaks for indented wrapped lines
set breakindent
" Visualisation for wrapped lines
set showbreak=➥\
" Always show 1 line above and below the cursor
set scrolloff=1
" Change window title to the file being edited
set title
" Allow the opening of new buffers without closing existing buffers, they become hidden
set hidden
" Change cursor shape when in command or insert mode, also works in TMUX
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\e[5 q\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\e[2 q\<Esc>\\"
elseif exists('$KONSOLE_PROFILE_NAME')
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
else
let &t_SI = "\e[5 q"
let &t_EI = "\e[2 q"
endif
" Show literal tabs as 4 spaces width
set tabstop=4
" 4 columns are used when tab is hit in insert mode
set softtabstop=4
" Tabs are inserted as 4 spaces
set expandtab
" When indenting with '>', use 4 spaces width
set shiftwidth=4
" Show last keystroke commands on the bottom right
set showcmd
" Keep the indentation when entering a new line
set autoindent
" Use custom configuration for different languages
filetype plugin indent on
" Show current line
set cursorline
" Cursor line highlight should be darker than the background
hi CursorLine cterm=NONE ctermbg=black guibg=black
hi CursorLineNR cterm=bold
" Show current column (disabled)
" set cursorcolumn
" Cursor column highlight should be darker than the background
" hi CursorColumn ctermbg=black guibg=black
" Show matching parantheses or brackets
set showmatch
hi MatchParen cterm=bold,underline ctermbg=none
" Visual autocomplete for command menu
set wildmenu
" Lazy redrawing of the screen, resulting in faster macros
set lazyredraw
" Incremental search
set incsearch
" Highlight search matches
set hlsearch
set statusline=%F%m%r%<\ %=%l,%v\ [%L]\ %p%%
hi statusline ctermbg=white ctermfg=black
set laststatus=2
" Enable swapfiles to guard against crashes (appears as `.file.swp`)
set swapfile
" Enable a persistent undo (appears as `.file.un~`)
set undofile
" Do not create persistent backups (as we already have persistent undo) (would appear as `file~`)
set nobackup
" Do create a backup just before overwriting the file (will appear as `file~`)
set writebackup
" Code folding based on indentation
set foldmethod=indent
" Don't fold anything by default
set nofoldenable
" Starting the folding level at 1 + the highest fold level in the file
autocmd BufWinEnter * normal zR
" Use Shift + Tab to insert a literal tab
inoremap <S-Tab> <C-V><Tab>
" Use the comma as the leader key
let mapleader=","
" Visually show tabs and newline-terminated spaces (this is useful for looking up erroneous whitespace)
set listchars=tab:•·,trail:·,extends:>,precedes:<
set list
" Check the file for changes to reload if after user input then idle cursor for X seconds (where X is by default 4)
" If we have not made any changes, it reloads automatically, if we have made changes, there will be a prompt asking us what to do
set autoread
au CursorHold,CursorHoldI * if getcmdwintype() == '' | checktime | endif
" Set backspace to be able to backspace pass insert start, indentation and end of line in insert mode
set backspace=indent,eol,start
" Allow left right arrow and space key to move past newlines in all modes
" It doesn't work for backspace, because we mapped backspace to X,x, and these cannot move past newlines
set whichwrap=b,s,<,>,[,]
" In normal mode, we make Backspace and Del keys delete without cutting to a register
" This aligns Backspace and Del key behaviour to most modeless editors
" Basically this will mean it won't clobber our copying registers.
" The _ is the blackhole register
" The x, X, d, D still cut normally, they don't just delete
" If you want a non-cutting d/D, just use visual mode + X and x
nnoremap <BS> "_X
nnoremap <Del> "_x
" In visual mode, X ends up deleting the entire line, so to align behaviour, we use x instead.
vnoremap <BS> "_x
vnoremap <Del> "_x
" Move vertically by line visually, this is useful for wrapped lines (don't skip the wrapped lines!)
" This behaviour aligns it with standard text editors
nnoremap k gk
nnoremap <Up> gk
nnoremap j gj
nnoremap <Down> gj
" Reset the search highlight
nnoremap <leader><space> :nohlsearch<CR>
" Map to gundo
nnoremap <leader>u :GundoToggle<CR>