首页 > 其他分享 >vimrc 配置,配色

vimrc 配置,配色

时间:2024-08-29 18:04:50浏览次数:10  
标签:set vimrc filetype 配置 call 配色 setline line append

特点:

1、创建代码的时候,自动加版权,作者,创建时间;

2、代码保存的时候,自动修改 Last Modify;

3、对于没有该模板开头的代码,不做任何的修改;

4、vim 打开,显示文件名,下划线的方式显示当前行;

vimrc 位置:~.vimrc

if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
   set fileencodings=ucs-bom,utf-8,utf-16,gbk,big5,gb18030,latin1
   set termencoding=utf-8
   set encoding=utf-8
endif
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
set nocompatible    " Use Vim defaults (much better!)
set bs=indent,eol,start     " allow backspacing over everything in insert mode
"set ai         " always set autoindenting on
"set backup     " keep a backup file
set viminfo='20,\"50    " read/write a .viminfo file, don't store more
            " than 50 lines of registers
set history=50      " keep 50 lines of command line history
set ruler       " show the cursor position all the time

" Only do this part when compiled with support for autocommands
if has("autocmd")
  augroup redhat
  autocmd!
  " In text files, always limit the width of text to 78 characters
  autocmd BufRead *.txt set tw=78
  " When editing a file, always jump to the last cursor position
  autocmd BufReadPost *
  \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  \   exe "normal! g'\"" |
  \ endif
  " don't write swapfile on most commonly used directories for NFS mounts or USB sticks
  autocmd BufNewFile,BufReadPre /media/*,/mnt/* set directory=~/tmp,/var/tmp,/tmp
  " start with spec file template
  autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec
  augroup END
endif

if &diff
    hi DiffAdd    cterm=bold ctermfg=12  guibg=LightBlue
    hi DiffDelete cterm=bold ctermfg=13 ctermbg=14  gui=bold guifg=blue guibg=LightCyan
    hi DiffChange cterm=bold ctermbg=green ctermfg=15  guibg=Magenta
    hi DiffText   term=reverse cterm=bold ctermfg=9 gui=bold  guibg=Red
endif

if has("cscope") && filereadable("/usr/bin/cscope")
   set csprg=/usr/bin/cscope
   set csto=0
   set cst
   set nocsverb
   " add any database in current directory
   if filereadable("cscope.out")
      cs add cscope.out
   " else add database pointed to by environment
   elseif $CSCOPE_DB != ""
      cs add $CSCOPE_DB
   endif
   set csverb
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

filetype plugin on

"show file name"


if &term=="xterm"
     set t_Co=8
     set t_Sb=^[[4%dm
     set t_Sf=^[[3%dm
endif



" Don't wake up system with blinking cursor:
" http://www.linuxpowertop.org/known.php
let &guicursor = &guicursor . ",a:blinkon0"
set number
set cursorline
"hi CursorLine   cterm=None ctermbg=lightmagenta  ctermfg=blue
"hi CursorColumn cterm=NONE ctermbg=black ctermfg=blue
syntax on
set softtabstop=4
set tabstop=4
set laststatus=2
set shiftwidth=4
set expandtab
let autosave=5

" file head add signature

autocmd BufNewFile *.conf set filetype=conf
autocmd BufNewFile *.[ch],*.hpp,*.cpp,Makefile,*.mk,*.sh,*.py,*.conf exec ":call SetTitle()"

"autocmd BufNewFile *.conf ":call SetTitle()"

autocmd BufWrite *.[ch],*.hpp,*.cpp,Makefile,*.mk,*.sh,*.py,*.conf exec ":call SetModify()"

func SetComment()
    call setline(1,"/*================================================================")
    call append(line("."),   "*   Copyright (C) ".strftime("%Y"). " ***.cn, All rights reserved.")
    call append(line(".")+1, "*   ")
    call append(line(".")+2, "*   @File Name   : ".expand("%:t"))
    call append(line(".")+3, "*   @Author      : Name@***.cn")
    call append(line(".")+4, "*   @Create Time : ".strftime("%Y-%m-%d %H:%M:%S"))
    call append(line(".")+5, "*   @Last Modify : ".strftime("%Y-%m-%d %H:%M:%S"))
    call append(line(".")+6, "*   @Description : ")
    call append(line(".")+7, "================================================================*/")
    call append(line(".")+8, "")
    call append(line(".")+9, "")
