aboutsummaryrefslogtreecommitdiffhomepage
path: root/vim/init/basic.vim
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-07-08 22:49:59 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-07-08 22:49:59 +0800
commitd834d6da82ba20e32699380d335a65936bad16f9 (patch)
tree49ce9f0427801c7803ed6c41633ae94821b2cc97 /vim/init/basic.vim
parenta86b98129c07ff6ac4e259d5e28499471f47e57c (diff)
Update
Diffstat (limited to 'vim/init/basic.vim')
-rw-r--r--vim/init/basic.vim195
1 files changed, 61 insertions, 134 deletions
diff --git a/vim/init/basic.vim b/vim/init/basic.vim
index 2867f69..b268c6b 100644
--- a/vim/init/basic.vim
+++ b/vim/init/basic.vim
@@ -1,36 +1,24 @@
1"====================================================================== 1"======================================================================
2"
3" init-basic.vim - Need vim tiny compatible 2" init-basic.vim - Need vim tiny compatible
4" 3"
5" Used for general usecases. No keymap and personal preference 4" 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" BUFFERS
14" TABSIZE
15" ENCODING_PREFERENCE
16" FOLDING
17" BACKUP
18" MISC
19"====================================================================== 5"======================================================================
20 6
7" Vimscript file settings ---------------------- {{{
21 8
22"---------------------------------------------------------------------- 9" Usage: type --- for foldmark
23" VIM_BEHAVIOR 10augroup filetype_vim
24"---------------------------------------------------------------------- 11 autocmd!
25 12 execute "autocmd FileType vim :inoreabbrev <buffer> --- ----------------{".."{{"
13 autocmd FileType vim setlocal foldmethod=marker foldlevel=0
14augroup END
15" }}}
16" VIM_BEHAVIOR ----------------{{{
26let mapleader = "," " Always use comma as leader key 17let mapleader = "," " Always use comma as leader key
27set nocompatible " Disable vi compatible, today is 20XX 18set nocompatible " Disable vi compatible, today is 20XX
28set path=.,** " Allow :find with completion 19set path=.,** " Allow :find with completion
29set mouse= " Disable mouse selection 20set mouse= " Disable mouse selection
30set winaltkeys=no " Allow alt key for mapping 21set winaltkeys=no " Allow alt key for mapping
31set cursorline
32set whichwrap=b,s
33" set autochdir " Automatically cd to current file
34 22
35" Turn persistent undo on 23" Turn persistent undo on
36" means that you can undo even when you close a buffer/VIM 24" means that you can undo even when you close a buffer/VIM
@@ -41,28 +29,44 @@ set conceallevel=1
41" Apply plugin and indent by filetype 29" Apply plugin and indent by filetype
42filetype plugin indent on 30filetype plugin indent on
43 31
44 32" Set to auto read when a file is changed from the outside
45"---------------------------------------------------------------------- 33" Unnamed buffer like CmdWindows should prevent this
46" VISUAL 34set autoread
47"---------------------------------------------------------------------- 35autocmd FocusGained,BufEnter .* checktime
36" }}}
37" VISUAL ----------------{{{
48 38
49" colorscheme desert " I like desert! 39" colorscheme desert " I like desert!
50 40
51" In most of the cases, it is overrides by lightline.vim 41" Editing Area
52set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c
53set showmatch " Show pairing brackets
54
55set number relativenumber " Use relativenumber 42set number relativenumber " Use relativenumber
56set wrap " Disable wrap by default 43set wrap " enable wrap by default
57set scrolloff=3 " Leave some buffer when scrolling down 44set scrolloff=3 " Leave some buffer when scrolling down
58set ruler " Show cursor position 45set showmatch " Show pairing brackets
59set laststatus=2 " Always show the status line 46set display=lastline
47set lazyredraw
48set formatoptions+=m " 遇到Unicode值大於255的文本,不必等到空格再折行
49set formatoptions+=B " 合併兩行中文時,不在中間加空格
50set whichwrap=b,s
51
52" Cursor
53set cursorline
60set guicursor=n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20 54set guicursor=n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20
55set matchtime=2
56
57" In most of the cases, it is overrides by lightline.vim
58set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c
59set laststatus=2 " Always show the status line
60set ruler " Show cursor position
61set wildmenu wildoptions=pum,fuzzy
61 62
63" Format of error message
64set errorformat+=[%f:%l]\ ->\ %m,[%f:%l]:%m
62 65
63"---------------------------------------------------------------------- 66" 顯示分隔符號
64" EDIT 67set listchars=tab:\|\ ,trail:.,extends:>,precedes:<
65"---------------------------------------------------------------------- 68" }}}
69" EDIT ----------------{{{
66 70
67set backspace=eol,start,indent " Set Backspace behaviors 71set backspace=eol,start,indent " Set Backspace behaviors
68set autoindent " If current line has indent, automatically set indent for next line 72set autoindent " If current line has indent, automatically set indent for next line
@@ -76,32 +80,21 @@ imap <C-c> <Esc>l
76" Change IM to US when exit to Normal mode 80" Change IM to US when exit to Normal mode
77autocmd InsertLeave * :silent !fcitx-remote -c &>/dev/null || true 81autocmd InsertLeave * :silent !fcitx-remote -c &>/dev/null || true
78 82
79 83" }}}
80"---------------------------------------------------------------------- 84" JUMP to anoterh file ----------------{{{
81" JUMP
82"----------------------------------------------------------------------
83 85
84set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~ " This affects filename recognition for gf (go to file) 86set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~ " This affects filename recognition for gf (go to file)
85set suffixesadd=.md " Enable reference markdown file without extension 87set suffixesadd=.md " Enable reference markdown file without extension
86 88
87 89" }}}
88"---------------------------------------------------------------------- 90" SEARCH ----------------{{{
89" SEARCH 91set ignorecase " Search case without case sensation
90"----------------------------------------------------------------------
91set ignorecase " Search case without case sensation
92set smartcase 92set smartcase
93set hlsearch " Hilight all matched texts 93set hlsearch " Hilight all matched texts
94set incsearch " Show matched strings when typing 94set incsearch " Show matched strings when typing
95 95" }}}
96"---------------------------------------------------------------------- 96" BUFFERS ----------------{{{
97" BUFFERS 97" Use <C-c> to quit the last buffer ----------------{{{
98"----------------------------------------------------------------------
99
100" Set to auto read when a file is changed from the outside
101" Unnamed buffer like CmdWindows should prevent this
102set autoread
103autocmd FocusGained,BufEnter .* checktime
104
105let g:quitVimWhenPressingCtrlC = 1 98let g:quitVimWhenPressingCtrlC = 1
106function! ToggleQuit() 99function! ToggleQuit()
107 let g:quitVimWhenPressingCtrlC = g:quitVimWhenPressingCtrlC ? 0 : 1 100 let g:quitVimWhenPressingCtrlC = g:quitVimWhenPressingCtrlC ? 0 : 1
@@ -111,8 +104,6 @@ endfunction
111 104
112nnoremap <leader><leader>gl :call ToggleQuit()<CR> 105nnoremap <leader><leader>gl :call ToggleQuit()<CR>
113 106
114" Simply exit when closing the last buffer
115
116function! Bye() 107function! Bye()
117 if len(getbufinfo({'buflisted': 1})) == 1 && len(getwininfo()) == 1 108 if len(getbufinfo({'buflisted': 1})) == 1 && len(getwininfo()) == 1
118 if g:quitVimWhenPressingCtrlC 109 if g:quitVimWhenPressingCtrlC
@@ -128,16 +119,15 @@ endfunction
128" Ctrl-C rules!!! 119" Ctrl-C rules!!!
129nnoremap <silent> <C-c> :call Bye()<CR> 120nnoremap <silent> <C-c> :call Bye()<CR>
130 121
122" }}}
123
131" Don't unload a buffer when no longer shown in a window 124" Don't unload a buffer when no longer shown in a window
132" This allows you open a new buffer and leaves current buffer modified 125" This allows you open a new buffer and leaves current buffer modified
133set hidden 126set hidden
134 127
135
136" Put these in an autocmd group, so that you can revert them with:
137" ":augroup vimStartup | au! | augroup END" 128" ":augroup vimStartup | au! | augroup END"
138augroup vimStartup 129augroup vimStartup
139 au! 130 au!
140
141 " When editing a file, always jump to the last known cursor position. 131 " When editing a file, always jump to the last known cursor position.
142 " Don't do it when the position is invalid, when inside an event handler 132 " Don't do it when the position is invalid, when inside an event handler
143 " (happens when dropping a file on gvim) and for a commit message 133 " (happens when dropping a file on gvim) and for a commit message
@@ -148,38 +138,9 @@ augroup vimStartup
148 \ | endif 138 \ | endif
149augroup END 139augroup END
150 140
151" Set filetype for beancount 141" }}}
152autocmd BufRead,BufNewFile *.bean call PrepareBean() 142" TABSIZE ----------------{{{
153function PrepareBean()
154 set filetype=beancount
155 silent !setsid fava ~/bean/main.bean &>/dev/null
156 autocmd VimLeave * silent !killall fava
157endfunction
158
159" Set filetype for index.html
160autocmd BufWrite *.html,*.js,*.css call ReloadServer()
161function ReloadServer()
162 silent !browser-sync reload &>/dev/null
163endfunction
164
165" Hide the first line of a file if editing password file
166" TODO a better way to determine a file is related to password-store, now use
167" files under /dev/shm as filter
168autocmd BufRead /dev/shm/*.txt call SetPasswordFile()
169function SetPasswordFile()
170 setlocal foldminlines=0
171 setlocal foldmethod=manual
172 function s:custom()
173 return "Password"
174 endfunction
175 setlocal foldtext=s:custom()
176 norm! ggzfl
177endfunction
178 143
179
180"----------------------------------------------------------------------
181" TABSIZE
182"----------------------------------------------------------------------
183set expandtab 144set expandtab
184set shiftwidth=2 145set shiftwidth=2
185set autoindent 146set autoindent
@@ -187,10 +148,9 @@ set tabstop=4
187set softtabstop=0 148set softtabstop=0
188set smartindent 149set smartindent
189 150
151" }}}
152" ENCODING_PREFERENCE ----------------{{{
190 153
191"----------------------------------------------------------------------
192" ENCODING_PREFERENCE
193"----------------------------------------------------------------------
194if has('multi_byte') 154if has('multi_byte')
195 set encoding=utf-8 155 set encoding=utf-8
196 set fileencoding=utf-8 156 set fileencoding=utf-8
@@ -198,18 +158,13 @@ if has('multi_byte')
198 set fileencodings=utf-8,big5,ucs-bom,gbk,gb18030,euc-jp,latin1 158 set fileencodings=utf-8,big5,ucs-bom,gbk,gb18030,euc-jp,latin1
199endif 159endif
200 160
201 161" }}}
202"---------------------------------------------------------------------- 162" FOLDING ----------------{{{
203" FOLDING
204"----------------------------------------------------------------------
205set foldenable " Allow fold 163set foldenable " Allow fold
206set foldmethod=indent " Fold contents by indent 164set foldmethod=indent " Fold contents by indent
207set foldlevel=2 " Expand all by default 165set foldlevel=2
208 166" }}}
209 167" BACKUP ----------------{{{
210"----------------------------------------------------------------------
211" BACKUP
212"----------------------------------------------------------------------
213 168
214" Allow backup 169" Allow backup
215set backup 170set backup
@@ -222,42 +177,13 @@ set backupdir=~/.vim/tmp
222 177
223" backup when write file 178" backup when write file
224set writebackup 179set writebackup
225 180" }}}
226"---------------------------------------------------------------------- 181" MISC ----------------{{{
227" MISC
228"----------------------------------------------------------------------
229
230" 顯示括號匹配的時間
231set matchtime=2
232
233" 顯示最後一行
234set display=lastline
235
236" 允許下方顯示目錄
237set wildmenu wildoptions=pum,fuzzy
238
239" Improve performance
240set lazyredraw
241
242" Format of error message
243set errorformat+=[%f:%l]\ ->\ %m,[%f:%l]:%m
244
245" 顯示分隔符號
246set listchars=tab:\|\ ,trail:.,extends:>,precedes:<
247
248" 遇到Unicode值大於255的文本,不必等到空格再折行
249set formatoptions+=m
250
251" 合併兩行中文時,不在中間加空格
252set formatoptions+=B
253 182
254" Use Unix way to add newline 183" Use Unix way to add newline
255set ffs=unix,dos,mac 184set ffs=unix,dos,mac
256 185
257
258"----------------------------------------------------------------------
259" Ignore these suffixes when find/complete 186" Ignore these suffixes when find/complete
260"----------------------------------------------------------------------
261set suffixes=.bak,~,.o,.h,.info,.swp,.obj,.pyc,.pyo,.egg-info,.class 187set suffixes=.bak,~,.o,.h,.info,.swp,.obj,.pyc,.pyo,.egg-info,.class
262 188
263set wildignore=*.o,*.obj,*~,*.exe,*.a,*.pdb,*.lib "stuff to ignore when tab completing 189set wildignore=*.o,*.obj,*~,*.exe,*.a,*.pdb,*.lib "stuff to ignore when tab completing
@@ -276,3 +202,4 @@ set wildignore+=*.ppt,*.pptx,*.docx,*.xlt,*.xls,*.xlsx,*.odt,*.wps
276set wildignore+=*.msi,*.crx,*.deb,*.vfd,*.apk,*.ipa,*.bin,*.msu 202set wildignore+=*.msi,*.crx,*.deb,*.vfd,*.apk,*.ipa,*.bin,*.msu
277set wildignore+=*.gba,*.sfc,*.078,*.nds,*.smd,*.smc 203set wildignore+=*.gba,*.sfc,*.078,*.nds,*.smd,*.smc
278set wildignore+=*.linux2,*.win32,*.darwin,*.freebsd,*.linux,*.android 204set wildignore+=*.linux2,*.win32,*.darwin,*.freebsd,*.linux,*.android
205" }}}