From 61476ef530c25f281300f9664c5962ebed2d47ca Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Thu, 20 Dec 2018 23:19:44 +0800 Subject: [PATCH] Improve align feature (#2213) --- autoload/SpaceVim/layers/edit.vim | 6 +- docs/cn/documentation.md | 112 ++++++++++++++--------------- docs/cn/layers/edit.md | 24 +++++++ docs/documentation.md | 116 +++++++++++++++--------------- docs/layers/edit.md | 24 +++++++ 5 files changed, 165 insertions(+), 117 deletions(-) diff --git a/autoload/SpaceVim/layers/edit.vim b/autoload/SpaceVim/layers/edit.vim index 364e0410f..c3ec1bb91 100644 --- a/autoload/SpaceVim/layers/edit.vim +++ b/autoload/SpaceVim/layers/edit.vim @@ -28,7 +28,7 @@ function! SpaceVim#layers#edit#plugins() abort \ ['haya14busa/vim-easyoperator-line'], \ ['editorconfig/editorconfig-vim', { 'merged' : 0, 'if' : has('python') || has('python3')}], \ ['osyo-manga/vim-jplus', { 'on_map' : '(jplus' }], - \ ['godlygeek/tabular', { 'on_cmd' : 'Tabularize'}], + \ ['godlygeek/tabular', { 'merged' : 0}], \ ['ntpeters/vim-better-whitespace', { 'on_cmd' : ['StripWhitespace', 'ToggleWhitespace', 'DisableWhitespace', 'EnableWhitespace']}], \ ] if executable('fcitx') @@ -80,7 +80,7 @@ function! SpaceVim#layers#edit#config() abort call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '.'], 'Tabularize /.', 'align region at .', 1) call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', ':'], 'Tabularize /:', 'align region at :', 1) call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', ';'], 'Tabularize /;', 'align region at ;', 1) - call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '='], 'Tabularize /=', 'align region at =', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '='], 'Tabularize /===\|<=>\|\(&&\|||\|<<\|>>\)=\|=\~[#?]\?\|=>\|[:+/*!%^=><&|.?-]\?=[#?]\?', 'align region at =', 1) call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '¦'], 'Tabularize /¦', 'align region at ¦', 1) call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', ''], 'Tabularize /|', 'align region at |', 1) call SpaceVim#mapping#space#def('nnoremap', ['x', 'd', 'w'], 'StripWhitespace', 'delete trailing whitespaces', 1) @@ -506,7 +506,7 @@ endif augroup spacevim_layer_edit au! - autocmd BufNewFile *.py call add_buffer_head() + autocmd BufNewFile * call add_buffer_head() augroup END let s:ft_head_tp = {} function! s:add_buffer_head() abort diff --git a/docs/cn/documentation.md b/docs/cn/documentation.md index 69905eeaa..ac9dca189 100644 --- a/docs/cn/documentation.md +++ b/docs/cn/documentation.md @@ -1514,62 +1514,62 @@ In highlight symbol transient state: 文本相关的命令 (以 `x` 开头): -| Key Binding | Description | | -| ------------- | -------------------------------------------------------------------- | --- | -| `SPC x a &` | align region at & | | -| `SPC x a (` | align region at ( | | -| `SPC x a )` | align region at ) | | -| `SPC x a [` | align region at \[ | | -| `SPC x a ]` | align region at ] | | -| `SPC x a {` | align region at { | | -| `SPC x a }` | align region at } | | -| `SPC x a ,` | align region at , | | -| `SPC x a .` | align region at . (for numeric tables) | | -| `SPC x a :` | align region at : | | -| `SPC x a ;` | align region at ; | | -| `SPC x a =` | align region at = | | -| `SPC x a ¦` | align region at ¦ | | -| `SPC x a |` | align region at | | -| `SPC x a a` | align region (or guessed section) using default rules (TODO) | | -| `SPC x a c` | align current indentation region using default rules (TODO) | | -| `SPC x a l` | left-align with evil-lion (TODO) | | -| `SPC x a L` | right-align with evil-lion (TODO) | | -| `SPC x a r` | align region using user-specified regexp (TODO) | | -| `SPC x a m` | align region at arithmetic operators `(+-*/)` (TODO) | | -| `SPC x c` | count the number of chars/words/lines in the selection region | | -| `SPC x d w` | delete trailing whitespaces | | -| `SPC x d SPC` | Delete all spaces and tabs around point, leaving one space | | -| `SPC x g l` | set lanuages used by translate commands (TODO) | | -| `SPC x g t` | translate current word using Google Translate | | -| `SPC x g T` | reverse source and target languages (TODO) | | -| `SPC x i c` | change symbol style to `lowerCamelCase` | | -| `SPC x i C` | change symbol style to `UpperCamelCase` | | -| `SPC x i i` | cycle symbol naming styles (i to keep cycling) | | -| `SPC x i -` | change symbol style to `kebab-case` | | -| `SPC x i k` | change symbol style to `kebab-case` | | -| `SPC x i _` | change symbol style to `under_score` | | -| `SPC x i u` | change symbol style to `under_score` | | -| `SPC x i U` | change symbol style to `UP_CASE` | | -| `SPC x j c` | set the justification to center (TODO) | | -| `SPC x j f` | set the justification to full (TODO) | | -| `SPC x j l` | set the justification to left (TODO) | | -| `SPC x j n` | set the justification to none (TODO) | | -| `SPC x j r` | set the justification to right (TODO) | | -| `SPC x J` | move down a line of text (enter transient state) | | -| `SPC x K` | move up a line of text (enter transient state) | | -| `SPC x l d` | duplicate line or region (TODO) | | -| `SPC x l s` | sort lines (TODO) | | -| `SPC x l u` | uniquify lines (TODO) | | -| `SPC x o` | use avy to select a link in the frame and open it (TODO) | | -| `SPC x O` | use avy to select multiple links in the frame and open them (TODO) | | -| `SPC x t c` | swap (transpose) the current character with the previous one | | -| `SPC x t w` | swap (transpose) the current word with the previous one | | -| `SPC x t l` | swap (transpose) the current line with the previous one | | -| `SPC x u` | set the selected text to lower case (TODO) | | -| `SPC x U` | set the selected text to upper case (TODO) | | -| `SPC x w c` | count the number of occurrences per word in the select region (TODO) | | -| `SPC x w d` | show dictionary entry of word from wordnik.com (TODO) | | -| `SPC x TAB` | indent or dedent a region rigidly (TODO) | | +| Key Binding | Description | +| ------------- | -------------------------------------------------------------------- | +| `SPC x a &` | align region at & | +| `SPC x a (` | align region at ( | +| `SPC x a )` | align region at ) | +| `SPC x a [` | align region at \[ | +| `SPC x a ]` | align region at ] | +| `SPC x a {` | align region at { | +| `SPC x a }` | align region at } | +| `SPC x a ,` | align region at , | +| `SPC x a .` | align region at . (for numeric tables) | +| `SPC x a :` | align region at : | +| `SPC x a ;` | align region at ; | +| `SPC x a =` | align region at = | +| `SPC x a ¦` | align region at ¦ | +| `SPC x a |` | align region at | +| `SPC x a a` | align region (or guessed section) using default rules (TODO) | +| `SPC x a c` | align current indentation region using default rules (TODO) | +| `SPC x a l` | left-align with evil-lion (TODO) | +| `SPC x a L` | right-align with evil-lion (TODO) | +| `SPC x a r` | align region using user-specified regexp (TODO) | +| `SPC x a m` | align region at arithmetic operators `(+-*/)` (TODO) | +| `SPC x c` | count the number of chars/words/lines in the selection region | +| `SPC x d w` | delete trailing whitespaces | +| `SPC x d SPC` | Delete all spaces and tabs around point, leaving one space | +| `SPC x g l` | set lanuages used by translate commands (TODO) | +| `SPC x g t` | translate current word using Google Translate | +| `SPC x g T` | reverse source and target languages (TODO) | +| `SPC x i c` | change symbol style to `lowerCamelCase` | +| `SPC x i C` | change symbol style to `UpperCamelCase` | +| `SPC x i i` | cycle symbol naming styles (i to keep cycling) | +| `SPC x i -` | change symbol style to `kebab-case` | +| `SPC x i k` | change symbol style to `kebab-case` | +| `SPC x i _` | change symbol style to `under_score` | +| `SPC x i u` | change symbol style to `under_score` | +| `SPC x i U` | change symbol style to `UP_CASE` | +| `SPC x j c` | set the justification to center (TODO) | +| `SPC x j f` | set the justification to full (TODO) | +| `SPC x j l` | set the justification to left (TODO) | +| `SPC x j n` | set the justification to none (TODO) | +| `SPC x j r` | set the justification to right (TODO) | +| `SPC x J` | move down a line of text (enter transient state) | +| `SPC x K` | move up a line of text (enter transient state) | +| `SPC x l d` | duplicate line or region (TODO) | +| `SPC x l s` | sort lines (TODO) | +| `SPC x l u` | uniquify lines (TODO) | +| `SPC x o` | use avy to select a link in the frame and open it (TODO) | +| `SPC x O` | use avy to select multiple links in the frame and open them (TODO) | +| `SPC x t c` | swap (transpose) the current character with the previous one | +| `SPC x t w` | swap (transpose) the current word with the previous one | +| `SPC x t l` | swap (transpose) the current line with the previous one | +| `SPC x u` | set the selected text to lower case (TODO) | +| `SPC x U` | set the selected text to upper case (TODO) | +| `SPC x w c` | count the number of occurrences per word in the select region (TODO) | +| `SPC x w d` | show dictionary entry of word from wordnik.com (TODO) | +| `SPC x TAB` | indent or dedent a region rigidly (TODO) | #### 文本插入命令 diff --git a/docs/cn/layers/edit.md b/docs/cn/layers/edit.md index 6d740e752..4d63156bb 100644 --- a/docs/cn/layers/edit.md +++ b/docs/cn/layers/edit.md @@ -11,6 +11,7 @@ lang: cn - [模块简介](#模块简介) - [功能特性](#功能特性) - [模块选项](#模块选项) +- [快捷键](#快捷键) @@ -30,3 +31,26 @@ lang: cn ## 模块选项 - `textobj`: specified a list of text opjects to be enabled, the avaliable list is :`indent`, `line`, `entire` + +## 快捷键 + +快捷键 | 功能描述 +--- | --- +`SPC x a {分隔符}` | 基于分隔符进行文本对齐 + +**默认的分隔符:** + +- `=`: 对齐 `===`, `==`, `!=`, `>=` 等 +- `&`: 对齐 `&` +- `¦`: 对齐 `¦` +- `;`: 对齐 `;` +- `:`: 对齐 `:` +- `,`: 对齐 `,` +- `.`: 对齐 `.` +- `[`: 对齐 `[` +- `(`: 对齐 `(` +- `{`: 对齐 `{` +- `]`: 对齐 `]` +- `}`: 对齐 `}` +- `)`: 对齐 `)` + diff --git a/docs/documentation.md b/docs/documentation.md index 5a621dafc..f172af9fd 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -323,7 +323,7 @@ use toml file to add custom forked plugins: ```toml [[custom_plugins]] - name = 'wsdjeg/neomake.vim' + name = "wsdjeg/neomake.vim" # note: you need to disable merged feature merged = false ``` @@ -400,7 +400,7 @@ to install it on your system if you wish to use it. To change the default font set the variable `guifont` in your `~/.SpaceVim.d/init.toml` file. By default its value is: ```toml - guifont = 'DejaVu Sans Mono for Powerline:h11' + guifont = "DejaVu Sans Mono for Powerline:h11" ``` If the specified font is not found, the fallback one will be used (depends on your system). @@ -1558,62 +1558,62 @@ In highlight symbol transient state: Text related commands (start with `x`): -| Key Binding | Description | | -| ------------- | -------------------------------------------------------------------- | --- | -| `SPC x a &` | align region at & | | -| `SPC x a (` | align region at ( | | -| `SPC x a )` | align region at ) | | -| `SPC x a [` | align region at \[ | | -| `SPC x a ]` | align region at ] | | -| `SPC x a {` | align region at { | | -| `SPC x a }` | align region at } | | -| `SPC x a ,` | align region at , | | -| `SPC x a .` | align region at . (for numeric tables) | | -| `SPC x a :` | align region at : | | -| `SPC x a ;` | align region at ; | | -| `SPC x a =` | align region at = | | -| `SPC x a ¦` | align region at ¦ | | -| `SPC x a |` | align region at | | -| `SPC x a a` | align region (or guessed section) using default rules (TODO) | | -| `SPC x a c` | align current indentation region using default rules (TODO) | | -| `SPC x a l` | left-align with evil-lion (TODO) | | -| `SPC x a L` | right-align with evil-lion (TODO) | | -| `SPC x a r` | align region using user-specified regexp (TODO) | | -| `SPC x a m` | align region at arithmetic operators `(+-*/)` (TODO) | | -| `SPC x c` | count the number of chars/words/lines in the selection region | | -| `SPC x d w` | delete trailing whitespaces | | -| `SPC x d SPC` | Delete all spaces and tabs around point, leaving one space | | -| `SPC x g l` | set lanuages used by translate commands (TODO) | | -| `SPC x g t` | translate current word using Google Translate | | -| `SPC x g T` | reverse source and target languages (TODO) | | -| `SPC x i c` | change symbol style to `lowerCamelCase` | | -| `SPC x i C` | change symbol style to `UpperCamelCase` | | -| `SPC x i i` | cycle symbol naming styles (i to keep cycling) | | -| `SPC x i -` | change symbol style to `kebab-case` | | -| `SPC x i k` | change symbol style to `kebab-case` | | -| `SPC x i _` | change symbol style to `under_score` | | -| `SPC x i u` | change symbol style to `under_score` | | -| `SPC x i U` | change symbol style to `UP_CASE` | | -| `SPC x j c` | set the justification to center (TODO) | | -| `SPC x j f` | set the justification to full (TODO) | | -| `SPC x j l` | set the justification to left (TODO) | | -| `SPC x j n` | set the justification to none (TODO) | | -| `SPC x j r` | set the justification to right (TODO) | | -| `SPC x J` | move down a line of text (enter transient state) | | -| `SPC x K` | move up a line of text (enter transient state) | | -| `SPC x l d` | duplicate line or region (TODO) | | -| `SPC x l s` | sort lines (TODO) | | -| `SPC x l u` | uniquify lines (TODO) | | -| `SPC x o` | use avy to select a link in the frame and open it (TODO) | | -| `SPC x O` | use avy to select multiple links in the frame and open them (TODO) | | -| `SPC x t c` | swap (transpose) the current character with the previous one | | -| `SPC x t w` | swap (transpose) the current word with the previous one | | -| `SPC x t l` | swap (transpose) the current line with the previous one | | -| `SPC x u` | set the selected text to lower case (TODO) | | -| `SPC x U` | set the selected text to upper case (TODO) | | -| `SPC x w c` | count the number of occurrences per word in the select region (TODO) | | -| `SPC x w d` | show dictionary entry of word from wordnik.com (TODO) | | -| `SPC x TAB` | indent or dedent a region rigidly (TODO) | | +| Key Binding | Description | +| ------------- | -------------------------------------------------------------------- | +| `SPC x a &` | align region at & | +| `SPC x a (` | align region at ( | +| `SPC x a )` | align region at ) | +| `SPC x a [` | align region at \[ | +| `SPC x a ]` | align region at ] | +| `SPC x a {` | align region at { | +| `SPC x a }` | align region at } | +| `SPC x a ,` | align region at , | +| `SPC x a .` | align region at . (for numeric tables) | +| `SPC x a :` | align region at : | +| `SPC x a ;` | align region at ; | +| `SPC x a =` | align region at = | +| `SPC x a ¦` | align region at ¦ | +| `SPC x a |` | align region at | +| `SPC x a a` | align region (or guessed section) using default rules (TODO) | +| `SPC x a c` | align current indentation region using default rules (TODO) | +| `SPC x a l` | left-align with evil-lion (TODO) | +| `SPC x a L` | right-align with evil-lion (TODO) | +| `SPC x a r` | align region using user-specified regexp (TODO) | +| `SPC x a m` | align region at arithmetic operators `(+-*/)` (TODO) | +| `SPC x c` | count the number of chars/words/lines in the selection region | +| `SPC x d w` | delete trailing whitespaces | +| `SPC x d SPC` | Delete all spaces and tabs around point, leaving one space | +| `SPC x g l` | set lanuages used by translate commands (TODO) | +| `SPC x g t` | translate current word using Google Translate | +| `SPC x g T` | reverse source and target languages (TODO) | +| `SPC x i c` | change symbol style to `lowerCamelCase` | +| `SPC x i C` | change symbol style to `UpperCamelCase` | +| `SPC x i i` | cycle symbol naming styles (i to keep cycling) | +| `SPC x i -` | change symbol style to `kebab-case` | +| `SPC x i k` | change symbol style to `kebab-case` | +| `SPC x i _` | change symbol style to `under_score` | +| `SPC x i u` | change symbol style to `under_score` | +| `SPC x i U` | change symbol style to `UP_CASE` | +| `SPC x j c` | set the justification to center (TODO) | +| `SPC x j f` | set the justification to full (TODO) | +| `SPC x j l` | set the justification to left (TODO) | +| `SPC x j n` | set the justification to none (TODO) | +| `SPC x j r` | set the justification to right (TODO) | +| `SPC x J` | move down a line of text (enter transient state) | +| `SPC x K` | move up a line of text (enter transient state) | +| `SPC x l d` | duplicate line or region (TODO) | +| `SPC x l s` | sort lines (TODO) | +| `SPC x l u` | uniquify lines (TODO) | +| `SPC x o` | use avy to select a link in the frame and open it (TODO) | +| `SPC x O` | use avy to select multiple links in the frame and open them (TODO) | +| `SPC x t c` | swap (transpose) the current character with the previous one | +| `SPC x t w` | swap (transpose) the current word with the previous one | +| `SPC x t l` | swap (transpose) the current line with the previous one | +| `SPC x u` | set the selected text to lower case (TODO) | +| `SPC x U` | set the selected text to upper case (TODO) | +| `SPC x w c` | count the number of occurrences per word in the select region (TODO) | +| `SPC x w d` | show dictionary entry of word from wordnik.com (TODO) | +| `SPC x TAB` | indent or dedent a region rigidly (TODO) | #### Text insertion commands diff --git a/docs/layers/edit.md b/docs/layers/edit.md index c07fcd8a4..0d71a4832 100644 --- a/docs/layers/edit.md +++ b/docs/layers/edit.md @@ -10,6 +10,7 @@ description: "Improve code edit expr in SpaceVim, provide more text opjects." - [Description](#description) - [Features](#features) - [Options](#options) +- [Key bindings](#key-bindings) @@ -29,3 +30,26 @@ This layer provide many edit key bindings for SpaceVim, and also porvide more te ## Options - `textobj`: specified a list of text opjects to be enabled, the avaliable list is :`indent`, `line`, `entire` + +## Key bindings + +Key binding | desc +--- | --- +`SPC x a {delimiter}` | align content based on delimiter + +**default delimiters** + +- `=`: align `===`, `==`, `!=`, `>=` etc. +- `&`: align `&` +- `¦`: align `¦` +- `;`: align `;` +- `:`: align `:` +- `,`: align `,` +- `.`: align `.` +- `[`: align `[` +- `(`: align `(` +- `{`: align `{` +- `]`: align `]` +- `}`: align `}` +- `)`: align `)` +