码迷,mamicode.com
首页 > 系统相关 > 详细

vimrc同步文档

时间:2018-11-04 12:38:48      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:ack   only   arc   conf   删除   rtc   write   def   cpp   

目录

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


vimrc同步文档

标签:ack   only   arc   conf   删除   rtc   write   def   cpp   

原文地址:https://www.cnblogs.com/ims-/p/9903219.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!