endfunc

func SetComment_sh()
    call setline(3, "#================================================================")
    call setline(4, "#   Copyright (C) ".strftime("%Y"). " ***.cn, All rights reserved.")
    call setline(5, "#   ")
    call setline(6, "#   @File Name   : ".expand("%:t"))
    call setline(7, "#   @Author      :  Name@***.cn")
    call setline(8, "#   @Create Time : ".strftime("%Y-%m-%d %H:%M:%S"))
    call setline(9, "#   @Last Modify : ".strftime("%Y-%m-%d %H:%M:%S"))
    call setline(10,"#   @Description :")
    call setline(11, "#")
    call setline(12, "#================================================================")
    call setline(13, "")
    call setline(14, "")
endfunc

func GETLINENUM()
    let knum = 0
    for EACH in getline(1,20)
        let knum += 1
        let modify=EACH[5:15]
        if modify == "Last Modify"
            return knum
        endif
    endfor
    return 0
endfunc



func SetModify()

     "call setline(17, "# Modify  @File Name   : &LINE:".modify)
     let modi=GETLINENUM()
     if modi != 0
         if &filetype == "h" || &filetype == "c" || &filetype == "cpp"
             "call setline(modi, "#   @Last Modify : ".strftime("%c"))
             call setline(modi, "#   @Last Modify : ".strftime("%Y-%m-%d %H:%M:%S"))
         elseif &filetype == "sh" || &filetype == "python" || &filetype == "make" || &filetype == "conf"
             call setline(modi, "#   @Last Modify : ".strftime("%Y-%m-%d %H:%M:%S"))
         endif
     endif
endfunc


func SetTitle()

    if &filetype == 'make' || &filetype == 'conf'
        let cc=&filetype
        call setline(1,"")
        call setline(2,"")
        call SetComment_sh()

    elseif &filetype == 'sh'
        call setline(1,"#!/system/bin/sh")
        call setline(2,"")
        call SetComment_sh()
    elseif &filetype == "python"
        call setline(1,"#!/usr/bin/python")
        call setline(2,"")
        call SetComment_sh()

    else
         call SetComment()
         if expand("%:e") == 'hpp'
              call append(line(".")+10, "#ifndef _".toupper(expand("%:t:r"))."_H")
              call append(line(".")+11, "#define _".toupper(expand("%:t:r"))."_H")
              call append(line(".")+12, "#ifdef __cplusplus")
              call append(line(".")+13, "extern \"C\"")
              call append(line(".")+14, "{")
              call append(line(".")+15, "#endif")
              call append(line(".")+16, "")
              call append(line(".")+17, "#ifdef __cplusplus")
              call append(line(".")+18, "}")
              call append(line(".")+19, "#endif")
              call append(line(".")+20, "#endif //".toupper(expand("%:t:r"))."_H")

         elseif expand("%:e") == 'h'
              call append(line(".")+10, "#pragma once")
         elseif &filetype == 'c'
              call append(line(".")+10,"#include \"".expand("%:t:r").".h\"")
         elseif &filetype == 'cpp'
              call append(line(".")+10, "#include \"".expand("%:t:r").".h\"")
         endif
    endif
    normal G
endfunc

 

标签:set,vimrc,filetype,配置,call,配色,setline,line,append
From: https://www.cnblogs.com/lovychen/p/11808870.html

