Vim 编辑器应用

编辑器设置:

  • syntax on 语法高亮
  • set number 显示行号
  • set autoindent set cindent 自动缩进
  • 自动加入文件头:
    autocmd BufNewFile .py,.cpp,.sh,.java exec ":call SetTitle()"
    func SetTitle()
    if &filetype == 'sh'
    call setline(1,"#!/bin/bash")
    call append(line("."), "# Author:Byrd")
    call append(line(".")+1, "# Version:0.1")
    call append(line(".")+2, "# Site:www.t4x.org")
    call append(line(".")+3, "# Contact:root#t4x.org")
    call append(line(".")+4, "")
    elseif &filetype == 'cpp'
    call setline(1,"// File Name: ".expand("%"))
    call append(line("."), "// Author: Byrd")
    call append(line(".")+1, "// Created Time: ".strftime("%c"))
    call append(line(".")+2, "")
    call append(line(".")+3, "#include<iostream>")
    call append(line(".")+4, "#include<string>")
    call append(line(".")+5, "#include<algorithm>")
    call append(line(".")+6, "#include<cstdlib>")
    call append(line(".")+7, "using namespace std;")
    call append(line(".")+8, "int main(){")
    call append(line(".")+9, "")
    call append(line(".")+10, " return 0")
    call append(line(".")+11,"}")
    elseif &filetype == 'python'
    call setline(1,"#!/usr/bin/env python")
    call append(line("."), "# Author: Byrd")
    call append(line(".")+1, "# Created Time: ".strftime("%c"))
    call append(line(".")+2, "")
    else
    call setline(1,"/")
    call append(line("."), "
    Author: Byrd")
    call append(line(".")+1, "* Created Time: ".strftime("%c"))
    call append(line(".")+2, "*/")
    call append(line(".")+3, "")
    endif
    endfunc
"新建文件后,自动定位到文件末尾
autocmd BufNewFile * normal G
"ts是tabstop的缩写,设TAB宽4个空格

set ts=4
set expandtab

最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容