vim自動載入模板的外掛~
又搜了下,貌似有個CVIM的外掛也很N~~~學習了~~
記得之前實習的時候新建一個檔案.h .c .cpp後會自動加一些檔案說明,比如檔案的名字,建立日期、建立者等等一些資訊,想起來使用很方便,就自己找了下怎麼做,沒想到這麼難搜,不過還是被我找到了~~~
1、將檔案放入 plugin(~/.vim/plugin/ 或者 $HOME/vimfiles/plugin/)目錄
2、.vimrc 加入:
let g:template_load = 1let g:template_tags_replacing = 1let g:T_AUTHOR = "Jestery"let g:T_AUTHOR_EMAIL = "
3、新建一個模板檔案存為 templates/tpl.c(例如~/.vim/templates/tpl.c)
模板名的取名規則是 tpl.extension,新建*.h的時候,tpl.h 被讀入
/* *Author: * <T_AUTHOR> <<T_AUTHOR_EMAIL>> * <T_AUTHOR_WEBSITE> * * File: <T_FILENAME> * Create Date: <T_CREATE_DATE> */void main(int argc, char* argv[]){ <T_CURSOR>}/* vim: set ts=4 sw=4: */
這樣就可以實現新建一個.h .c .cpp等檔案時自動載入模板裡面的內容了。上面是作者的做法,我的做法如下:
前兩步是一樣的,第三步其實也很類似,只是我把模板放在了指定的其他位置,模板的名稱以template.h template.c template.cpp命名,這樣每次新建同類型的檔案時就會載入這些模板裡面的內容。同時在如果要支援其他型別的檔案,直接增加模板檔案就ok了。比如要支援字尾為.*的檔案,則可以增加一個template.*模板,那麼新建檔案時候就會載入這個模板了。很方便吧~~~哈哈~~~
沒找到csdn上附件的插入位置。。
貼下程式碼吧,不是很長,而且很清晰
- "=============================================================================
- " Vim global plugin for load template files
- " File: template_loader.vim
- " Maintainer: Jestery Liu <[email protected]>
- " Last Change: 2007/02/02
- " Version: 0.1
- " Description:
- " Load template file for editing new files
- " Options:
- " (int) g:template_load
- " Set to 0 to disable template auto-loading, 1 for enable.
- "
- " (int) g:template_confirm
- " If set to 1, everytime you edit a new file you will be asked for
- " whether load template or not.
- "
- " (string) g:template_path
- " If set, script will look fortemplate files in this path, if not set,
- " the script will locate template files in each path in &runtimepath.
- "
- " (string) g:template_dir_name
- " By default, if g:template_path is not set, script will locate template
- " files in &runtimepath.'/templates/', '~/.vim/templates/'for example,
- " you can custom your own directory name by set this value. If
- " g:template_path is set, this value never be used.
- "
- " (string) g:template_prefix
- " The defaulttemplate file name is 'tpl.extension', for example, if you
- " create a 'foo.c', '~/.vim/templates/tpl.c' will be loaded. You can set
- " this value to 'skel' to load 'skel.c'
- "
- " (int) g:template_tags_replacing
- " If set to 1, some pre-defined tags will be replaced by the
- " following variables:
- " (string) g:T_AUTHOR
- " (string) g:T_AUTHOR_EMAIL
- " (string) g:T_AUTHOR_WEBSITE
- " (string) g:T_LICENSE
- " (string) g:T_DATE_FORMAT (Same as strftime)
- " (int) g:T_FILENAME_USE_FULL_PATH
- " (If 1, /foo/bar.c will be used, otherwise, bar.c)
- " Pre-defined tags:
- " <T_AUTHOR>, <T_AUTHOR_EMAIL>, <T_AUTHOR_WEBSITE>
- " <T_LICENSE>, <T_FILENAME>, <T_CREATE_DATE>
- " <T_CURSOR>
- " If found <T_CURSOR>, the cursor will be placed here and <T_CURSOR>
- " will be deleted.
- "
- " (int) g:template_replace_start_line
- " Start tag replacing from here. Default is 1
- "
- " (int) g:template_replace_end_line
- " End tag replacing to here. Default is the last line ("$")
- if exists("g:template_load") && g:template_load==1
- augroup Template_Loader
- autocmd!
- au BufNewFile * call LoadTemplate()
- augroup END
- else
- finish
- endif
- function! LoadTemplate()
- let s:template_file = ""
- let g:template_prefix = exists("g:template_prefix") ? g:template_prefix : 'tpl'
- let s:ext = expand('%:e')
- if s:ext == ""
- let s:ext = expand('%:t')
- endif
- let s:template_file_name = g:template_prefix . '.' . s:ext
- if exists("g:template_path")
- let s:template_file = g:template_path.'/'.s:template_file_name
- else
- let s:template_dir_name = exists("g:template_dir_name") ? g:template_dir_name : 'templates'
- let s:rtp = &runtimepath
- let s:dirs = split(s:rtp, ',')
- if empty(s:dirs)
- return
- endif
- for dir in s:dirs
- let s:template_file = dir.'/'.s:template_dir_name.'/'.s:template_file_name
- if filereadable(s:template_file)
- break
- endif
- endfor
- "unlet s:rtp, s:dirs, s:template_dir_name
- endif
- if s:template_file=="" || !filereadable(s:template_file)
- echo "Missing template file. (".s:template_file.")"
- return
- endif
- call LoadTemplateFile(s:template_file)
- endfunction
- function! LoadTemplateFile(filename)
- let choice = 1
- if exists("g:template_confirm") && g:template_confirm==1
- let choice = confirm("Do you want to load template for this new file?", "&Yes/n&No")
- endif
- if choice==0
- return
- endif
- sil! execute "0r " . a:filename
- call TemplateReplTags()
- endfunction
- function! TemplateReplTags()
- if g:template_tags_replacing != 1
- return
- endif
- let sl = exists("g:template_replace_start_line") ? g:template_replace_start_line : 1
- let el = exists("g:template_replace_end_line") ? g:template_replace_end_line : "$"
- if exists("g:T_AUTHOR")
- sil! execute sl.','.el."s/<T_AUTHOR>/".g:T_AUTHOR."/g"
- endif
- if exists("g:T_AUTHOR_EMAIL")
- sil! execute sl.','.el."s/<T_AUTHOR_EMAIL>/".g:T_AUTHOR_EMAIL."/g"
- endif
- if exists("g:T_AUTHOR_WEBSITE")
- sil! execute sl.','.el."s=<T_AUTHOR_WEBSITE>=".g:T_AUTHOR_WEBSITE."=g"
- endif
- if exists("g:T_LICENSE")
- sil! execute sl.','.el."s/<T_LICENSE>/".g:T_LICENSE."/g"
- endif
- if exists("g:T_DATE_FORMAT")
- sil! execute sl.','.el."s/<T_CREATE_DATE>/".strftime(g:T_DATE_FORMAT)."/g"
- endif
- if exists("g:T_FILENAME_USE_FULL_PATH") && g:T_FILENAME_USE_FULL_PATH==1
- let s:fn = expand("%:p")
- else
- let s:fn = expand("%:t")
- endif
- sil! execute sl.','.el."s/<T_FILENAME>/".s:fn."/g"
- unlet s:fn
- let s:curpos = search("<T_CURSOR>", 'W')
- if !empty(s:curpos)
- call cursor(s:curpos)
- sil! execute "normal df>"
- sil! execute "startinsert"
- endif
- endfunction
- " vim: set ts=4 sw=4 tw=78:
相關推薦
vim自動載入模板的外掛~
又搜了下,貌似有個CVIM的外掛也很N~~~學習了~~ 記得之前實習的時候新建一個檔案.h .c .cpp後會自動加一些檔案說明,比如檔案的名字,建立日期、建立者等等一些資訊,想起來使用很方便,就自己找了下怎麼做,沒想到這麼難搜,不過還是被我找到了~~~ 1
vim自動載入cscope.out
cscope可以查詢程式碼的引用、定義等,但是當用vim直接開啟專案子目錄中的一個檔案時,cscope.out不能直接載入。在網上搜了一把,autoload_cscope外掛可以解決這個問題,但是這個外掛只針對c, h檔案,開啟cpp時好像不能生效(可能是我沒找到設
CentOS7 Vim自動補全外掛----YouCompleteMe安裝與配置
最近剛裝了新系統CentOS7,想要把編碼環境配置一下,使用Vim編寫程式少不了使用自動補全外掛,我以前用的是neocomplcache+code_complete+omnicppcomplete。但在網上搜索時,看到了YouCompleteMe,說YCM更好用一些。
vim 自動提示、自動補齊外掛 YouCompleteMe for windows Gvim 安裝及使用效果
YouCompleteMe is a fast, as-you-type, fuzzy-search(親~~支援模糊匹配哦) code completion engine for Vim. It has two completion engines: an identifier-based engi
Vim為特定檔案載入模板
程式設計開發實際上有許多重複性的工作,比如編寫C/C++時有一些標頭檔案是通用的,但在Vim裡面每次建立新檔案預設都是空白檔案,手工輸入其實挺繁瑣的,下面介紹兩種為特定檔案載入模板的方法,僅以C為例,其他語言類似 方法一 這種方法的特點是以純vimscript實現,跨平臺 a
vim python自動補全外掛:pydiction
vim python自動補全外掛:pydiction 可以實現下面python程式碼的自動補全: 1.簡單python關鍵詞補全 2.python 函式補全帶括號 3.python 模組補全 4.python 模組內函式,變數補全 5.from module
pace.js – 網頁自動載入進度條外掛
之前有很多同學詢問覺唯網站頂部的頁面載入進度條是怎麼實現的,頁面的載入進度百分比,有時候獲取是比較麻煩的,當然也可以利用一些優秀的JavaScript外掛來實現,今天就為大家介紹這樣子的一款外掛:pace.js。 在頁面中引入Pace.js,頁面就會自動監測你的請求
CAD.net 寫登錄檔自動載入外掛dll
RegistryKey LocaIMachine = Registry.LocalMachine; RegistryKey MyPrograrm = LocaIMach
vim ctags cscope lookupfile外掛(包括如何自動生成索引tag、自動查詢索引tag)
好長時間沒有上來更新了, 今天趁老闆不再上來休閒一下. 本章要說的是和vim的tags相關的內容. 之所以在跳轉之後就說明tags是因為這個功能相當的重要和實用. 好的東西自然是需要提前分享的. 首先, 要說的是關於vim使用ctags, cscope的相關教程
自動補全外掛 jedi-vim
安裝方式 1. 在.vimrc 新增 jedi-vim 和 supertab call vundle#begin() ... Bundle 'davidhalter/jedi-vim' Bundle 'ervandew/supertab' ... call vun
vim安裝youcompleteme自動補全外掛
本文介紹的是如何在vim中安裝youcompleteme自動補全外掛 一、安裝youcompleteme 開啟檔案~/.vimrc 新增下面一行程式碼 Bundle 'Valloric/YouCompleteMe' 儲存退出,開啟一個vim新檔
vim 新建檔案後自動插入模板
例如 vim a.php 自從插入一段註釋 開啟 ~/.vimrc 加上下面程式碼 function AddFileInformation() let infor = "<?php\n" \."/************************
Vim中自動載入cscope.out
Vimer初成長,Vim + ctags + cscope 這個組合基本是每個Vimer的必備吧。雖然ctags已經足夠強大,但是cscope可以做的更多。下面來分享下自己的vimrc指令碼關於cscope的一部分,該指令碼可以實現在專案的任一子目錄下,自動的向上查詢cs
實踐中學習vim之vim配置檔案、外掛檔案載入路徑
0 引言 理解vim的啟動過程對於增強使用vim的信心非常重要,本文所有的資訊均來自vim自身提供的參考手冊和作者實際操作實踐。VIM REFERENCE MANUAL的Starting Vim這節詳細描述了vim的啟動過程。vim完整的啟動過程非常複雜,因為要相容不同的平
php設計模式--命名空間與自動載入
使用 命令 說明 自動載入 str space () 就會 sta 關於命名空間: 最早的php是沒有命名空間的概念的,這樣不能存在相同名稱的類或者函數,當項目變大了之後,產生沖突的可能性就高了,代碼量也會變大,為了規劃,從php5.3開始對命名空間就支持了。 說明代碼
vim 自動在操作符 前後加上空格 C語言
空格 func 再次 不知道 編碼 placement 字符 cti spa function! Align_Space() let current_line = getline(‘.‘) let replacement = subs
VIM自動補齊括號和引號
VIM補齊括號 VIM補齊引號 在~/.vimrc文件中追加以下內容: inoremap ( ()<ESC>iinoremap [ []<ESC>iinoremap { {}<ESC>iinoremap < <><ESC>iinorem
牛客小白月賽6 G 指紋鎖 set的自動排序 模板
加密 的人 算法 esc code 超過 fin 代碼 sync 鏈接:https://www.nowcoder.com/acm/contest/136/G來源:牛客網 題目描述 HA實驗有一套非常嚴密的安全保障體系,在HA實驗基地的大門,有一個指紋鎖。
Pycharm載入第三方外掛失敗方法(關鍵字:Nothing to show)和安裝失敗解決辦法
一、修復外掛顯示錯誤,共3個步驟: 1,新增額外源: 清華:https://pypi.tuna.tsinghua.edu.cn/simple 阿里雲:http://mirrors.aliyun.com/pypi/simple/ 中國科技大學 https://pypi.mi
PHP規範PSR4(自動載入)介紹
本文件中的關鍵詞“必須”,“必須”,“必需”,“應該”,“不應該”,“應該”,“不應該”,“推薦”,“可以”和“可選”按照RFC 2119中的描述進行解釋。 1 概述 此PSR描述了從檔案路徑自動載入類的規範。它完全可互操作,除了包括PSR-0在內的任何其他自動載入規範外,還可以使用它。此P