aboutsummaryrefslogtreecommitdiffhomepage
path: root/vim/init/basic.vim
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-07-28 21:01:19 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-07-28 21:01:19 +0800
commit9b564fcfeec95ed965252ef4acc6ee42702ded88 (patch)
tree6e3eec076baf803724879be796cf5a5324cd8fb0 /vim/init/basic.vim
parent0e010ae8e8686e3a374a27885391f99d3ea315cc (diff)
Update
Diffstat (limited to 'vim/init/basic.vim')
-rw-r--r--vim/init/basic.vim133
1 files changed, 96 insertions, 37 deletions
diff --git a/vim/init/basic.vim b/vim/init/basic.vim
index 2394045..e18d51f 100644
--- a/vim/init/basic.vim
+++ b/vim/init/basic.vim
@@ -4,7 +4,7 @@
4" Used for general usecases. No keymap and personal preference 4" Used for general usecases. No keymap and personal preference
5"====================================================================== 5"======================================================================
6 6
7" Vimscript file settings ---------------------- {{{ 7" For Vimscript {{{
8 8
9" Usage: type --- for foldmark 9" Usage: type --- for foldmark
10augroup filetype_vim 10augroup filetype_vim
@@ -14,13 +14,63 @@ augroup filetype_vim
14augroup END 14augroup END
15 15
16" }}} 16" }}}
17" GERERNAL ----------------{{{ 17" For Buffer and Tab {{{
18augroup tabinfo
19 au!
20 let g:tab_group = {}
21 " BufEnter {{{
22 function! AddBufToTabGroup(tab_group)
23 let l:tabId = tabpagenr()
24 let l:bufnr = bufnr()
25
26 if has_key(a:tab_group, l:tabId)
27 for v in a:tab_group[l:tabId]
28 if v == l:bufnr
29 return
30 endif
31 endfor
32 call add(a:tab_group[l:tabId], l:bufnr)
33 else
34 let a:tab_group[l:tabId] = [l:bufnr]
35 endif
36
37 endfunc
38 autocmd BufWinEnter * if &buflisted | call AddBufToTabGroup(g:tab_group) | endif
39 " }}}
40 " BufDelete {{{
41 function! RemoveBufFromTabGroup(tab_group)
42 let l:tabId = tabpagenr()
43
44 if has_key(a:tab_group, l:tabId)
45 let l:new_tab_group = {}
46
47 for [k, tab_list] in items(a:tab_group)
48 let l:list = []
49 for buf in tab_list
50 if buflisted(buf) > 0 && buf != expand('<abuf>')
51 call add(l:list, buf)
52 end
53 endfor
54 if !empty(l:list)
55 let l:new_tab_group[k] = l:list
56 endif
57 endfor
58 let g:tab_group = l:new_tab_group
59
60 endif
61
62 endfunc
63 autocmd BufDelete * call RemoveBufFromTabGroup(g:tab_group)
64 "}}}
65augroup END
66"}}}
67" GERERNAL {{{
18 68
19let mapleader = "," " Always use comma as leader key 69let mapleader = "," " Always use comma as leader key
20set nocompatible " Disable vi compatible, today is 20XX 70set nocompatible " Disable vi compatible, today is 20XX
21set path=.,** " Allow :find with completion 71set path=.,** " Allow :find with completion
22set mouse= " Disable mouse selection 72set mouse= " Disable mouse selection
23set winaltkeys=no " Allow alt key for mapping 73set winaltkeys=no " Allow alt key for mapping
24 74
25" Turn persistent undo on 75" Turn persistent undo on
26" means that you can undo even when you close a buffer/VIM 76" means that you can undo even when you close a buffer/VIM
@@ -43,22 +93,20 @@ set spellfile="/tmp/spell"
43sign define piet text=>> texthl=Search 93sign define piet text=>> texthl=Search
44 94
45" }}} 95" }}}
46" VISUAL ----------------{{{ 96" VISUAL {{{
47 97
48" colorscheme desert 98" colorscheme desert
49 99
50" Editing Area 100" Editing Area
51set wrap " enable wrap by default 101set wrap " enable wrap by default
52set scrolloff=3 " Leave some buffer when scrolling down 102set scrolloff=3 " Leave some buffer when scrolling down
53set showmatch " Show pairing brackets 103set showmatch " Show pairing brackets
54set display=lastline 104set display=lastline
55set lazyredraw 105set lazyredraw
56set formatoptions+=m " 遇到Unicode值大於255的文本,不必等到空格再折行
57set formatoptions+=B " 合併兩行中文時,不在中間加空格
58set whichwrap=b,s 106set whichwrap=b,s
59 107
60" Side column 108" Side column
61set signcolumn=yes number relativenumber 109set number relativenumber
62 110
63" Cursor 111" Cursor
64set cursorline 112set cursorline
@@ -67,30 +115,40 @@ set matchtime=2
67 115
68" In most of the cases, it is overrides by lightline.vim 116" In most of the cases, it is overrides by lightline.vim
69set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c 117set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c
70set laststatus=2 " Always show the status line 118set laststatus=2 " Always show the status line
71set ruler " Show cursor position 119set ruler " Show cursor position
72set wildmenu wildoptions=pum,fuzzy 120set wildmenu wildoptions=pum,fuzzy
73 121
74" Format of error message 122" Format of error message
75set errorformat+=[%f:%l]\ ->\ %m,[%f:%l]:%m 123set errorformat+=[%f:%l]\ ->\ %m,[%f:%l]:%m
76 124
125" Direction for new window
126set splitright
127
77" }}} 128" }}}
78" EDIT ----------------{{{ 129" EDIT {{{
130
131" overrides ftplugin in runtimepath
132" Don't wrap line when typing CJK characters
133" Don't add spaces for CJK
134" Don't add comment at next line
135autocmd Filetype * set fo+=mB fo-=cro
79 136
80set backspace=eol,start,indent " Set Backspace behaviors
81set autoindent smartindent
82set shiftwidth=2 137set shiftwidth=2
138set autoindent smartindent
83set cindent 139set cindent
84set ttimeout 140set ttimeout
85set timeoutlen=500 141set timeoutlen=500
142
143set backspace=eol,start,indent " Set Backspace behaviors
144
86" set updatetime=4000 145" set updatetime=4000
87" autocmd CursorHold * normal! m' 146" autocmd CursorHold * normal! m'
88 147
89" TAB and special Chars ----------------{{{ 148" TAB and special Chars {{{
90 149
91set tabstop=8 150set tabstop=8 softtabstop=8
92set expandtab 151set expandtab
93set softtabstop=-1
94 152
95" Invisible chars 153" Invisible chars
96set nolist 154set nolist
@@ -99,23 +157,23 @@ set listchars=tab:»·,extends:>,precedes:<
99" }}} 157" }}}
100 158
101" }}} 159" }}}
102" JUMP to anoterh file ----------------{{{ 160" JUMP to anoterh file {{{
103 161
104set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~ " This affects filename recognition for gf (go to file) 162set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~ " This affects filename recognition for gf (go to file)
105set suffixesadd=.md " Enable reference markdown file without extension 163set suffixesadd=.md " Enable reference markdown file without extension
106 164
107" }}} 165" }}}
108" SEARCH ----------------{{{ 166" SEARCH {{{
109 167
110set ignorecase " Search case without case sensation 168set ignorecase " Search case without case sensation
111set smartcase 169set smartcase
112set hlsearch " Hilight all matched texts 170set hlsearch " Highlight all matched texts
113set incsearch " Show matched strings when typing 171set incsearch " Show matched strings when typing
114 172
115" }}} 173" }}}
116" BUFFERS ----------------{{{ 174" BUFFERS {{{
117 175
118" Go to last cursor position ----------------{{{ 176" Go to last cursor position {{{
119augroup vimStartup 177augroup vimStartup
120 au! 178 au!
121 " When editing a file, always jump to the last known cursor position. 179 " When editing a file, always jump to the last known cursor position.
@@ -131,21 +189,22 @@ augroup END
131" }}} 189" }}}
132 190
133" }}} 191" }}}
134" FOLD ----------------{{{ 192" FOLD {{{
193
135set foldenable " Allow fold 194set foldenable " Allow fold
136set foldmethod=indent " Fold contents by indent 195set foldmethod=indent " Fold contents by indent
137set foldlevel=2 196set foldlevel=2
138set fillchars+=foldopen:▽,foldsep:│,foldclose:▶ 197set fillchars+=foldopen:▽,foldsep:│,foldclose:▶
139let g:defaut_foldcolumn = "" 198let g:defaut_foldcolumn = ""
140if has('nvim') 199if has('nvim')
141 let g:defaut_foldcolumn = "auto:5" 200 let g:defaut_foldcolumn = "auto:3"
142else 201else
143 let g:defaut_foldcolumn = 5 202 let g:defaut_foldcolumn = 3
144endif 203endif
145let &foldcolumn = g:defaut_foldcolumn 204let &foldcolumn = g:defaut_foldcolumn
146 205
147" }}} 206" }}}
148" ENCODING_PREFERENCE ----------------{{{ 207" ENCODING_PREFERENCE {{{
149 208
150if has('multi_byte') 209if has('multi_byte')
151 set encoding=utf-8 210 set encoding=utf-8
@@ -155,7 +214,7 @@ if has('multi_byte')
155endif 214endif
156 215
157" }}} 216" }}}
158" BACKUP ----------------{{{ 217" BACKUP {{{
159 218
160" Allow backup 219" Allow backup
161set backup 220set backup
@@ -170,7 +229,7 @@ set backupdir=~/.vim/tmp
170set writebackup 229set writebackup
171 230
172" }}} 231" }}}
173" HIGHLIGHT ----------------{{{ 232" HIGHLIGHT {{{
174 233
175syntax enable 234syntax enable
176set conceallevel=1 235set conceallevel=1
@@ -185,7 +244,7 @@ highlight ExtraWhitespace ctermbg=red guibg=red
185match ExtraWhitespace /\s\+$/ 244match ExtraWhitespace /\s\+$/
186 245
187" }}} 246" }}}
188" MISC ----------------{{{ 247" MISC {{{
189 248
190" Use Unix way to add newline 249" Use Unix way to add newline
191set ffs=unix,dos,mac 250set ffs=unix,dos,mac