Linux里vim简单配置文件

 vim是Linux下的编辑器,可以根据个人需要配置成自己喜欢的样子,下面简单介绍一下我的配置。
首先,在当前用户目录下添加.vimrc文件,打开文件,就可以进行配置文件的编写了,当然,所系配置只对在当前目录下文件进行vim编辑时有效,即缩写配置文件只作用于当前用户的vim。
  1 set nu    //显示行号
  2 syntax on   //语法高亮
  3 autocmd Insertleave * se nocul    //浅色高亮当前行
  4 autocmd InsertEnter * se cul   //浅色高亮当前行
  5 set shiftwidth=4   //设定 << 和 >> 命令移动时的宽度为 4
  6 set tabstop=4    //设定 tab 长度为 4
  7 set go=    //不要图形按钮
  8 set ruler  //显示标尺
  9 set showcmd  //输入的命令显示出来
 10 vmap <C-c>   //在vim中可以Ctrl+C复制选中部分
 11 if version >= 603  //显示中文帮助                                                         
 12 set helplang=cn  
 13 set encoding=utf-8 
 14 endif  
 15 set autoindent  //自动缩进
 16 set cindent 
 17 filetype indent on  //为特定文件类型载入相关缩进文件
 //新建.c,.h,.sh,.java文件,自动插入文件头
 18 autocmd BufNewFile *.cpp,*.[ch],*.sh,*.py,*.java exec ":call SetTitle()"
 19 func SetTitle()
 20      if &filetype == 'sh'
 21           call setline(1,"\#!/bin/bash")
 22           call append(line("."),"\#########################################    ################################")
 23           call append(line(".")+1, "\# File Name: ".expand("%"))
 24           call append(line(".")+2, "\# Created Time: ".strftime("%c"))
 25           call append(line(".")+3, "\######################################    ###################################")
 26           call append(line(".")+4, "")
 27      else
 28          call setline(1, "/************************************************    *************************")
 29          call append(line("."), "    > File Name: ".expand("%"))
 30          call append(line(".")+1, "\# File Name: ".expand("%"))
 31          call append(line(".")+2, "\# Created Time: ".strftime("%c"))
 32          call append(line(".")+3, " ***************************************    *********************************/")
 33          call append(line(".")+4, "")
 34     endif
 35     if &filetype == 'cpp'
 36         call append(line(".")+6, "#include<iostream>")
 37         call append(line(".")+7, "using namespace std;")
 38         call append(line(".")+8, "")
 39     endif
 40     if &filetype='c'
 41         call append(line(".")+6, "#include<stdio.h>")
 42         call append(line(".")+7, "")
 43     endif
 44 endfunc
 //新建文件后,自动定位到文件末尾
 45 autocmd BufNewFile * normal G

效果图
.c文件

这里写图片描述

.cpp文件

这里写图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章