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
|
" Vim configuration
"
" =============================================================================
" Vim-plug setup
" =============================================================================
call plug#begin()
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
Plug 'christoomey/vim-tmux-navigator'
Plug 'vim-scripts/cscope.vim'
Plug 'bling/vim-airline'
Plug 'chriskempson/base16-vim'
Plug 'jlanzarotta/bufexplorer'
Plug 'rking/ag.vim'
call plug#end()
set nocompatible
set ttyfast
" =============================================================================
" External configuration
" =============================================================================
" enable modeline in files
set modeline
" allow local .vimrc files but use only safe options
set exrc
set secure
" =============================================================================
" Colorscheme
" =============================================================================
set t_Co=256
let base16colorspace=256 " Access colors present in 256 colorspace
colorscheme base16-default
set background=dark
syntax on
" highlight matching brackets
set showmatch
" =============================================================================
" Interface
" =============================================================================
set cursorline
set number
set wildmenu
set relativenumber
set shortmess=atI
set laststatus=2
" leader r to toggle relative line numbers
nmap <leader>r :set rnu!<CR>
nnoremap ; :
nnoremap : ;
vnoremap ; :
vnoremap : ;
" =============================================================================
" Indentation
" =============================================================================
set tabstop=8
set softtabstop=8
set shiftwidth=8
set noexpandtab
filetype plugin indent on
" =============================================================================
" Invisible characters
" =============================================================================
nmap <leader>l :set list!<CR>
set listchars=tab:▸\ ,eol:¬
function! Preserve(command)
" Save last search and cursor position
let _s=@/
let l = line(".")
let c = col(".")
execute a:command
" Restore search history and cursor position
let @/=_s
call cursor(l, c)
endfunction
nmap _$ :call Preserve("%s/\\s\\+$//e")<CR>
" =============================================================================
" Buffers
" =============================================================================
" Auto hide buffers without raising error
set hidden
" =============================================================================
" Navigation mappings
" =============================================================================
" better window navigation
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" disable arrow keys
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>
imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>
" better scrolling within wrapped lines
nnoremap j gj
nnoremap k gk
" leader r to toggle relative line numbers
nmap <leader>r ;set rnu!<CR>
set pastetoggle=<F11>
" =============================================================================
" Search
" =============================================================================
set hlsearch
nnoremap <leader><space> :noh<cr>
set incsearch
set smartcase
" use g flag by default
set gdefault
" very magic regular expressions
nnoremap / /\v
vnoremap / /\v
" =============================================================================
" Temporary/backup/undo files
" =============================================================================
" save backups to .vim-backup directory in pwd (if exists), if not, then at
" ~/.vim/backup
if isdirectory($HOME . '/.vim/backup') == 0
:silent !mkdir -p ~/.vim/backup >/dev/null 2>&1
endif
set backupdir-=.
set backupdir+=.
set backupdir-=~/
set backupdir^=~/.vim/backup
set backupdir^=./.vim-backup
set backup
" do simmilar thing for swap files
if isdirectory($HOME . '/.vim/swap') == 0
:silent !mkdir -p ~/.vim/swap >/dev/null 2>&1
endif
set directory=./.vim-swap//
set directory+=~/.vim/swap//
" and for undo files
if exists("+undofile")
if isdirectory($HOME . '/vim/undo') == 0
:silent !mkdir -p ~/.vim/undo >/dev/null 2>&1
endif
set undodir=./.vim-undo//
set undodir+=~/.vim/undo//
set undofile
endif
set viminfo+=n~/.vim/viminfo
" =============================================================================
" Scrolling
" =============================================================================
set scrolloff=10
" =============================================================================
" Cscope
" =============================================================================
"
nnoremap <leader>fa :call cscope#findInteractive(expand('<cword>'))<CR>
nnoremap <leader>l :call ToggleLocationList()<CR>
" s: Find this C symbol
nnoremap <leader>fs :call cscope#find('s', expand('<cword>'))<CR>
" g: Find this definition
nnoremap <leader>fg :call cscope#find('g', expand('<cword>'))<CR>
" d: Find functions called by this function
nnoremap <leader>fd :call cscope#find('d', expand('<cword>'))<CR>
" c: Find functions calling this function
nnoremap <leader>fc :call cscope#find('c', expand('<cword>'))<CR>
" t: Find this text string
nnoremap <leader>ft :call cscope#find('t', expand('<cword>'))<CR>
" e: Find this egrep pattern
nnoremap <leader>fe :call cscope#find('e', expand('<cword>'))<CR>
" f: Find this file
nnoremap <leader>ff :call cscope#find('f', expand('<cword>'))<CR>
" i: Find files #including this file
nnoremap <leader>fi :call cscope#find('i', expand('<cword>'))<CR>
" =============================================================================
" Plugins configuration
" =============================================================================
"
let g:airline_powerline_fonts = 1
|