aben20807 / my_vim

Using for recording my vim configuration
https://github.com/aben20807/aben20807.vim
GNU General Public License v3.0
1 stars 0 forks source link
abbreviations brackets cygwin keymap vim vimrc

Vim 配置整理

Abbreviations (縮寫)

:iab <buffer> <expr> function CodeAbbr("function", "function
    \<CR>
    \<CR>endfunction
    \<UP><TAB>
    \<UP><ESC>$li <C-R>=Eatchar(\'\\m\\s\\<bar>\\r\')<CR>
    \")

Demo

Airline-theme (Airline主題)

Demo

Alt key map (Alt鍵的mapping)

Author Information (添加作者資訊)

function! AddTitle()
    call append(0,"\" Author: Huang Po-Hsuan <aben20807@gmail.com>")
    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

Demo

Brackets (括號補全)

Colortheme (vim主題)

Comment (註解)

Demo

Compile and Run (編譯執行)

map <F5> :call CompileAndRun()<CR>
" 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

Demo Demo

Completion (補全插件)

Demo

Indent highlight (縮排顯示插件)

Plugin 'Yggdroot/indentLine'
let g:indentLine_setColors = 0
let g:indentLine_char = '┊'
nnoremap <F3> :IndentLinesToggle<CR>

Line number (行號)

nnoremap <F2> :set norelativenumber!<CR>:set nonumber!<CR>
:set number
:set relativenumber

Markdown preview (Markdown預覽插件)

let g:mkdp_path_to_chrome = "cygstart /chrome.lnk"
let g:mkdp_auto_start = 0

Demo

Remove trailing white space (移除空白)

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 (加上括號)

Terminal (內部終端機插件)

nnoremap <C-t> :ConqueTermVSplit bash<CR>

Demo

Time (顯示時間)

function! DateAndTime()
    redraw
    echohl WarningMsg
        echo strftime("   ❖  現在時間 %H:%M ❖ ")
    echohl NONE
endfunction
nnoremap <M-t> :call DateAndTime()<CR>

Demo