项目作者: monaqa

项目描述 :
Increment/decrement plugin using denops.vim
高级语言: TypeScript
项目地址: git://github.com/monaqa/dps-dial.vim.git
创建时间: 2021-07-12T13:35:46Z
项目社区:https://github.com/monaqa/dps-dial.vim

开源协议:MIT License

下载


dps-dial.vim: Extended increment/decrement plugin

日本語版はこちら

NOTICE: This plugin is work-in-progress yet. User interface is subject to
change without notice.

Extended increment/decrement plugin for
Vim/Neovim.
Written in Deno, using
denops.vim.

This plugin is a reimplementation of
dial.nvim plugin for the following
purposes:

  • To support both Vim and Neovim
  • For ease of development and debugging

Installation

This plugin depends on Deno and
denops.vim.

  1. Plug 'vim-denops/denops.vim'
  2. Plug 'monaqa/dps-dial.vim'

Usage

By adding the following description to the configuration file, you can change
the behavior of <C-a> and <C-x>:

  1. nmap <C-a> <Plug>(dps-dial-increment)
  2. nmap <C-x> <Plug>(dps-dial-decrement)
  3. xmap <C-a> <Plug>(dps-dial-increment)
  4. xmap <C-x> <Plug>(dps-dial-decrement)
  5. xmap g<C-a> g<Plug>(dps-dial-increment)
  6. xmap g<C-x> g<Plug>(dps-dial-decrement)

Features

Increment/Decrement/Toggle Non-Numeric Strings

You can perform string operations according to the following rules:

  • Date Increase/Decrease

    • If you press 7<C-a> on 25 in 2021/08/25, you will get the date one
      week later, 2021/09/01.
    • For the same string as above, pressing 7<C-a> on 08, then you will get
      the date seven months later, 2022/03/25.
  • Toggle between camelCase and snake_case

    • You can toggle the notation (camelCase, snake_case, etc.) of identifier
      under the cursor.
    • You need to tweak the configuration values such as g:dps_dial#augends.
  • Switch arbitrary words

    • You can switch between words with a several number of candidates, such as
      ['true', 'false'] or [ 'Mon', 'Tue', ..., 'Sun' ].
    • You need to tweak the configuration values such as g:dps_dial#augends.
  • User extension

    • You can create arbitrary rule with Vim script.

Dot-Repeat

Unlike the standard dot repeating in <C-a> / <C-x>, dps-dial.vim provides
dot repeating with a fixed increment/decrement rule. For example, suppose you
have a buffer like the following, and you want to move all due dates back one
month:

  1. date: 2020/11/08
  2. ...
  3. due date of 1st report: 2020/11/23
  4. ...
  5. due date of 2nd report: 2020/12/21
  6. ...
  7. date of exam: 2021/01/14

In dps-dial.vim, it can be achieved by the following simple operations:

  1. Move the 11 in the first line 2020/11/08 and press <C-a> (this will
    change the date in the first line to 2020/12/08)
  2. Search for date and jump to the third line at date
  3. Do dot-repeat . (this will change the date in the third line to
    2020/12/23)
  4. Do n.n. (the date will be incremented by one month for line 5 and 7 as
    well)

Note that if you press <C-a> at step3, the 1 part of 1st will be
incremented. Dot-repeat remembers that the previous operation was to increment
the month of the date by one, so you can skip the number 1st and just
increment the date.

Configure Augend Rules

The increment/decrement is done according to the rules set in
g:dps_dial#augends.

  1. function! s:dps_dial_settings() abort
  2. let g:dps_dial#augends += ['boolean']
  3. call extend(g:dps_dial#aliases, {
  4. \ 'boolean': {
  5. \ 'kind': 'constant',
  6. \ 'opts': {
  7. \ 'elements': ['true', 'false'],
  8. \ 'word': v:true,
  9. \ 'cyclic': v:true,
  10. \ },
  11. \ },
  12. \ })
  13. endfunction
  14. autocmd User DenopsPluginPost:dial call <SID>dps_dial_settings()

Note that if there is a buffer-local variable b:dps_dial_augends, it will be
used as the configuration.

  1. autocmd FileType python let b:dps_dial#augends = ['decimal', {'kind': 'constant', 'opts': {'elements': ['True', 'False']}}]

Specify Augend Rules with Register Name

  • If you type "x<C-a> instead of <C-a>, the increment will be performed
    according to the rules written in g:dps_dial#augends#register#x instead of
    g:dps_dial#augends.
  • If you type "1<C-a> instead of <C-a>, the behavior of subsequent
    dot-repeat will be cumulative. That is, each time a dot-repeat is executed,
    the addend is increased by one.
  • If you type "X<C-a> instead of <C-a>, the increment will be performed
    according to the rules written in g:dps_dial#augends#register#x instead of
    g:dps_dial#augends, and the behavior of subsequent dot-repeat will be
    cumulative.

Other Features

See vim help for a list of augend and aliases (currently only Japanese).

  1. :help dps-dial.txt

LICENSE

MIT