vim中的模板?
模板的更新?也算測試。或者其實應該是vim配置的緣故。
其實還是感覺emacs下這個yasnippet更正常一點,vim下面插入稍微不那麼順手?好像vim更多的是,打開某類文件的時候就自動插入了。
使用的就是vim-template這個插件。
安裝使用vim-plug——是的,已經從vundle切換過來了。好像也沒有太多差別。
不過就是vimrc中加入一句Plug 'aperezdc/vim-template'
,vim-plug應該單獨寫一個。
然後vim-plug的話,模板就在plugged下面,vim-plug文件夾下的temlate裏面,可以自己寫。
幫助文檔在這裏:help template.txt
然後裏面就有一些默認的模板了。
大概這種:
=template=.bash =template=.c =template=.c++ =template=.cc =template=.cmake =template=.coffee =template=.cpp =template=.css =template=.cxx =template=.dart =template=.f =template=.f90 =template=.go =template=.h =template=.hs =template=.html =template=.humans.txt =template=.java =template=.jl =template=.js =template=.jsp =template=.jsx =template=.lhs =template=.lua =template=.m =template=.mk =template=.ml =template=.mm =template=.php =template=.pl =template=.pls =template=.pm =template=.pro =template=.py =template=.rb =template=.robots.txt =template=.rs =template=.sh =template=.sol =template=.sql =template=.tex =template=.txt =template=.xml =template=.xsl =template=.zcml =template=.zig =template=CMakeLists.txt =template=GNUmakefile =template=Makefile
這個=template=就是模板命名的格式。然後可以自己新建需要的模板,然後就:TemplateHere+模板名稱
就可以了。
模板其中,可以引用插件自己的變量。大概有這些:
%DAY%
, %YEAR%
, %MONTH
Current day of the month, year, and month of the year,
as numeric values.
%DATE%
Current date in YYYY-mm-dd
format. This is equivalent
to expanding %YEAR%-%MONTH%-%DAY%
.
%TIME%
Current time in HH:MM
format.
%FDATE%
Current full date (date and time) in YYYY-mm-dd HH:MM
format. This is equivalent to expanding %DATE% %TIME%
.
%FILE%
File name, without extension.
%EXT%
File extension (component after the last period).
%FFILE%
File name, with extension. This is equivalent to
expanding %FILE%.%EXT%
.
%MAIL%
E-mail address of the current user. May be overriden by
defining the g:email
variable.
%USER%
Current logged-in user name. May be overriden by defining
the g:username
variable.
%LICENSE%
Tries to determine the project’s license it the following order:
1. Using licensee
if installed. This can be disabled by
setting the g:templates_use_licensee
variable to 0
.
2. Using the g:license
variable.
3. If all else fails: Default to MIT
.
%HOST%
Current host name.
%GUARD%
A string containing only alphanumeric characters, and
underscores, suitable to be used as preprocessor guards
for C/C++/Objective-C header file.
%CLASS%
File name, without extension, and the first character of
each word capitalised. This is typically used for Java/C++
class names.
%MACROCLASS%
File name, without extension, in all-capitals.
%CAMELCLASS%
File name, without extension, with the first character of
every work capitalised, and underscores removed.
%HERE%
Expands to nothing, but ensures that the cursor will be placed in
the position where this variable appears after expanding the template.
另外,配置的話,有幾個參數,其實默認的基本不用修改貌似也沒有太多問題。1
主要參數有自動插入、模板路徑、模板prefix、用戶變量等。具體這些:
g:templates_no_autocmd
Whether to disable automatic insertion of templates when new
buffers are created. (Default: 0
).
g:templates_directory
Path of a directory containing additional global templates.
Alternatively, it can contain a list of paths, which will
be searched in order. See |template-search-order| for more
details. (Default: []
).
g:templates_name_prefix
Prefix for path-relative templates. See |template-search-order|
for more details. (Default: .vim-template:
).
g:templates_global_name_prefix
Prefix for global templates (builtin and those listed in
g:templates_directory
, NOT path-relative templates). See
|template-search-order| for more details. (Default:
=template=
).
g:templates_fuzzy_start
If non-zero, template patterns are not forced to match the
entire file name, just the end (<pattern>$
). If zero, template
patterns need to consume the entire file name to procure a match
(^<pattern>$
). For example, if g:templates_fuzzy_start = 1
,
a file named template:.c
would match files named .c
and
test.c
. If set to zero, the template would only match .c
(Default: 1
).
g:templates_tr_in
, and g:templates_tr_out
These variables control how template names are interpreted as
regular expressions for matching file names. This can be
useful on a Windows box where *
is not allowed in file
names. The default configuration converts underscores (_
)
into regular expression wildcards (.*
).
(Default: `['.','*','?']`, and `['\.','.*','\?']`).
g:templates_no_builtin_templates
If non-zero, disables usage of the built-in templates. See
|template-search-order| for more details. (Default: 0
).
g:templates_user_variables
Allows expansion of user-defined variables. See
|template-user-variables| for more details.
(Default: []
).
g:templates_use_licensee
Use licensee to detect project license when expanding
%LICENSE%
. (Default: 1
)
g:templates_debug
If non-zero, output debugging information. (Default: 0
).
g:templates_plugin_loaded
Setting this to a non-zero value will disable the plug-in.
(Default: 0
).
g:templates_search_height
Controls the search in the current directory and parents. If
set to -1, the template is searched for in the given
directory and all parents in its directory structure, stopping
at the first matching template. If set to 0, no searching
is done in the given directory or any parents. If set to [1]
only the given directory is searched. If greater
than one, n parents and the given directory will be searched
where n is equal to height - 1. (Default: -1
).
g:templates_detect_git
Detects if the directory is in a Git repository and uses git
to determine the root of the repository. Licensee - if enabled
- is given the root directory instead of the one containing
the new file, since most Git repositories keep the license in
the root. Set to 1
to enable. May add half a second to
opening a new file.
footnotes:
-
只是好像貌似有點和c.vim衝突,模板的話。其實只是還沒有找到解決的辦法。然後好像多少有些問題——其實就是同時加載了c.vim的模板和tempalte裏面的C模板,說起來,後續模板也沒有什麼特別的。只是兩個一起不免看起來有些錯誤。解決的方法之一:把template的自動插入模板功能關掉。vimrc配置裏面寫一個
let g:templates_no_autocmd=1
,默認是0,應該是自動插入打開的。 ↩