autocmd BufNewFile *.py,*.pl exec ":call SetTitle()"
"新建python
"定义函数SetTitle,自动插入文件头
func SetTitle()
"如果文件类型为.python文件
if &filetype == 'python'
call setline(1, "\#!/usr/bin/env python")
call append(line("."), "\# -*- coding=utf8 -*-")
endif
if &filetype == 'perl'
call setline(1, "\#!/usr/bin/env perl")
call append(line("."), "##################################")
endif
call append(line(".")+1, "\# Author: vinson")
call append(line(".")+2, "\# Created Time : ".strftime("%c"))
call append(line(".")+3, "\# File Name: ".expand("%"))
call append(line(".")+4, "\# Description:")
call append(line(".")+5, "##################################")
endfunc
comment:
可以通过:set filetype 查看当前文件类型
可以先参看
runtime macros/matchit.vim
在.vimrc中添加
" Let the matchit plugin know what items can be matched.
"
runtime! macro/matchit.vim
if exists('loaded_matchit')
let b:match_ignorecase=0
let b:match_words=
\ '\
\ '\
\ '\
\ '\
\ '\
\ '\
\ '\
\ '\
\ '\
\ '\
\ '\
\ '\
\ '\
\ '\
\ '\
\ '\
\ '\
\ '\
\ '`ifdef\>:`else\>:`endif\>,' .
\ '\
endif
setlocal foldmethod=expr
set foldexpr=MyFoldExpr(v:lnum)
function! MyFoldExpr(line)
let str = getline(a:line)
if str =~ '^\s*task\s' || str =~ '^\s*function\s'
return 'a1'
elseif str =~ '^\s*endtask' || str =~ '^\s*endfunction'
return 's1'
elseif str=~'`uvm_\w*_utils_begin'
return 'a1'
elseif str=~'`uvm_\w*_utils_end'
return 's1'
elseif str =~ '\sbegin\s*'
return 'a2'
elseif str =~ '\send\s*'
return 's2'
else
return -1
endif
endfunction
set tabstop=2 " (ts) width (in spaces) that a is displayed as
set expandtab " (et) expand tabs to spaces (use :retab to redo entire file)
set shiftwidth=2 " (sw) width (in spaces) used in each step of autoindent (aswell as << and >>)
set softtabstop=2
将之前的tab 也换成空格
在gvim上输入:retab !
.vimrc 常用配置
if has("syntax")
syntax on
endif
if has("autocmd")
filetype plugin indent on
endif
" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
set showcmd " Show (partial) command in status line.
set showmatch " Show matching brackets.
set ignorecase " Do case insensitive matching
"set smartcase " Do smart case matching
"set incsearch " Incremental search
"set autowrite " Automatically save before commands like :next and :make
"set hidden " Hide buffers when they are abandoned
set mouse=a " Enable mouse usage (all modes)
set selection=exclusive
"set selection=mouse,key
"the below is my write
set nu
"set autoindent
"set cindent
"set smartindent
set nocompatible
set background=light
set confirm " need to confirm when save the read-only/no save file
set tabstop=4
set shiftwidth=4
"set expandtab
"set softtabstop=4
" :retab !
set hlsearch
set incsearch
set gdefault
set whichwrap+=<,>,h,l
set completeopt=preview,menu
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 一般设定
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
colorscheme desert
"colorscheme torte
set guifont=Monospace\ 10
set clipboard+=unnamed
syntax on
"syntax keyword gtkType gint gshort guint gushort gulong gdouble gfloat gchar guchar gboolean gpointer
"highlight link gtkType Type
highlight StatusLine guifg=SlateBlue guibg=Yellow
highlight StatusLineNC guifg=Gray guibg=White
set fillchars=vert:\ ,stl:\ ,stlnc:\
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
set laststatus=2
" {{{ map keyword
inoremap ( ()
inoremap { {}
inoremap [ []
inoremap " ""
map 1gt
map 2gt
map 3gt
map 4gt
map 5gt
map 6gt
map 7gt
map 8gt
map 9gt
map :tablast
map ww :w
map qq :q
" configuration vundle
vnoremap $1 `>a)`
vnoremap $2 `>a]`
vnoremap $3 `>a}`
vnoremap $$ `>a"`
vnoremap $q `>a'`
vnoremap $e `>a"`
" }}}
"""""""""""""""""""""""""""""""""
" tags
"""""""""""""""""""""""""""""""""
source ~/vim_tag/vim_tag
"Let the matchit plugin know what items can be matched.
runtime! ftplugin/matchit.vim
if exists("loaded_matchit")
let b:match_ignorecase=0
let b:match_words=
\ '\:\,' .
\ '\:\,' .
\ '\:\,' .
\ '\:\,' .
\ '\:\,' .
\ '\:\,' .
\ '\:\,' .
\ '\:\,' .
\ '\:\,' .
\ '\:\,' .
\ '\:\,' .
\ '\:\,' .
\ '\:\,' .
\ '\:\,' .
\ '\:\,' .
\ '\:\,' .
\ '\\|\\|\:\,' .
\ '\:\\|\\|\,' .
\ '`ifdef\>:`else\>:`endif\>,' .
\ '\:\'
endif