diff --git a/docs/cn/conventions.md b/docs/cn/conventions.md index 034baca7f..63bfac80b 100644 --- a/docs/cn/conventions.md +++ b/docs/cn/conventions.md @@ -33,8 +33,9 @@ lang: cn - [空白行](#空白行) - [连续行](#连续行) - [命名](#命名) -- [markdown 代码规范](#markdown-代码规范) -- [感谢:](#感谢) +- [按键表示](#按键表示) +- [Vimscript 代码规范](#vimscript-代码规范) +- [Markdown 代码规范](#markdown-代码规范) @@ -60,7 +61,7 @@ Vim 具有高度可定制性。用户可以更改很多的默认设置,包括 双引号字符串在 Vim 和脚本中的语义跟其它语言中不一样,你可能并不需要它们(它们打破了正则表达式)。 -当你需要转义时使用双引号(例如 "\\n") 或者你需要嵌入单引号,例如 "Abce'a'" 。 +当你需要转义时使用双引号(例如`\\n`) 或者你需要嵌入单引号,例如"Abce'a'"。 #### 匹配字符串 @@ -73,33 +74,34 @@ Vim 具有高度可定制性。用户可以更改很多的默认设置,包括 **所有的正则表达前缀都是 \\m, \\v, \\M, 或 \\V 其中之一** -在传统的大小写语义设置下,正则表达式的行为取决于用户的无魔法(nomagic)设置。为了让正则表达式的行为像无魔法(nomagic)和不忽略大小写(noignorecase)设置下一样,在所有正则表达式前都必须有前缀,前缀是 \\m, \\v, \\M, 或 \\V 其中之一。 +在传统的大小写语义设置下,正则表达式的行为取决于用户的无魔法(nomagic)设置。 +为了让正则表达式的行为像无魔法(nomagic)和不忽略大小写(noignorecase)设置下一样,在所有正则表达式前都必须有前缀,前缀是`\\m`,`\\v`,`\\M`, 或`\\V`其中之一。 -欢迎你使用其它等级的魔法(magic levels)(\\v) 和大小写敏感性(\\c) 只要确定了它们是你有意为之并且是明确的。 +欢迎你使用其它等级的魔法(magic levels)`\\v` 和大小写敏感性`\\c`,只要确定了它们是你有意为之并且是明确的。 #### 危险命令 **避免命令意想不到的副作用** -避免使用 `:s[ubstitute]` 因为它会移动光标并打印错误消息。函数(例如 search())更适用于脚本。 +避免使用`:s[ubstitute]`因为它会移动光标并打印错误消息。函数(例如search())更适用于脚本。 -这意味着 g 标志取决于上层中 gdefault 的设置。如果你用了 `:substitute` 你必须要保存 gdefault, 把它设置为 0 或 1,预先生成替换并且在操作完成后还原它。 -For many Vim commands, functions exist that do the same thing with fewer side effects. See `:help functions()` for a list of built-in functions. -有很多内置的 Vim 命令、函数,可以在更小的影响下完成同样的事情。查看 `:help functions` 查看内置的函数表。 +这意味着`g`标志取决于上层中 gdefault 的设置。如果你用了`:substitute`你必须要保存 gdefault, 把它设置为 0 或 1,预先生成替换并且在操作完成后还原它。 + +有很多内置的函数可以代替Vim 命令在影响更小的情况下完成同样的事情。查看`:help functions`查看内置的函数表。 #### 脆弱命令 **避免依赖于用户设置的命令** -一直使用普通模式(normal) 在普通模式下安装。后者取决于用户的按键映射,可以做任何事情。 +总是使用`normal!`在替代`normal`。后者取决于用户的按键映射,可以做任何事情。 -避免 `:s[ubstitute]`,因为它的行为取决于上层的一些运行设置。 +避免`:s[ubstitute]`,因为它的行为取决于上层的一些运行设置。 其它同样的命令的应用,在此不再列出。 #### 捕获异常 -**匹配异常代码,而非异常文本** +**匹配错误代码,而非错误文本** 错误文本可能与语言环境(local dependant)有关。 @@ -120,11 +122,11 @@ For many Vim commands, functions exist that do the same thing with fewer side ef Vim 脚本在处理一些类型(style)时有不安全,不直观的行为。举个例子:`0 == 'foo'` 认证为真(evalutaes to true)。 -尽可能的用严格的比较操作。当二次比较字母的时候用 is# 操作符。除此之外,更适合用 maktaba#value#IsEqual 或明确使用 check htype()。 +尽可能的用严格的比较操作。当二次比较字母的时候用`is#`操作符。除此之外,更适合用 maktaba#value#IsEqual 或明确使用 check htype()。 在使用变量前,明确检查变量的类型。使用 maktaba#ensure 中的函数(functions from maktaba#ensure) 或 check maktaba#value 或 type() 找出你自己的错误。 -使用 `:unlet` 对变量使用(:unlet)可能更改变量的类型,尤其是在循环中赋值的时候。 +对变量使用`:unlet`可能更改变量的类型,尤其是在循环中赋值的时候。 #### Python @@ -142,7 +144,8 @@ Vim 脚本在处理一些类型(style)时有不安全,不直观的行为。举 **将功能组织到模块化插件中** -把你的功能组织成为一个插件,统一放在一个文件夹中(或者是代码仓库)分享你的插件名(用一个 "vim-" 前缀或者需要的话使用 ".vim" 后缀)。它应该可以被拆分到 plugin/, autoload/, 等等。子目录应该以 addon-info.json 格式声明元数据(详情参见 Vim 文档)。 +把你的功能组织成为一个插件,统一放在一个文件夹中(或者是代码仓库)分享你的插件名(用一个 "vim-" 前缀或者需要的话使用 ".vim" 后缀)。 +它应该可以被拆分到 plugin/, autoload/, 等等。子目录应该以 addon-info.json 格式声明元数据(详情参见 Vim 文档)。 #### 功能 @@ -150,9 +153,9 @@ Vim 脚本在处理一些类型(style)时有不安全,不直观的行为。举 自动加载允许按需加载函数,这使得启动时间更快,并且强制执行函数命名空间(namespacing)。 -脚本本地函数(Script-local functions)是被欢迎的,但是只应存活在 atuoload/ 和被自动运行函数调用中。 +脚本本地函数(Script-local functions)是被欢迎的,但是只应存活在`atuoload/`中并且能够被自动运行函数调用。 -非库函数(Non-library) 插件应该提供命令来代替函数。命令逻辑应该被提取到功能和自动加载。 +非库函数(Non-library)插件应该提供命令来代替函数。命令逻辑应该被提取到功能和 `autoload/`。 [!] 允许开发者无需申诉(complaint)便可重新加载它们的功能。 @@ -170,17 +173,17 @@ Excluding [!] prevents your plugin from silently clobbering existing commands. C **在 plugin/autocmds.vim 中用参数组(augroups) 替换它们** -把所有的自动命令(autocommands)替换进参数组(augroups)。 +把所有的自动命令(autocommands)放进参数组(augroups)。 每个参数组都应当有一个独特的名字。或许你应该给它加上插件名前缀。 -在定义一个新的自动命令(autocommands)前,用 autocmd! 清除参数组(augroup)。这可以让你的插件复用(re-entrable)。 +在定义一个新的自动命令(autocommands)前,用`autocmd!`清除参数组(augroup)。这可以让你的插件复用(re-entrable)。 #### 映射 **在 plugin/mappings.vim 中用 maktaba#plugin#MapPrefix 获取前缀** -所有的按键映射都应当在 plugin/mappings.vim 中被定义。 +所有的按键映射都应当在`plugin/mappings.vim`中被定义。 练习映射(参看`:help using-`)应当在 plugin/plugs.vim 中被定义。 @@ -196,7 +199,7 @@ Excluding [!] prevents your plugin from silently clobbering existing commands. C **在本地更改设置** -用 `:setlocal` 和 &l: 替代 `:set` 和 & 除非你有明确的原因不去使用它们。 +用`:setlocal`和`&l:`替代`:set`和`&`,除非你有明确的原因不去使用它们。 ### 风格 @@ -217,7 +220,7 @@ let s:variable = "concatenated " . "strings" command -range=% MyCommand ``` -- 不要在空白行处留下空白字符 +- 不要在行尾留下空白字符 你无需用自己的方法去清除它。 @@ -258,46 +261,50 @@ autocommand BufEnter \|endif ``` -- 你应该尽量避免使用多行命令,可以用函数调用来替代它 +- 应当尽量避免使用多行命令,可以用函数调用来替代它 #### 命名 -总的来说,使用 -- 像这样的插件名 `plugin-names-like-this` -- 像这样的函数名 `FunctionNamesLikeThis` -- 像这样的命令名 `CommandNamesLikeThis` -- 像这样的参数组 `augroup_names_like_this` -- 像这样的变量名 `variable_names_like_this` -- 像这样的提示 `hints-like-this` +- 保持简单易于理解 -总是在变量名前加上它们的范围前缀 -- `plugin-names-like-this` - 保持简单易于理解 -- `FunctionNamesLikeThis` - - 本地脚本函数的前缀为`s:` - - 自动运行函数(autoload functions)可以没有范围前缀。 - - 不要编写(creat)全局函数。用自动运行函数(autoloaded functions)来替代全局函数。 -- `CommandNamesLikeThis` - 通用命令优先于一般的前缀 -- `variable_names_like_this` - Augroup names count as variables for naming purposes. - 参数组(augroup)名字计数作为变量的命名方向。 +- 总的来说,使用 + - 像这样的插件名 `plugin-names-like-this` + - 像这样的函数名 `FunctionNamesLikeThis` + - 像这样的命令名 `CommandNamesLikeThis` + - 像这样的参数组 `augroup_names_like_this` + - 像这样的变量名 `variable_names_like_this` + - 像这样的提示 `hints-like-this` + +- 不要编写(create)全局函数,用自动运行函数(autoloaded functions)来替代全局函数。 +- 通用命令优先于一般的前缀 +- 参数组(augroup)名字像变量一样命名。(Augroup names count as variables for naming purposes.) - 所有的变量据需要加上它们的范围前缀。 - - 全局变量的前缀为`g:` - - 本地脚本变量的前缀为`s:` - - 函数的参数前缀为`a:` - - 本地函数的变量前缀为`l:` - - Vim 预定义(Vim-predefinded)变量前缀为`v:` - - 本地缓冲区(Buffer-local)变量的前缀为`b:` - - `g:`, `s:`, 和 `a:` 前缀必须使用 - - `b:` 当你想要改变本地缓冲区(buffer-local)的变量的语义时前缀为 `b:` - - `l:` and `v:` should be used for consistency, future proofing, and to avoid subtle bugs. They are not strictly required. Add them in new code but don’t go out of your way to add them elsewhere. + - 全局变量的前缀为`g:` + - 本地脚本变量的前缀为`s:` + - 函数的参数前缀为`a:` + - 本地函数的变量前缀为`l:` + - Vim 预定义(Vim-predefinded)变量前缀为`v:` + - 本地缓冲区(Buffer-local)变量的前缀为`b:` + - `g:`,`s:`,和`a:`前缀必须使用 + - `b:`当你想要改变本地缓冲区(buffer-local)的变量的语义时前缀为`b:` + - `l:`and`v:`should be used for consistency, future proofing, and to avoid subtle bugs. They are not strictly required. Add them in new code but don’t go out of your way to add them elsewhere. + - 自动运行函数(autoloaded functions)可以没有范围前缀。 -## markdown 代码规范 +## 按键表示 -## 感谢: +- 使用首字母大写的单词和尖括号来表示按键:``, ``。 +- 使用大写字母来表示custom leader:`SPC`, `WIN`, `UNITE`, `DENITE`。 +- 使用空格来分隔按键序列:`SPC t w`, ` f o`. +- 使用`/` 来分隔多个可选的按键序列:`` / ``. +- 在文档中使用`Ctrl-e`而不是``。 + +## Vimscript 代码规范 + +- [Google Vimscript Style Guide](https://google.github.io/styleguide/vimscriptguide.xml) +- [Google Vimscript Guide](https://google.github.io/styleguide/vimscriptfull.xml) +- [Vim Scripting Style Guide](https://github.com/noahfrederick/vim-scripting-style-guide/blob/master/doc/scripting-style.txt) + +## Markdown 代码规范 + +- [Google's Markdown style guide](https://github.com/google/styleguide/blob/3591b2e540cbcb07423e02d20eee482165776603/docguide/style.md) -- link: -- link: -- link: -- [google's markdown style guide](https://github.com/google/styleguide/blob/3591b2e540cbcb07423e02d20eee482165776603/docguide/style.md) diff --git a/docs/conventions.md b/docs/conventions.md index 1dfd1461a..5b7fc05af 100644 --- a/docs/conventions.md +++ b/docs/conventions.md @@ -1,5 +1,5 @@ --- -title: "Conventions" +title: "Conventions" description: "conventions of contributing to SpaceVim, including the coding style guides about vim script and markdown" --- @@ -33,7 +33,8 @@ description: "conventions of contributing to SpaceVim, including the coding styl - [Line Continuations](#line-continuations) - [Naming](#naming) - [Key notations](#key-notations) -- [Thanks:](#thanks) +- [Vimscript Style](#vimscript-style) +- [Markdown Style](#markdown-style) @@ -140,7 +141,7 @@ Avoid using other scripting languages such as ruby and lua. We cannot guarantee **Organize functionality into modular plugins** -Group your functionality as a plugin, unified in one directory (or code repository) which shares your plugin's name (with a "vim-" prefix or ".vim" suffix if desired). It should be split into plugin/, autoload/, etc. subdirectories as necessary, and it should declare metadata in the addon-info.json format (see the VAM documentation for details). +Group your functionality as a plugin, unified in one directory (or code repository) which shares your plugin's name (with a "vim-" prefix or ".vim" suffix if desired). It should be split into plugin/, autoload/, etc. subdirectories as necessary, and it should declare metadata in the addon-info.json format (see the Vim documentation for details). #### Functions @@ -188,7 +189,7 @@ Your plugins generally shouldn't introduce mappings, but if they do, the map com #### Errors -When using catch, match the error code rather than the error text. +When using catch, match the error codes rather than the error text. #### Settings @@ -221,7 +222,7 @@ Trailing whitespace is allowed in mappings which prep commands for user input, such as "noremap gf :grep -f ". - Restrict lines to 80 columns wide -- Indent continued lines by four spaces +- Indent continued lines by two spaces - Do not align arguments of commands ```diff @@ -259,31 +260,28 @@ autocommand BufEnter #### Naming -In general, use `plugin-names-like-this`, `FunctionNamesLikeThis`, -`CommandNamesLikeThis`, `augroup_names_like_this`, `variable_names_like_this`. +- Keep them short and sweet. +- In general, use + - `plugin-names-like-this` + - `FunctionNamesLikeThis` + - `CommandNamesLikeThis` + - `augroup_names_like_this` + - `variable_names_like_this` -Always prefix variables with their scope. - -- `plugin-names-like-this` - Keep them short and sweet. -- `FunctionNamesLikeThis` - - Prefix script-local functions with s: - - Autoloaded functions may not have a scope prefix. - - Do not create global functions. Use autoloaded functions instead. -- `CommandNamesLikeThis` - Prefer succinct command names over common command prefixes. -- `variable_names_like_this` - Augroup names count as variables for naming purposes. +- Do not create global functions. Use autoloaded functions instead. +- Prefer succinct command names over common command prefixes. +- Augroup names count as variables for naming purposes. - Prefix all variables with their scope. - - Global variables with g: - - Script-local variables with s: - - Function arguments with a: - - Function-local variables with l: - - Vim-predefined variables with v: - - Buffer-local variables with b: - - g:, s:, and a: must always be used. - - b: changes the variable semantics; use it when you want buffer-local semantics. - - l: and v: should be used for consistency, future proofing, and to avoid subtle bugs. They are not strictly required. Add them in new code but don’t go out of your way to add them elsewhere. + - Global variables with g: + - Script-local variables with s: + - Function arguments with a: + - Function-local variables with l: + - Vim-predefined variables with v: + - Buffer-local variables with b: + - g:, s:, and a: must always be used. + - b: changes the variable semantics; use it when you want buffer-local semantics. + - l: and v: should be used for consistency, future proofing, and to avoid subtle bugs. They are not strictly required. Add them in new code but don’t go out of your way to add them elsewhere. + - Autoloaded functions may not have a scope prefix. ## Key notations @@ -293,9 +291,13 @@ Always prefix variables with their scope. - Use `/` for alternative sequences: `` / ``. - Use `Ctrl-e` rather than `` in documentation. -## Thanks: +## Vimscript Style + +- [Google Vimscript Style Guide](https://google.github.io/styleguide/vimscriptguide.xml) +- [Google Vimscript Guide](https://google.github.io/styleguide/vimscriptfull.xml) +- [Vim Scripting Style Guide](https://github.com/noahfrederick/vim-scripting-style-guide/blob/master/doc/scripting-style.txt) + +## Markdown Style + +- [Google's Markdown style guide](https://github.com/google/styleguide/blob/3591b2e540cbcb07423e02d20eee482165776603/docguide/style.md) -- link : -- link : -- link : -- [google's markdown style guide](https://github.com/google/styleguide/blob/3591b2e540cbcb07423e02d20eee482165776603/docguide/style.md)