-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
213 lines (167 loc) · 6.1 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
" just pure vim, no vi compatible mode
set nocompatible
" init pathogen (for plugins in ~/.vim/bundle)
runtime bundle/vim-pathogen/autoload/pathogen.vim
call pathogen#infect()
call pathogen#helptags()
" Enable loading filetype
filetype plugin on
" Turn syntax highlighting on
syntax on
" When auto-completing, insert longest common prefix, and list all options
" When not configured, CTRL-L and CTRL-D do those tasks, respectively
set wildmode=longest:list
" show line and column number of the cursor position in status line
set ruler
" Incremental search (show matches as you type search string)
set incsearch
" Don't highlight results of a search (when not searching anymore)
set nohlsearch
" Use F5 to toggle 'paste' mode, faster than :set paste / :set paste&
set pastetoggle=<F5>
" Use 4 spaces for (auto)indent, with cindent, <<, >>
set shiftwidth=4
" Spaces to show for <Tab> and replace when using :retab
set tabstop=4
" Replaces a tab with a series of spaces in insert mode
" to insert a real tab the following should be used: CTRL-V<Tab>
set expandtab
" Mostly regarding automatic white-space handling see |fo-table|
" c - to autowrap comment lines to a set textwidth
" r - when writing a comment and going to a new line, comment leader is added
" o - add comment leader when starting an edit on a comment using 'o' command
" n - recognize numbered lists: 1. 2., 3: 4: and indent them automatically
" l - existing long lines are not automatically formatted to textwidth if edited
set formatoptions+=croqln
" The a option is what reworks the spacing of entire paragraph on edit
set formatoptions-=a
" The t option causes text to autowrap when you reach at textwidth
set formatoptions-=t
" Do not use special octal processing for CTRL-A/CTRL-X for numbers that begin
" with zero, treat them as normal decimals
set nrformats-=octal
" Set maximum text width (for wrapping)
set textwidth=80
" Folding options
set foldlevel=1000
set foldcolumn=0
" show commands in the status
set showcmd
" When a bracket is inserted, briefly jump to a matching one
set showmatch
" Jump to matching bracket for 5/10th of a second (used by showmatch)
set matchtime=5
" Increase history size for use w/ q:
set history=1000
" Show status bar for all windows
set laststatus=2
" Do not show mode, because airline will have it in the status line
set noshowmode
" Do not add two spaces from joining w/ J
set nojoinspaces
" case-insensitive search
set ignorecase
" switch to case-sensitive in mixed case is used in the search term
set smartcase
" copy indent from previous line for O and o
set autoindent
" smart indent around {} and certain keywords
set smartindent
" Determine what's saved in .viminfo
" remember marks for the last 20 files,
" save max 50 lines for each registry up to 10Kb
set viminfo='20,<50,s10
" Enable backups
" Note $VIM_MAIN_BACKUP_DIR is used in backup plugin,
" that build file path hierarhy and takes incremental
" snapshots
let $VIM_MAIN_BACKUP_DIR=expand("~/.vimbackups")
if !isdirectory($VIM_MAIN_BACKUP_DIR)
silent! execute "!mkdir $VIM_MAIN_BACKUP_DIR"
endif
set backup
set backupdir=$VIM_MAIN_BACKUP_DIR
" If file is opened in read-only mode we can will write them as root
" :W
command! W :execute ':silent w !sudo tee % > /dev/null' | :edit!
" Settings for CTRL-P plugin
" open a ctrl-p search by pressing space
nnoremap [<Space> :CtrlPMixed<CR>
let g:ctrlp_show_hidden = 1
" Show NerdTree
nnoremap <Leader>f :NERDTreeToggle<CR>
" display line numbers and be relative to current line
set number
set relativenumber
" Airline settings for a status line customizations
set t_Co=256
let g:airline_powerline_fonts=1
let g:airline_theme='solarized'
" Get current color variant from management script
function! ColorMode(mode)
if a:mode == 'light'
set background=light
else
set background=dark
highlight Normal ctermbg=0
endif
endfunction
function! ApplyColorMode(...)
if a:0 > 0
let color_variant=a:1
else
let color_variant=system("$HOME/bin/color-mode-for-term")
if v:shell_error
" if no management script, fall back to env variable
let color_variant=$TERM_COLOR_VARIANT
endif
endif
call ColorMode(color_variant)
endfunction
function! ColorModeToggle()
call ApplyColorMode(&background == 'dark' ? 'light' : 'dark')
endfunction
nnoremap <Leader>c :call ColorModeToggle()<CR>
let g:solarized_contrast='normal'
colorscheme solarized
call ApplyColorMode()
" Learn homerow!
noremap <Up> :echom "Use k"<CR>
noremap <Down> :echom "Use j"<CR>
noremap <Left> :echom "Use h"<CR>
noremap <Right> :echom "Use l"<CR>
" automatically leave insert mode after 'updatetime' milliseconds of inaction
au CursorHoldI * stopinsert
" set 'updatetime' just for insert mode / default is 4000 ms
au InsertEnter * let updaterestore=&updatetime | set updatetime=5000
au InsertLeave * let &updatetime=updaterestore
" Go lang
let g:go_fmt_command = 'goimports'
if isdirectory($GOPATH . '/src/github.com/golang/lint/misc/vim')
set rtp+=$GOPATH/src/github.com/golang/lint/misc/vim
endif
function! Smart_TabComplete()
let line = getline('.') " current line
let substr = strpart(line, -1, col('.')+1) " from the start of the current
" line to one character right
" of the cursor
let substr = matchstr(substr, "[^ \t]*$") " word till cursor
if (strlen(substr)==0) " nothing to match on empty string
return "\<tab>"
endif
let has_period = match(substr, '\.') != -1 " position of period, if any
let has_slash = match(substr, '\/') != -1 " position of slash, if any
if (!has_period && !has_slash)
return "\<C-X>\<C-P>" " existing text matching
elseif ( has_slash )
return "\<C-X>\<C-F>" " file matching
else
return "\<C-X>\<C-O>" " plugin matching
endif
endfunction
inoremap <tab> <c-r>=Smart_TabComplete()<CR>
" local customizations
let $LOCALFILE=expand("~/.vimrc_extras")
if filereadable($LOCALFILE)
source $LOCALFILE
endif