From 76922c395db1d9745e2a47f8c0584545958a3fee Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Wed, 22 May 2024 13:57:46 +0800 Subject: Update --- vim/init/basic.vim | 279 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 279 insertions(+) create mode 100644 vim/init/basic.vim (limited to 'vim/init/basic.vim') 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 @@ +"====================================================================== +" +" init-basic.vim - Need vim tiny compatible +" +" Used for general usecases. No keymap and personal preference +" +" Use '*' to search for: +" VIM_BEHAVIOR +" VISUAL +" EDIT +" JUMP +" SEARCH +" SYNTAX_HIGHLIGHT +" BUFFERS +" ENCODING_PREFERENCE +" FOLDING +" MISC +"====================================================================== + + +"---------------------------------------------------------------------- +" VIM_BEHAVIOR +"---------------------------------------------------------------------- + +let mapleader = "," " Always use comma as leader key +set nocompatible " Disable vi compatible, today is 20XX +set autochdir " Automatically cd to current file +set path=.,** " Allow :find with completion +set mouse= " Disable mouse selection +set winaltkeys=no " Allow alt key for mapping +set cursorline + +" Turn persistent undo on +" means that you can undo even when you close a buffer/VIM +set undofile +set undodir=~/.vim/.undodir +set conceallevel=1 + +" Apply plugin and indent by filetype +filetype plugin indent on + + +"---------------------------------------------------------------------- +" VISUAL +"---------------------------------------------------------------------- + +colorscheme desert " I like desert! +" In most of the cases, it is overrides by lightline.vim +set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c +set showmatch " Show pairing brackets + +set number relativenumber " Use relativenumber +set wrap " Disable wrap by default +set scrolloff=3 " Leave some buffer when scrolling down +set ruler " Show cursor position +set laststatus=2 " Always show the status line +set guicursor=n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20 + + +"---------------------------------------------------------------------- +" EDIT +"---------------------------------------------------------------------- + +set backspace=eol,start,indent " Set Backspace behaviors +set autoindent " If current line has indent, automatically set indent for next line +set cindent +set ttimeout +set ttimeoutlen=50 +set updatetime=250 + +imap l +" Change IM to US when exit to Normal mode +autocmd InsertLeave * :silent !fcitx-remote -c &>/dev/null || true + + +"---------------------------------------------------------------------- +" JUMP +"---------------------------------------------------------------------- + +set isfname=@,48-57,/,.,-,_,+,,,#,$,%,~ " This affects filename recognition for gf (go to file) +set suffixesadd=.md " Enable reference markdown file without extension + + +"---------------------------------------------------------------------- +" SEARCH +"---------------------------------------------------------------------- +set ignorecase " Search case without case sensation +set smartcase +set hlsearch " Hilight all matched texts +set incsearch " Show matched strings when typing + + +"---------------------------------------------------------------------- +" SYNTAX_HIGHLIGHT +"---------------------------------------------------------------------- + +syntax enable + +function! GetHighlightGroupName() + let l:syntaxID = synID(line('.'), col('.'), 1) + let l:groupName = synIDattr(l:syntaxID, 'name') + echo "Highlight Group Name: " . l:groupName +endfunction + +" Defualt highlight for matched parenthesis is so weird in many colorscheme +" Why the background color is lighter than my caret !? +highlight MatchParen ctermfg=NONE ctermbg=darkgrey cterm=NONE +highlight LuaParen ctermfg=NONE ctermbg=darkgrey cterm=NONE + +" Show trailing spaces +highlight ExtraWhitespace ctermbg=red guibg=red +match ExtraWhitespace /\s\+$/ + +" Persist visualized lines +" define line highlight color +highlight MultiLineHighlight ctermbg=LightYellow guibg=LightYellow ctermfg=Black guifg=Black +" highlight the current line +nnoremap h :call matchadd('MultiLineHighlight', '\%'.line('.').'l') +" clear all the highlighted lines +nnoremap H :call clearmatches() + + +"---------------------------------------------------------------------- +" BUFFERS +"---------------------------------------------------------------------- + +" Set to auto read when a file is changed from the outside +" Unnamed buffer like CmdWindows should prevent this +set autoread +autocmd FocusGained,BufEnter .* checktime + +let g:quitVimWhenPressingCtrlC = 1 +function! ToggleQuit() + let g:quitVimWhenPressingCtrlC = g:quitVimWhenPressingCtrlC ? 0 : 1 + let message = g:quitVimWhenPressingCtrlC ? "Unlock" : "Lock" + echo message +endfunction + +nnoremap gl :call ToggleQuit() + +" Simply exit when closing the last buffer +function! Bye() + " Delete current buffer if working on special filetype + let specialFileTypes = ['help', 'netrw', 'vim-plug', 'nerdtree'] + if index(specialFileTypes, &filetype) != -1 + :bdelete + " Delete current buffer if more than one buffers + elseif len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) != 1 + :bdelete + elseif g:quitVimWhenPressingCtrlC + " Otherwise, quit vim + :silent! qall + else + :echo "Press gl to allow quit with " + endif +endfunction + +" Ctrl-C rules!!! +nnoremap :call Bye() + +" Don't unload a buffer when no longer shown in a window +" This allows you open a new buffer and leaves current buffer modified +set hidden + + +" Put these in an autocmd group, so that you can revert them with: +" ":augroup vimStartup | au! | augroup END" +augroup vimStartup +au! + +" When editing a file, always jump to the last known cursor position. +" Don't do it when the position is invalid, when inside an event handler +" (happens when dropping a file on gvim) and for a commit message +" (it's likely a different one than last time). +autocmd BufReadPost * + \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit' + \ | exe "normal! g`\"" + \ | endif +augroup END + +" Set filetype for beancount +autocmd BufRead,BufNewFile *.bean call PrepareBean() +function PrepareBean() + set filetype=beancount + silent !setsid fava ~/bean/main.bean &>/dev/null + autocmd VimLeave * silent !killall fava +endfunction + +" Set filetype for index.html +autocmd BufWrite *.html,*.js,*.css call ReloadServer() +function ReloadServer() + silent !browser-sync reload &>/dev/null +endfunction + +" Hide the first line of a file if editing password file +" TODO a better way to determine a file is related to password-store, now use +" files under /dev/shm as filter +autocmd BufRead /dev/shm/*.txt call SetPasswordFile() +function SetPasswordFile() + setlocal foldminlines=0 + setlocal foldmethod=manual + setlocal foldtext= + norm! ggzfl +endfunction + + + +"---------------------------------------------------------------------- +" ENCODING_PREFERENCE +"---------------------------------------------------------------------- +if has('multi_byte') + set encoding=utf-8 + set fileencoding=utf-8 + " Try encodings by this order + set fileencodings=utf-8,big5,ucs-bom,gbk,gb18030,euc-jp,latin1 +endif + + +"---------------------------------------------------------------------- +" FOLDING +"---------------------------------------------------------------------- +set foldenable " Allow fold +set foldmethod=indent " Fold contents by indent +set foldlevel=99 " Expand all by default + + +"---------------------------------------------------------------------- +" MISC +"---------------------------------------------------------------------- + +" 顯示括號匹配的時間 +set matchtime=2 + +" 顯示最後一行 +set display=lastline + +" 允許下方顯示目錄 +set wildmenu + +" Improve performance +set lazyredraw + +" Format of error message +set errorformat+=[%f:%l]\ ->\ %m,[%f:%l]:%m + +" 顯示分隔符號 +set listchars=tab:\|\ ,trail:.,extends:>,precedes:< + +" 遇到Unicode值大於255的文本,不必等到空格再折行 +set formatoptions+=m + +" 合併兩行中文時,不在中間加空格 +set formatoptions+=B + +" Use Unix way to add newline +set ffs=unix,dos,mac + + +"---------------------------------------------------------------------- +" Ignore these suffixes when find/complete +"---------------------------------------------------------------------- +set suffixes=.bak,~,.o,.h,.info,.swp,.obj,.pyc,.pyo,.egg-info,.class + +set wildignore=*.o,*.obj,*~,*.exe,*.a,*.pdb,*.lib "stuff to ignore when tab completing +set wildignore+=*.so,*.dll,*.swp,*.egg,*.jar,*.class,*.pyc,*.pyo,*.bin,*.dex +set wildignore+=*.zip,*.7z,*.rar,*.gz,*.tar,*.gzip,*.bz2,*.tgz,*.xz " MacOSX/Linux +set wildignore+=*DS_Store*,*.ipch +set wildignore+=*.gem +set wildignore+=*.png,*.jpg,*.gif,*.bmp,*.tga,*.pcx,*.ppm,*.img,*.iso +set wildignore+=*.so,*.swp,*.zip,*/.Trash/**,*.pdf,*.dmg,*/.rbenv/** +set wildignore+=*/.nx/**,*.app,*.git,.git +set wildignore+=*.wav,*.mp3,*.ogg,*.pcm +set wildignore+=*.mht,*.suo,*.sdf,*.jnlp +set wildignore+=*.chm,*.epub,*.pdf,*.mobi,*.ttf +set wildignore+=*.mp4,*.avi,*.flv,*.mov,*.mkv,*.swf,*.swc +set wildignore+=*.ppt,*.pptx,*.docx,*.xlt,*.xls,*.xlsx,*.odt,*.wps +set wildignore+=*.msi,*.crx,*.deb,*.vfd,*.apk,*.ipa,*.bin,*.msu +set wildignore+=*.gba,*.sfc,*.078,*.nds,*.smd,*.smc +set wildignore+=*.linux2,*.win32,*.darwin,*.freebsd,*.linux,*.android -- cgit v1.2.3-70-g09d2