vim 真是上瘾啊

时间:2021-09-18 10:30:57

再次更新

.vimrc

" leader
let mapleader = ","
nnoremap <leader>ev :vsplit ~/.vimrc<cr>
nnoremap <leader>sv :source ~/.vimrc<cr>

" syntax
syntax on

" tablewidth
set tabstop=8
set softtabstop=8
set shiftwidth=8

" indent
set autoindent
set cindent

" show line number
set nu

" hilight search results
set hlsearch

" color scheme
set t_Co=256
colo molokai
" hilight function name
autocmd BufNewFile,BufRead * :syntax match cfunctions "\<[a-zA-Z_][a-zA-Z_0-9]*\>[^()]*)("me=e-2
autocmd BufNewFile,BufRead * :syntax match cfunctions "\<[a-zA-Z_][a-zA-Z_0-9]*\>\s*("me=e-1
hi cfunctions ctermfg=81
hi Type ctermfg=118 cterm=none
hi Structure ctermfg=118 cterm=none
hi Macro ctermfg=161 cterm=bold
hi PreCondit ctermfg=161 cterm=bold

set cursorline

" abbreviate
iab main #include <stdio.h>
\<CR>
\<CR>int main(int argc, const char *argv[])
\<CR>{
\<CR>return 0; }
iab p printf("%d\n", );

" auto compile
autocmd BufWritePost *.c :call Compile()
"map <C-M> :call Compile()
func! Compile()
    if &filetype == 'c'
        exec "w"
        exec "! clear; rm -f %<; gcc % -o %< -g -Wall -lm -lpthread; ./%<;"
    endif

"    exec "w"
"    exec "! clear; rm -f %<; echo [Assemble %]; as % -o %<.o; echo [Link %<.o]; ld %<.o -o %<; echo [Run %<]; ./%<;"
"    exec "w"
"    exec "! clear; rm -f %<; echo [Assemble %]; nasm -f elf hello.s; echo [Link %<.o]; ld -s -o %< %<.o; echo [Run %<]; ./%<;"
endfunc

" Man
set laststatus=0
source $VIMRUNTIME/ftplugin/man.vim
nnoremap K :Man <C-R><C-W><cr>:res<cr>:set nonu<cr>:<Esc>
nnoremap 1K :Man 1 <C-R><C-W><cr>:res<cr>:set nonu<cr>:<Esc>
nnoremap 2K :Man 2 <C-R><C-W><cr>:res<cr>:set nonu<cr>:<Esc>
nnoremap 3K :Man 3 <C-R><C-W><cr>:res<cr>:set nonu<cr>:<Esc>
nnoremap 4K :Man 4 <C-R><C-W><cr>:res<cr>:set nonu<cr>:<Esc>
nnoremap 5K :Man 5 <C-R><C-W><cr>:res<cr>:set nonu<cr>:<Esc>
nnoremap 6K :Man 6 <C-R><C-W><cr>:res<cr>:set nonu<cr>:<Esc>
nnoremap 7K :Man 7 <C-R><C-W><cr>:res<cr>:set nonu<cr>:<Esc>
nnoremap 8K :Man 8 <C-R><C-W><cr>:res<cr>:set nonu<cr>:<Esc>
nnoremap 9K :Man 9 <C-R><C-W><cr>:res<cr>:set nonu<cr>:<Esc>

" Rename tabs to show tab number.
" (Based on http://*.com/questions/5927952/whats-implementation-of-vims-default-tabline-function)
if exists("+showtabline")
    function! MyTabLine()
        let s = ''
        let wn = ''
        let t = tabpagenr()
        let i = 1
        while i <= tabpagenr('$')
            let buflist = tabpagebuflist(i)
            let winnr = tabpagewinnr(i)
            let s .= '%' . i . 'T'
            let s .= (i == t ? '%1*' : '%2*')
            let s .= ' '
            let wn = tabpagewinnr(i,'$')

let s .= '%#TabNum#'
            let s .= i
            " let s .= '%*'
            let s .= (i == t ? '%#TabLineSel#' : '%#TabLine#')
            let bufnr = buflist[winnr - 1]
            let file = bufname(bufnr)
            let buftype = getbufvar(bufnr, 'buftype')
            if buftype == 'nofile'
            if file =~ '\/.'
                let file = substitute(file, '.*\/\ze.', '', '')
            endif
            else
                let file = fnamemodify(file, ':p:t')
            endif
            if file == ''
                let file = '[No Name]'
            endif
            let s .= ' ' . file . ' '
            let i = i + 1
        endwhile

let s .= '%T%#TabLineFill#%='
        let s .= (tabpagenr('$') > 1 ? '%999XX' : 'X')
        return s
    endfunction

set stal=2
    set tabline=%!MyTabLine()
    highlight link TabNum Special
endif

.bashrc

# switch caps lock with esc
xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape'
#sudo loadkeys .swap_esc_capslock

# aliases
alias ll='ls -l'
#alias dict='/home/akaedu/c/Jul29/stardict/dict'
alias dict='sdcv'
alias lynx='lynx -accept_all_cookies'
alias vi='vim'

# show time in en_US
export LC_TIME='en_US.UTF-8'

# single vim
export VIM_SINGLE=`which vim`
export SUPPORTS=`$VIM_SINGLE --version | grep "+clientserver"`
if [ "$SUPPORTS" != '' ];then
alias vim="single-vim"
fi
function single-vim(){
    filename=$1
    filenameWithoutDouble=`echo $filename | sed -rn "s/(.*):$/\1/p"`
    if [ ! -f "$filename" ] && [ -f "$filenameWithoutDouble" ]; then
        filename=$filenameWithoutDouble
    fi
    pid=`ps ax | grep -v grep | grep vim$$`
    jobid=`jobs | grep vim | awk -F ] '{print $1}' | awk -F [ '{print $2}'`
    if [ -z "$pid" ]; then
        $VIM_SINGLE --servername vim$$ $filename
    else
        $VIM_SINGLE --servername vim$$ --remote-tab $filename
        $VIM_SINGLE --servername vim$$ --remote-send ':tabp<CR>:tabn<CR>'

fg $jobid
    fi
}