1. 程式人生 > >vimrc同步文件

vimrc同步文件

目錄

18.04 content

if has("syntax")  
syntax on  
endif  
" Source a global configuration file if available  
if filereadable("/etc/vim/vimrc.local")  
source /etc/vim/vimrc.local  
endif  
 
set showcmd             " Show (partial) command in status line.  
set showmatch           " Show matching brackets.  
"set ignorecase     " Do case insensitive matching  
"set smartcase      " Do smart case matching  
"set incsearch      " Incremental search  
set autowrite       " Automatically save before commands like :next and :make  
set hidden      " Hide buffers when they are abandoned  
set mouse=a     " Enable mouse usage (all modes) 啟用滑鼠方便翻頁,移動游標  

set nu           "show line number  
set nobackup        "no backup  
"set cursorline       "high this line  
set ruler            "show cursor site in right below   
autocmd InsertLeave * se nocul  " 用淺色高亮當前行  
set tabstop=4      " 統一縮排為4  
set shiftwidth=4  

set pastetoggle=<F6> "插入模式貼上不會自動縮排避免混亂  
set autoindent    "自動縮排  
set cindent  

"set foldenable " 開始摺疊  
"set foldmethod=syntax " 設定語法摺疊  
set foldcolumn=0 " 設定摺疊區域的寬度  
setlocal foldlevel=1 " 設定摺疊層數  
set foldopen=all     "游標到達摺疊快時,自動開啟  
"set foldclose=all    " 離開程式碼塊後,自動摺疊  

" 用空格鍵來開關摺疊  
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>  

set autoread  " 設定當檔案被改動時自動載入  

set completeopt=longest,menu  
set completeopt=preview,menu "程式碼補全   
set nocompatible "取消vi 相容模式  

"start----- 自動補全  -----------------
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>  
:inoremap { {<CR>}<ESC>O
:inoremap } <c-r>=ClosePair('}')<CR>  
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>  
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char  
   return "\<Right>"
else  
   return a:char
endif
endfunction
"end------------------------------------------
  

"----- 開啟檔案型別檢測-----------------
filetype plugin indent on
autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr>  
  
"start---------- definition  SetTitle() ------------------------------------ 
  
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java  exec ":call SetTitle()"  
func SetTitle()   
    if &filetype == 'sh'   
        call setline(1,"\#########################################################################")  
        call append(line("."), "\# File Name: ".expand("%"))  
        call append(line(".")+1, "\# Author: ims")  
        call append(line(".")+2, "\# Created Time: ".strftime("%c"))  
        call append(line(".")+3, "\#########################################################################")  
        call append(line(".")+4, "\#!/bin/bash")  
        call append(line(".")+5, "")  
    else  
        call setline(1, "/*************************************************************************")  
        call append(line("."), "    > File Name: ".expand("%"))  
        call append(line(".")+1, "    > Author: ims")  
        call append(line(".")+2, "    > Created Time: ".strftime("%c"))  
        call append(line(".")+3, " ************************************************************************/")  
        call append(line(".")+4, "")  
    endif  

    if &filetype == 'cpp'  
        call append(line(".")+5, "#include<iostream>")  
        call append(line(".")+6, "using namespace std;")  
        call append(line(".")+7, "")  
        call append(line(".")+8, "int main()")  
        call append(line(".")+9, "{")  
        call append(line(".")+10, "\t")  
        call append(line(".")+11, "\treturn 0;")  
        call append(line(".")+12, "}")  
    endif

    if &filetype == 'c'
        call append(line(".")+5, "#include<stdio.h>")  
        call append(line(".")+6, "")  
        call append(line(".")+7, "")  
        call append(line(".")+8, "int main()")  
        call append(line(".")+9, "{")  
        call append(line(".")+10, "\t")  
        call append(line(".")+11, "\treturn 0;")  
        call append(line(".")+12, "}")  
    endif

    normal 12G"
endfunc
  
"end----------- SetTitle() --------------------------------

"start------- set title of file of .py ----------
autocmd BufNewFile *.py  exec ":call SetTitleOfFilePy()"  
func SetTitleOfFilePy()   
    call setline(1,"\#! /usr/bin/python3.5")  
    call append(line("."), "\# -*- coding: UTF-8 -*-")  
    call append(line(".")+1, "\####################################################################")  
    call append(line(".")+2, "\# File Name: ".expand("%"))  
    call append(line(".")+3, "\# Author: ims")  
    call append(line(".")+4, "\# Created Time: ".strftime("%c"))  
    call append(line(".")+5, "\####################################################################")  
    call append(line(".")+6, "")  
    call append(line(".")+7, "")  
    normal 9G  
endfunc  
"end--------------------------------------------
      

 
"start------執行.c/.cpp/.java/.sh檔案-----------------

map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
    exec "w"
    if &filetype == 'c'  
        exec "!g++ % -o %<"  
        exec "! ./%<"  
    elseif &filetype == 'cpp'
        exec "!g++ % -o %<"
        exec "! ./%<"
    elseif &filetype == 'java'   :
        exec "!javac %"   
        exec "!java %<"  
    elseif &filetype == 'sh'  
        exec "!chmod +x %"   
        :!./%  
    endif  
endfunc 

"notice: csdn複製後<CR>  後面會有2個空格,要刪除,不然,執行後直接回到編輯介面 
"end------------------------------------------

"start------執行.py 檔案 <F4> ----------------

map <F4> :call RunPy()<CR>  
func! RunPy()  
    exec "w"  
    exec "!chmod +x %"  
    :!./%  
endfunc
"end-----------------------------------

"start------------除錯C/C++ 繫結<F8>---------------
    map <F8> :call Rungdb()<CR>  
    func! Rungdb()  
        exec "w"  
        exec "!g++ % -g -Wall -o %<"  
        exec "!gdb ./%<"  
    endfunc  
"end---------------------------------------------------

let Tlist_Show_One_File=1 

let Tlist_Exit_OnlyWindow=1
" Open and close all the three plugins on the same time 
nmap <F8>   :TrinityToggleAll<CR> 

" Open and close the srcexpl.vim separately 
nmap <F9>   :TrinityToggleSourceExplorer<CR> 

" Open and close the taglist.vim separately 
nmap <F10>  :TrinityToggleTagList<CR> 

" Open and close the NERD_tree.vim separately 
nmap <F11>  :TrinityToggleNERDTree<CR> 

redhat