相关文章

  • python读取配置文件&&简单封装 公共配置文件 config
    之前有做过把爬虫数据写到数据库中的练习,这次想把数据库信息抽离到一个ini配置文件中,这样做的好处在于可以在配置文件中添加多个数据库,方便切换(另外配置文件也可以添加诸如邮箱、url等信息)1.configparser模块python使用自带的configparser模块用来读取配置文件,配置文......
  • vue history 模式打包部署在域名的二级目录的配置指南
    1.vue-router路由的文件的配置,根据自己部署的二级目录填写123exportdefaultnewVueRouter({ mode:"history",  base:"/web",2.在vue.config.js配置文件(如果没有新建一个,项目根目录下) 注意:baseUrl从VueCLI3.3起已弃用,请使用publicPath。......
  • 沉浸式学习ACL基本原理与配置(上)
    随着网络技术的飞速发展,网络安全问题日益突出。ACL(AccessControlList,访问控制列表)可以通过对网络中报文流的精确识别,与其他技术结合,达到控制网络访问行为、防止网络攻击和提高网络带宽利用率的目的,从而切实保障网络环境的安全性和网络服务质量的可靠性。ACL使用包过滤技术,在......
  • powershell 创建winform窗体 T2 : 自动配置相机网卡参数
    <#脚本功能说明:选择要配置的相机网卡,点击配置按键,自动配置参数#2024.08.29#>#获取管理员权限if(-NOT([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator......
  • 应对Nginx负载均衡中的请求超时:策略与配置
    在Nginx负载均衡的部署中,处理请求超时是一个关键问题。请求超时不仅影响用户体验,还可能隐藏着后端服务的性能瓶颈。合理配置Nginx以处理超时情况,可以显著提高服务的稳定性和可靠性。本文将详细介绍如何在Nginx负载均衡中处理请求超时,包括超时的原因、配置参数、优化策略以及......
  • Nginx负载均衡中的缓存过期配置:策略与实现
    在Nginx负载均衡的高级应用中,合理配置缓存过期策略对于提升网站性能和保证内容的新鲜度至关重要。缓存过期意味着存储在代理缓存中的响应在一定时间后将被视为过时,并在下一次请求时从原始服务器重新获取。本文将详细介绍如何在Nginx中配置缓存过期,包括缓存机制的理解、过期......
  • Nginx负载均衡SSL证书配置全指南
    在当今的网络安全实践中,使用SSL证书对网站进行加密已成为标准配置。Nginx作为一个广泛使用的Web服务器和反向代理,提供了强大的SSL配置选项来保护数据传输的安全。本文将详细介绍如何在Nginx负载均衡中配置SSL证书,包括证书的获取、配置文件的编写、证书的更新和续期等。1.S......
  • 嵌入式STM32单片机开发环境配置教学Win/Mac
    合集-环境配置(2)1.最全!嵌入式STM32单片机开发环境配置教学Win/Mac!!!08-282.最简最速!C++版OpenCV安装配置教程Win/Mac!!!08-28收起嵌入式STM32单片机开发环境配置教学Win/Mac·本教程支持Windows和Mac·Windows可选的开发软件为Keil、Clion、STM32CubeMX,可自由选择开发方式·M......
  • Clion\+OpenCV(C\+\+版)开发环境配置教程Win/Mac
    合集-环境配置(2)1.最全!嵌入式STM32单片机开发环境配置教学Win/Mac!!!08-282.最简最速!C++版OpenCV安装配置教程Win/Mac!!!08-28收起Clion+OpenCV(C++版)开发环境配置教程Win/Mac平时在学习和比赛的时候都是使用的Python版本的OpenCV,最近遇到了一个项目使用的上位机性能有限于是决定......
  • 有限元分析从定义到场景到硬件配置详细讲解
    有限元分析(FiniteElementAnalysis,简称FEA)是一种利用数学近似的方法对真实物理系统(几何和载荷工况)进行模拟的数值分析技术。其核心思想是将一个连续的问题离散化为一组有限个、且仅在有限个节点上相互连接的单元组合体,从而对实际问题进行近似求解。以下是有限元分析的详细解析......