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
|
" Plugins
call plug#begin()
" Plugins listed below
Plug 'morhetz/gruvbox'
Plug 'lilydjwg/colorizer'
call plug#end()
" Call after plugin is loaded
autocmd vimenter * ++nested colorscheme gruvbox
set nocompatible " This fixes the problem where arrow keys do not function properly on some systems.
let mapleader=' ' " Use space for leader key
" General visual look of Vim
set number
set ruler
set noerrorbells
set laststatus=2
set noshowmode " Don't show mode in bottom status line
let &fillchars ..= ',eob: ' " Hide tildes at EOF
set splitbelow splitright
set cursorline " Highlight the active cursor line
set termguicolors
" Clipboard
set clipboard=unnamedplus
" Text searching options
set incsearch
set ignorecase
set smartcase
set showmatch
" Syntax and formatting
syntax on
set encoding=utf-8
set hidden
" Tabs and indenting
set smartindent
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set noshiftround
set scrolloff=3
" Command line completion options
set showcmd
set wildmenu
filetype plugin on
set omnifunc=syntaxcomplete#Complete
set completeopt=menuone,noselect " Don't autoselect the completion
" Setup undo history
if !isdirectory($HOME."/.vim")
call mkdir($HOME."/.vim", "", 0770)
endif
if !isdirectory($HOME."/.vim/undo-dir")
call mkdir($HOME."/.vim/undo-dir", "", 0700)
endif
set undodir=~/.vim/undo-dir
set undofile
" Colors
set background=dark
hi Normal guibg=NONE ctermbg=NONE " Set background transparent
" Setup terminal with gruvbox dark
let g:terminal_ansi_colors = [
\ '#282828', '#cc241d',
\ '#98971a', '#d79921',
\ '#458588', '#b16286',
\ '#689d6a', '#a89984',
\ '#928374', '#fb4934',
\ '#b8bb26', '#fabd2f',
\ '#83a598', '#d3869b',
\ '#8ec07c', '#ebdbb2',
\]
" Setup netrw
let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 3
let g:netrw_altv = 1
let g:netrw_winsize = 25
" Setup custom statusline
function! GitBranch()
return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
endfunction
function! StatuslineGit()
let l:branchname = GitBranch()
return strlen(l:branchname) > 0?' '.l:branchname.' ':''
endfunction
function! StatuslineMode()
let l:mode=mode()
if l:mode==#"n"
return "Normal"
elseif l:mode==#"v"
return "Visual"
elseif l:mode==#"V"
return "Visual line"
elseif l:mode==#"\<C-V>"
return "Visual block"
elseif l:mode==#"i"
return "Insert"
elseif l:mode==#"R"
return "Replace"
elseif l:mode==#"s"
return "Select"
elseif l:mode==#"t"
return "Terminal"
elseif l:mode==#"c"
return "Enter command"
elseif l:mode==#"!"
return "Shell"
endif
endfunction
"set statusline=
"set statusline+=%#Color458588#
"set statusline+=%#DiffAdd#%{(mode()=='n')?'\ \ NORMAL\ ':''}
"set statusline+=%#Color458588#%{(mode()=='i')?'\ \ INSERT\ ':''}
"set statusline+=%#ReplaceColor#%{(mode()=='R')?'\ \ REPLACE\ ':''}
"set statusline+=%#VisualColor#%{(mode()=='v')?'\ \ VISUAL\ ':''}
"set statusline+=%#PmenuSel#%{(mode()=='\<C-V>')?'\ \ BLOCK\ ':''}
"set statusline+=\ %{StatuslineMode()}\
"set statusline+=%#DiffAdd#
"set statusline+=%{StatuslineGit()}
"set statusline+=\ %F
"set statusline+=\ %r
"set statusline+=%m
"set statusline+=%#CursorColumn#
"set statusline+=%=
"set statusline+=\ %y\
"set statusline+=%#DiffAdd#
"set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
"set statusline+=\[%{&fileformat}\]
"set statusline+=\ %p%%
"set statusline+=\ %l:%c
"set statusline+=\
let g:mode_colors = {
\ 'n': 'StatusLineSection',
\ 'v': 'StatusLineSectionV',
\ "\<C-V>": 'StatusLineSectionV',
\ 'i': 'StatusLineSectionI',
\ 'c': 'StatusLineSectionC',
\ 'r': 'StatusLineSectionR'
\ }
fun! StatusLineRenderer()
let hl = '%#' . get(g:mode_colors, tolower(mode()), g:mode_colors.n) . '#'
return hl
\ . ' %{StatuslineMode()} '
\ . '%#DiffAdd#'
\ . '%{StatuslineGit()}'
\ . '%#DiffAdd#'
\ . ' %F '
\ . ' %r '
\ . (&modified ? ' + ' : '')
\ . '%#CursorColumn#%='
\ . ' %Y '
\ . hl
\ . '%#DiffAdd#'
\ . ' %{&fileencoding?&fileencoding:&encoding}'
\ . ' [%{&fileformat}]'
\ . ' %p%% '
\ . ' %l:%c '
endfun
fun! <SID>StatusLineHighlights()
hi StatusLine ctermbg=8 guibg=#313131 ctermfg=15 guifg=#cccccc
hi StatusLineNC ctermbg=0 guibg=#313131 ctermfg=8 guifg=#999999
hi StatusLineSection ctermbg=8 guibg=#b8bb26 ctermfg=0 guifg=#333333
hi StatusLineSectionV ctermbg=11 guibg=#928374 ctermfg=0 guifg=#000000
hi StatusLineSectionI ctermbg=10 guibg=#83a598 ctermfg=0 guifg=#ffffff
hi StatusLineSectionC ctermbg=12 guibg=#db7b55 ctermfg=0 guifg=#000000
hi StatusLineSectionR ctermbg=12 guibg=#ed3f45 ctermfg=0 guifg=#000000
endfun
call <SID>StatusLineHighlights()
" only set default statusline once on initial startup.
" ignored on subsequent 'so $MYVIMRC' calls to prevent
" active buffer statusline from being 'blurred'.
if has('vim_starting')
let &statusline = ' %{StatusLineFilename()}%= %l:%c '
endif
augroup vimrc
au!
" show focussed buffer statusline
au FocusGained,VimEnter,WinEnter,BufWinEnter *
\ setlocal statusline=%!StatusLineRenderer()
" show blurred buffer statusline
au FocusLost,VimLeave,WinLeave,BufWinLeave *
\ setlocal statusline&
" restore statusline highlights on colorscheme update
au Colorscheme * call <SID>StatusLineHighlights()
augroup END
|