https://github.com/aben20807/my_vim
Using for recording my vim configuration
https://github.com/aben20807/my_vim
abbreviations brackets cygwin keymap vim vimrc
Last synced: 7 months ago
JSON representation
Using for recording my vim configuration
- Host: GitHub
- URL: https://github.com/aben20807/my_vim
- Owner: aben20807
- License: gpl-3.0
- Created: 2016-04-08T09:35:29.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-10-09T03:30:20.000Z (over 8 years ago)
- Last Synced: 2025-03-06T07:50:08.410Z (about 1 year ago)
- Topics: abbreviations, brackets, cygwin, keymap, vim, vimrc
- Language: Vim script
- Homepage: https://github.com/aben20807/aben20807.vim
- Size: 151 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Vim 配置整理
===
- 環境: Windows 10, Cygwin, Vim8
## Abbreviations (縮寫)
- 檔案: .vimrc, .vim/after/ftplugin/vim.vim, .vim/after/ftplugin/rust.vim
- 參考: https://superuser.com/questions/487603/abbreviations-override-in-comments-and-quoted-text
- 使用 CodeAbbr() 確認是否可以啟動縮寫功能,若為註解或字串不啟動
- 使用 Eatchar() 吃掉縮寫後的空白或換行字元
- e.g. 在.vim的檔案打 "function" 會自動補全
```vim
:iab function CodeAbbr("function", "function
\
\endfunction
\
\$li =Eatchar(\'\\m\\s\\\\r\')
\")
```

## Airline-theme (Airline主題)
- 檔案: .vim/bundle/vim-airline-themes/autoload/airline/themes/ouo.vim
- 修改了警告、錯誤區塊的顏色

