-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
283 lines (210 loc) · 7.07 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
273
274
275
276
277
278
279
280
281
282
283
" Tips {{{1
"
" When using a put command like p or P in Visual mode, Vim will try to replace
" the selected text with the contents of the register.
" <C-R>=, or Ctrl+R= is used to insert the result of an expression at the cursor.
" :help i_ctrl_r
" = is the "expression register". See :help "=
" q: — Open with a command history from normal mode
" q/ — Open with a search history from normal mode (to search forward)
" q? — Open with a search history from normal mode (to search backward)
" Ctrl+F — Open with a command history from command mode
" you can yank, delete or change forward or backward to a search result:
" y/search<Enter>
" y?search<Enter>
" d/search<Enter>
" d?search<Enter>
" c/search<Enter>
" c?search<Enter>
" ctags
" ctags -R --fields=+ialS --language=c
" hitting g] or CTRL-] will jump to the place where that method is defined or implemented.
" :CtrlPTag will let you search through your tags file and jump to where tags are defined
" built-in solution to the problem of mismatches when using the jump commands
" (f, t, F, T) is the use of ; and, Semicolon will repeat the last jump command,
" and comma will repeat it in the opposite direction. t: till before
"
" }}}
" Use Vim settings, rather then Vi settings.
set nocompatible
let mapleader = "\<Space>"
let g:mapleader = "\<Space>"
if filereadable(expand("~/.vimrc.plug"))
source ~/.vimrc.plug
endif
filetype plugin indent on
" No audible bell
set vb
" improves redrawing for newer computers
set ttyfast
" will not redraw the screen while running macros (goes faster)
set lazyredraw
" display incomplete commands
set showcmd
" Open new split panes to right and bottom, which feels more natural
set splitbelow
set splitright
" Intuitive backspacing in insert mode
set backspace=indent,eol,start
" key map {{{1
" don't use Arrow to navigator
nnoremap <Left> :echoe "Use h"<CR>
nnoremap <Right> :echoe "Use l"<CR>
nnoremap <Up> :echoe "Use k"<CR>
nnoremap <Down> :echoe "Use j"<CR>
nnoremap <Leader>q :q!<cr>
nnoremap <Leader>w :w<cr>
" Resize Window
nnoremap <Leader>- 2<C-w>-
nnoremap <Leader>= 2<C-w>+
" http://vim.wikia.com/wiki/Move_cursor_by_display_lines_when_wrapping
nnoremap <silent> j gj
nnoremap <silent> k gk
vnoremap <silent> j gj
vnoremap <silent> k gk
" Typing 'a will jump to the line marked with ma. However, `a will jump to the
" line and column marked with ma. "swap them.
nnoremap ' `
nnoremap ` '
" For when you forget to sudo.. Really Write the file.
cmap w!! w !sudo tee % >/dev/null
" select last changed/pasted text
" similar to the standard 'gv': select the last visually-selected text.
" http://vim.wikia.com/wiki/Selecting_your_pasted_text
nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'
" press <Enter> to toggle fold
" foldmethod: indent, syntax, marker, manual etc
nnoremap <expr> <CR> foldlevel(line('.')) ? "za" : "\<CR>"
" Find merge conflict markers
nnoremap <leader>fc /\v^[<\|=>]{7}( .*\|$)<CR>
if !has("gui_running")
silent !stty -ixon > /dev/null 2>&1
imap <C-q> <Esc>:q!<CR>
map <C-q> :q!<CR>
endif
" An alternative for the esc key is CTRL+[ combination
inoremap jk <Esc>
nnoremap <F5> :w<CR> :silent make<CR>
inoremap <F5> <Esc>:w<CR>:silent make<CR>
" }}}
" visual style {{{1
"always show the status line
set laststatus=2
if has("gui_running")
set guioptions-=r "remove right-hand scroll bar
set guioptions-=L "remove left-hand scroll bar
set gfn=Anonymice\ Powerline:h14
" colorscheme
let g:rehash256=1
let g:molokai_original=1
colorscheme molokai
set t_Co=256 "for terminal
else
colorscheme gruvbox
endif
set background=dark
" enable syntax highlight
syntax enable
" must after loading theme related
" Font used by gvim/Terminal must support italic typeface
highlight Comment cterm=italic
highlight Comment gui=italic
" highlight current line
set cursorline
" show matching bractes
set showmatch
set number
" 'list' is to visualise tabs, spaces, and line endings
" eol: the character to show at the end of each line
" tab: the characters to show a tab. Two characters are used, 2nd will be
" repeated for each space
" trail: character to show for trailling spaces
" vim-better-space is installed, only set tab here
set listchars=tab:▸\ ,
" it is convenient to use :set list! to toggle the option 'list' on
set list
" set textwidth=80
" set cc=+1
" }}}
" clipboard {{{1
" make all yanking/deleting operations automatically copy to the system clipboard
"
" since the version of vim that comes with OSX does not support using the system
" clipboard, mvim is used. This command will also alias vim, vi, view, vimdiff,
" etc. brew install macvim --override-system-vim && brew linkapps
if has("clipboard")
" on Mac and Windows, use * register for copy-paste
if has("macunix")||has("win32")||has("win64")
set clipboard=unnamed
else " on Linux, use + register for copy-paste
set clipboard=unnamedplus
endif
endif
" }}}
" backup {{{1
set nobackup
set noswapfile
if has("persistent_undo")
"directory must be existed first
set undodir='~/.undodir/'
set undofile
set undolevels=1000 " Maximum number of changes that can be undone
set undoreload=10000 " Maximum number lines to save for undo on a buffer reload
endif
" }}}
" search {{{1
" highlight search
set hlsearch
" start searching when you type the first character
set incsearch
" these two options, when set together, will make /-style searchs
" case-sensitive only if there is a capital letter in the search expression.
" *-style searchs continue to be consistently case-sensitive
set ignorecase
set smartcase
" }}}
" file {{{1
" Allow buffer switching without saving
set hidden
set wildignore+=*.o,*.so,*.ko,*.swp,*.zip,*.pyc
set formatoptions+=mM
set encoding=utf-8
set fileencodings=ucs-bom,utf8,gbk
set fileformats=unix,dos,mac
" set to auto read when a file is changed from tht outside
set autoread
" automatically save before running command
set autowrite
" }}}
" indent {{{1
" to insert a real tab when 'expandtab' is on, use CTRL-V<Tab>
" set expandtab
set tabstop=4 shiftwidth=4 softtabstop=4
"help smarttab
"set smarttab
" }}}
" autocmd {{{1
augroup vimrc
autocmd!
" Auto jump to last edit place when opening a file
if has("autocmd")
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal g'\"" | endif
endif
" Instead of reverting the cursor to the last position in the buffer, set it to
" the first line when editing a git commit message
autocmd FileType gitcommit autocmd! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0])
" Always switch to the current file directory
autocmd BufEnter * if bufname("") !~ "^\[A-Za-z0-9\]*://" | lcd %:p:h | endif
augroup END
" cause the quickfix window to open after any grep invocation:
autocmd QuickFixCmdPost *grep* cwindow
" }}}
if filereadable('./local.vimrc')
so ./local.vimrc
endif
" set grepprg=ag\ --nogroup\ --nocolor
" command -nargs=+ -complete=file -bar Ag silent! grep! <args>|cwindow|redraw!
" nnoremap K :grep! "\b<C-R><C-W>\b"<CR>:cw<CR>
" nnoremap <leader>/ :Ag<SPACE>
" vim: set foldlevel=0 foldmethod=marker: