aboutsummaryrefslogtreecommitdiffhomepage
path: root/vim/init/basic.vim
diff options
context:
space:
mode:
Diffstat (limited to 'vim/init/basic.vim')
-rw-r--r--vim/init/basic.vim279
1 files changed, 279 insertions, 0 deletions
diff --git a/vim/init/basic.vim b/vim/init/basic.vim
new file mode 100644
index 0000000..4c6cd45
--- /dev/null
+++ b/vim/init/basic.vim
@@ -0,0 +1,279 @@
1"======================================================================
2"
3" init-basic.vim - Need vim tiny compatible
4"
5" Used for general usecases. No keymap and personal preference
6"
7" Use '*' to search for:
8" VIM_BEHAVIOR
9" VISUAL
10" EDIT
11" JUMP
12" SEARCH
13" SYNTAX_HIGHLIGHT
14" BUFFERS
15" ENCODING_PREFERENCE
16" FOLDING
17" MISC
18"======================================================================
19
20
21"----------------------------------------------------------------------
22" VIM_BEHAVIOR
23"----------------------------------------------------------------------
24
25let mapleader = "," " Always use comma as leader key
26set nocompatible " Disable vi compatible, today is 20XX
27set autochdir " Automatically cd to current file
28set path=.,** " Allow :find with completion
29set mouse= " Disable mouse selection
30set winaltkeys=no " Allow alt key for mapping
31set cursorline
32
33" Turn persistent undo on
34" means that you can undo even when you close a buffer/VIM
35set undofile
36set undodir=~/.vim/.undodir
37set conceallevel=1
38
39" Apply plugin and indent by filetype
40filetype plugin indent on
41
42
43"----------------------------------------------------------------------
44" VISUAL
45"----------------------------------------------------------------------
46
47colorscheme desert " I like desert!
48" In most of the cases, it is overrides by lightline.vim
49set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c
50set showmatch " Show pairing brackets
51
52set number relativenumber " Use relativenumber
53set wrap " Disable wrap by default
54set scrolloff=3 " Leave some buffer when scrolling down
55set ruler " Show cursor position
56set laststatus=2 " Always show the status line
57set guicursor=n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20
58
59
60"----------------------------------------------------------------------
61" EDIT
62"----------------------------------------------------------------------
63
64set backspace=eol,start,indent " Set Backspace behaviors
65set autoindent " If current line has indent, automatically set indent for next line
66set cindent
67set ttimeout
68set ttimeoutlen=50
69set updatetime=250
70
71imap <C-c> <Esc>l
72" Change IM to US when exit to Normal mode
73autocmd InsertLeave * :silent !fcitx-remote -c &>/dev/null || true
74
75
76"----------------------------------------------------------------------
77" JUMP
78"----------------------------------------------------------------------
79
80set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~ " This affects filename recognition for gf (go to file)
81set suffixesadd=.md " Enable reference markdown file without extension
82
83
84"----------------------------------------------------------------------
85" SEARCH
86"----------------------------------------------------------------------
87set ignorecase " Search case without case sensation
88set smartcase
89set hlsearch " Hilight all matched texts
90set incsearch " Show matched strings when typing
91
92
93"----------------------------------------------------------------------
94" SYNTAX_HIGHLIGHT
95"----------------------------------------------------------------------
96
97syntax enable
98
99function! GetHighlightGroupName()
100 let l:syntaxID = synID(line('.'), col('.'), 1)
101 let l:groupName = synIDattr(l:syntaxID, 'name')
102 echo "Highlight Group Name: " . l:groupName
103endfunction
104
105" Defualt highlight for matched parenthesis is so weird in many colorscheme
106" Why the background color is lighter than my caret !?
107highlight MatchParen ctermfg=NONE ctermbg=darkgrey cterm=NONE
108highlight LuaParen ctermfg=NONE ctermbg=darkgrey cterm=NONE
109
110" Show trailing spaces
111highlight ExtraWhitespace ctermbg=red guibg=red
112match ExtraWhitespace /\s\+$/
113
114" Persist visualized lines
115" define line highlight color
116highlight MultiLineHighlight ctermbg=LightYellow guibg=LightYellow ctermfg=Black guifg=Black
117" highlight the current line
118nnoremap <silent> <leader><leader>h :call matchadd('MultiLineHighlight', '\%'.line('.').'l')<CR>
119" clear all the highlighted lines
120nnoremap <silent> <leader><leader>H :call clearmatches()<CR>
121
122
123"----------------------------------------------------------------------
124" BUFFERS
125"----------------------------------------------------------------------
126
127" Set to auto read when a file is changed from the outside
128" Unnamed buffer like CmdWindows should prevent this
129set autoread
130autocmd FocusGained,BufEnter .* checktime
131
132let g:quitVimWhenPressingCtrlC = 1
133function! ToggleQuit()
134 let g:quitVimWhenPressingCtrlC = g:quitVimWhenPressingCtrlC ? 0 : 1
135 let message = g:quitVimWhenPressingCtrlC ? "Unlock" : "Lock"
136 echo message
137endfunction
138
139nnoremap gl :call ToggleQuit()<CR>
140
141" Simply exit when closing the last buffer
142function! Bye()
143 " Delete current buffer if working on special filetype
144 let specialFileTypes = ['help', 'netrw', 'vim-plug', 'nerdtree']
145 if index(specialFileTypes, &filetype) != -1
146 :bdelete
147 " Delete current buffer if more than one buffers
148 elseif len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) != 1
149 :bdelete
150 elseif g:quitVimWhenPressingCtrlC
151 " Otherwise, quit vim
152 :silent! qall
153 else
154 :echo "Press gl to allow quit with <C-c>"
155 endif
156endfunction
157
158" Ctrl-C rules!!!
159nnoremap <silent> <C-c> :call Bye()<CR>
160
161" Don't unload a buffer when no longer shown in a window
162" This allows you open a new buffer and leaves current buffer modified
163set hidden
164
165
166" Put these in an autocmd group, so that you can revert them with:
167" ":augroup vimStartup | au! | augroup END"
168augroup vimStartup
169au!
170
171" When editing a file, always jump to the last known cursor position.
172" Don't do it when the position is invalid, when inside an event handler
173" (happens when dropping a file on gvim) and for a commit message
174" (it's likely a different one than last time).
175autocmd BufReadPost *
176 \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
177 \ | exe "normal! g`\""
178 \ | endif
179augroup END
180
181" Set filetype for beancount
182autocmd BufRead,BufNewFile *.bean call PrepareBean()
183function PrepareBean()
184 set filetype=beancount
185 silent !setsid fava ~/bean/main.bean &>/dev/null
186 autocmd VimLeave * silent !killall fava
187endfunction
188
189" Set filetype for index.html
190autocmd BufWrite *.html,*.js,*.css call ReloadServer()
191function ReloadServer()
192 silent !browser-sync reload &>/dev/null
193endfunction
194
195" Hide the first line of a file if editing password file
196" TODO a better way to determine a file is related to password-store, now use
197" files under /dev/shm as filter
198autocmd BufRead /dev/shm/*.txt call SetPasswordFile()
199function SetPasswordFile()
200 setlocal foldminlines=0
201 setlocal foldmethod=manual
202 setlocal foldtext=
203 norm! ggzfl
204endfunction
205
206
207
208"----------------------------------------------------------------------
209" ENCODING_PREFERENCE
210"----------------------------------------------------------------------
211if has('multi_byte')
212 set encoding=utf-8
213 set fileencoding=utf-8
214 " Try encodings by this order
215 set fileencodings=utf-8,big5,ucs-bom,gbk,gb18030,euc-jp,latin1
216endif
217
218
219"----------------------------------------------------------------------
220" FOLDING
221"----------------------------------------------------------------------
222set foldenable " Allow fold
223set foldmethod=indent " Fold contents by indent
224set foldlevel=99 " Expand all by default
225
226
227"----------------------------------------------------------------------
228" MISC
229"----------------------------------------------------------------------
230
231" 顯示括號匹配的時間
232set matchtime=2
233
234" 顯示最後一行
235set display=lastline
236
237" 允許下方顯示目錄
238set wildmenu
239
240" Improve performance
241set lazyredraw
242
243" Format of error message
244set errorformat+=[%f:%l]\ ->\ %m,[%f:%l]:%m
245
246" 顯示分隔符號
247set listchars=tab:\|\ ,trail:.,extends:>,precedes:<
248
249" 遇到Unicode值大於255的文本,不必等到空格再折行
250set formatoptions+=m
251
252" 合併兩行中文時,不在中間加空格
253set formatoptions+=B
254
255" Use Unix way to add newline
256set ffs=unix,dos,mac
257
258
259"----------------------------------------------------------------------
260" Ignore these suffixes when find/complete
261"----------------------------------------------------------------------
262set suffixes=.bak,~,.o,.h,.info,.swp,.obj,.pyc,.pyo,.egg-info,.class
263
264set wildignore=*.o,*.obj,*~,*.exe,*.a,*.pdb,*.lib "stuff to ignore when tab completing
265set wildignore+=*.so,*.dll,*.swp,*.egg,*.jar,*.class,*.pyc,*.pyo,*.bin,*.dex
266set wildignore+=*.zip,*.7z,*.rar,*.gz,*.tar,*.gzip,*.bz2,*.tgz,*.xz " MacOSX/Linux
267set wildignore+=*DS_Store*,*.ipch
268set wildignore+=*.gem
269set wildignore+=*.png,*.jpg,*.gif,*.bmp,*.tga,*.pcx,*.ppm,*.img,*.iso
270set wildignore+=*.so,*.swp,*.zip,*/.Trash/**,*.pdf,*.dmg,*/.rbenv/**
271set wildignore+=*/.nx/**,*.app,*.git,.git
272set wildignore+=*.wav,*.mp3,*.ogg,*.pcm
273set wildignore+=*.mht,*.suo,*.sdf,*.jnlp
274set wildignore+=*.chm,*.epub,*.pdf,*.mobi,*.ttf
275set wildignore+=*.mp4,*.avi,*.flv,*.mov,*.mkv,*.swf,*.swc
276set wildignore+=*.ppt,*.pptx,*.docx,*.xlt,*.xls,*.xlsx,*.odt,*.wps
277set wildignore+=*.msi,*.crx,*.deb,*.vfd,*.apk,*.ipa,*.bin,*.msu
278set wildignore+=*.gba,*.sfc,*.078,*.nds,*.smd,*.smc
279set wildignore+=*.linux2,*.win32,*.darwin,*.freebsd,*.linux,*.android