vim 推荐配置

主要是针对vim IDE的一些配置,欢迎补充!

"设置字符集
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8

"把当前行的对起格式应用到下一行
set autoindent

"将换行自动缩进设置成4个空格;
set shiftwidth=4

"表示一个tab键相当于4个空格键
set tabstop=4

"自动填充4个空格为tab
set expandtab

"显示行号
set nu

"启用标记折叠。所有文本将按照特定标记(默认为{{{和}}})自动折叠。
set foldmethod=marker

"粘贴不缩进的方法:set paste
set paste

"从不备份
set nobackup

"禁止生成临时文件
set noswapfile

"确认VI
set confirm

"关闭鼠标
set mouse -=a

"显 示 TAB 键
"set list

"设置文件格式
set fileformat=unix

"代码自动完成(ctrl-x ctrl-o)
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascrīpt set omnifunc=javascrīptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete
filetype plugin on



"文件头注释生成,"映射F2快捷键,生成后跳转至第10行,然后使用o进入vim的插入模式
autocmd BufNewFile *.c,*.cpp,*.sh,*.py,*.java,*.php exec ":call Setfilehead()"
func Setfilehead()

    "如果文件类型为.c或者.cpp文件
    if (&filetype == 'c' || &filetype == 'cpp')
            call setline(1, "/*************************************************************************")  
            call setline(2, "\ @Author: Your Name")  
            call setline(3, "\ @Created Time : ".strftime("%c"))  
            call setline(4, "\ @File Name: ".expand("%"))  
            call setline(5, "\ @Description:")  
            call setline(6, " ************************************************************************/")  
            call setline(7,"")  
    endif
    "如果文件类型为.sh文件
    if &filetype == 'shell'  
            call setline(1, "\#!/bin/sh")
            call setline(2, "\# Author: Your Name")
            call setline(3, "\# Created Time : ".strftime("%c"))
            call setline(4, "\# File Name: ".expand("%"))
            call setline(5, "\# Description:")
            call setline(6,"")
    endif
    "如果文件类型为.py文件
    if &filetype == 'python'
            call setline(1, "\#!/usr/bin/env python")
            call setline(2, "\# -*- coding=utf8 -*-")
            call setline(3, "\"\"\"")
            call setline(4, "\# Author: Your Name")
            call setline(5, "\# Created Time : ".strftime("%c"))
            call setline(6, "\# File Name: ".expand("%"))
            call setline(7, "\# Description:")
            call setline(8, "\"\"\"")
            call setline(9,"")
    endif
    "如果文件类型为.php文件
    if &filetype == 'php'  
        call append(0, '') 
    endif   

endfunc
map  :call Setfilehead():10o

"内部注释快捷键生成,映射F11快捷键,生成后跳转至下行,该注释段可以自行修改
func SetComment()
    call append(line(".")  , '//**************** comment start ********************')
    call append(line(".")+1, '//**************** comment end   ********************')
endfunc
map  :call SetComment()jO

你可能感兴趣的:(vim 推荐配置)