## Alt key map (Alt鍵的mapping)
- 檔案: .keymap.vim
- 貼文: [106.07.19 vim map alt(meta) key](http://aben20807.blogspot.tw/2017/07/1060719-vim-map-altmeta-key.html)
- 設定後可用 `` 來map Alt+x, 其中x 為 a\~z, A\~Z, 0\~9, 還有一些特殊符號像.和/
## Author Information (添加作者資訊)
- 檔案: .author.vim, .vim/after/ftplugin/\*.vim
- 參考: http://www.gegugu.com/2016/02/11/17175.html
- 透過 `` 在文件開頭添加作者、檔案資訊
- 如果原本就有只會更新日期、檔名,沒有才會新增
- 請使用 AddTitle() 定義各檔案類型的資訊內容
- e.g 在 .vim/after/ftplugin/vim.vim 定義如下
```vim
function! AddTitle()
call append(0,"\" Author: Huang Po-Hsuan ")
call append(1,"\" Filename: ".expand("%:t"))
call append(2,"\" Last Modified: ".strftime("%Y-%m-%d %H:%M:%S"))
call append(3,"\" Vim: enc=utf-8")
call append(4,"")
endfunction
```

## Brackets (括號補全)
- 檔案: .brackets.vim
- 貼文: [106.07.01 vim 括號自動配對](http://aben20807.blogspot.tw/2017/07/1060701-vim.html)
## Colortheme (vim主題)
- 檔案: .vim/color/ouo.vim
- 對應的區塊大部分都在註解裡面了去找吧
## Comment (註解)
- 檔案: .comment.vim, .vim/after/ftplugin/\*.vim
- 請先在各個 ftplugin 的檔案中設定 call CommentFormat("")
- 使用 `` 來註解或取消註解
- 使用 visual mode 可一次操作多行

## Compile and Run (編譯執行)
- 檔案: .vimrc
- 參考: http://www.edbiji.com/doccenter/showdoc/24/nav/284.html
- 跳出之前會先關閉 ale
- 輸出現在時間避免搞混
- 也可以切換 markdown 預覽
```vim
map :call CompileAndRun()
" save -> close ALE -> print date -> [execute] run -> open ALE
function! CompileAndRun()
" save only when changed
execute "up"
execute "ALEDisable"
if &filetype == 'markdown'
" markdown preview
try
" Stop before starting and handle exception
execute "MarkdownPreviewStop"
catch /^Vim:E492:/
execute "MarkdownPreview"
endtry
else
" echo date time
silent execute "!echo"
silent execute "!echo -e '\033[31m ╔══════════════════════════════╗' "
silent execute "!echo -n ' ║ '"
silent execute "!echo -n `date`"
silent execute "!echo ' ║ '"
silent execute "!echo -e '\033[31m ╚══════════════════════════════╝' \033[37m"
" detect file type
if &filetype == 'rust'
" execute "!rustc % && time ./%< && rm %<"
execute "!time cargo run"
elseif &filetype == 'c'
execute "!gcc -std=c11 % -o /tmp/a.out && time /tmp/a.out"
elseif &filetype == 'cpp'
execute "!g++ -std=c++11 % -o /tmp/a.out && time /tmp/a.out"
elseif &filetype == 'java'
execute "!javac -encoding utf-8 %"
execute "!time java %<"
elseif &filetype == 'sh'
:!%
elseif &filetype == 'python'
execute "!time python3 %"
else
redraw
echohl WarningMsg
echo strftime(" ❖ 不支援 ❖ ")
echohl NONE
endif
endif
execute "ALEEnable"
endfunction
```


## Completion (補全插件)
- 檔案: .bundles.vim
- 插件: [maralla/completor.vim](https://github.com/maralla/completor.vim)
- 插件(forked): [aben20807/completor.vim](https://github.com/aben20807/completor.vim)
- 在insert mode按 `` 開關

## Indent highlight (縮排顯示插件)
- 檔案: .bundles.vim
- 插件: [Yggdroot/indentLine](https://github.com/Yggdroot/indentLine)
- 按 `` 開關顯示
```vim
Plugin 'Yggdroot/indentLine'
let g:indentLine_setColors = 0
let g:indentLine_char = '┊'
nnoremap :IndentLinesToggle
```
## Line number (行號)
- 檔案: .vimrc
- 混和版本: 目前行使用絕對行,其他行使用相對行
- 按 `` 開關顯示
```vim
nnoremap :set norelativenumber!:set nonumber!
:set number
:set relativenumber
```
## Markdown preview (Markdown預覽插件)
- 檔案: .bundles.vim
- 插件: [iamcco/markdown-preview.vim](https://github.com/iamcco/markdown-preview.vim)
- cygwin 內啟動 chrome 的設定如下
```vim
let g:mkdp_path_to_chrome = "cygstart /chrome.lnk"
let g:mkdp_auto_start = 0
```

## Remove trailing white space (移除空白)
- 檔案: .vimrc
- 來源: Vigil ``
- 自動在寫檔前把行末空白、文件末空行刪除
```vim
function RemoveTrailingWhitespace()
if &ft != "diff"
let b:curcol = col(".")
let b:curline = line(".")
silent! %s/\s\+$//
silent! %s/\(\s*\n\)\+\%$//
call cursor(b:curline, b:curcol)
endif
endfunction
autocmd BufWritePre * call RemoveTrailingWhitespace()
```
## Surround (加上括號)
- 檔案: .surround.vim
- 如果輸入字元不支援會顯示 ❖ 不支援字元 ❖
- `x`: 在光標所在的單字左右加入x, 其中x 為 ' , " , \( , \[ , \{ , <
- `x`: 在 visual mode 則在選取的左右加入
- `nx`: 加在包含光標以後 n 個單字, n 為整數
- `x`: 若有包在 x 裡面則刪除字元 x
- `xy`: 用 y 取代 x
## Terminal (內部終端機插件)
- 檔案: .bundles.vim
- 插件: [wkentaro/conque.vim](https://github.com/wkentaro/conque.vim)
- 按 `` 在分屏開啟終端機
```vim
nnoremap :ConqueTermVSplit bash
```

## Time (顯示時間)
- 檔案: .keymap.vim
- 在 normal mode 按 `` 就會顯示現在時間
```vim
function! DateAndTime()
redraw
echohl WarningMsg
echo strftime(" ❖ 現在時間 %H:%M ❖ ")
echohl NONE
endfunction
nnoremap :call DateAndTime()
```
