美文网首页PHP实战
vim 开发者推荐配置

vim 开发者推荐配置

作者: 零一间 | 来源:发表于2018-02-09 12:37 被阅读25次

主要是针对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
    "如果文件类型为.java文件
    if &filetype == 'java'  
            call setline(1, "//coding=utf8")  
            call setline(2, "/**")  
            call setline(3, "\ *\ @Author: Your Name")  
            call setline(4, "\ *\ @Created Time : ".strftime("%c"))  
            call setline(5, "\ *\ @File Name: ".expand("%"))  
            call setline(6, "\ *\ @Description:")  
            call setline(7, "\ */")  
            call setline(8,"")  
    endif
    "如果文件类型为.php文件
    if &filetype == 'php'  
        call append(0, '<?php ')
        call append(1, '/**')
        call append(2, '* @File: '.expand("%"))
        call append(3, '* @Author: Your Name')
        call append(4, '* @Description: ---')
        call append(5, '* @Date: '.strftime("%Y-%m-%d %H:%M:%S"))
        call append(6, '* @Last Modified: '.strftime("%Y-%m-%d %H:%M:%S")."\n" )
        call append(7, '*/')
        call append(8, '')
        call append(9, '')
        call append(10, '')
        call append(11, '')
        call append(12, '')
        call append(13, '')
        call append(14, '/* vim: set expandtab ts=4 sw=4 sts=4 tw=100: */')
        call append(15, '?>') 
    endif   

endfunc
map <F2> :call Setfilehead()<CR>:10<CR>o

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


相关文章

网友评论

    本文标题:vim 开发者推荐配置

    本文链接:https://www.haomeiwen.com/subject/ayuftftx.html