mjbrownie / swapit

vim plugin: Extensible Keyword Swapper
39 stars 8 forks source link

Is it possible to add markdown header levels #, ##, ### as a swaplist #27

Closed kiryph closed 8 years ago

kiryph commented 8 years ago

I had another idea for a swaplist for markdown files:

I have tried two definitions in ~/.vim/after/ftplugin/markdown_swapit.vim:

1.

SwapList formats # ## ###

2.

let g:swap_lists = [
        \{'name':'formats', 'options':
        \['#','##' , '###']},
        \]

Unfortunately, both do not work. Why?

mjbrownie commented 8 years ago

Hi, I'm afraid it wont work as is. (It might work in visual mode) I originally wrote the command to match on the :he register.

  1. Matches the from your lists
  2. Performs what amounts to a viwp (visual-inner-word-paste) in ProcessMatches()

Note that is limited to alphanumeric. There is code to handle visual mode selections but it is a bit clunky.

So it is not good for non alpha lists like ( || && ) etc, which would be handy.

I think there have since been some other substitution scripts that might handle this (cycle.vim?) but I haven't looked at them.

I looked at changing the hack to something more general purpose but it's probably better off being rewritten in something like python.

You could also take advantage of the SwapitFallback(incrementor,Decrimentor) and write your own function. You would probably only need a few substitutes s/^#/##/ s/^##/### etc.

kiryph commented 8 years ago

Thanks for your reply.

Maybe you can add the information to the documentation of swapit that only alphanumeric keywords are allowed.

Indeed you were right that other plugins could handle non-alphanumeric letters. I have checked additional features I like:

Plugin dot-repeat Forward to speeddating
and builtin inc/dec
non-alphanum keywords
swapit yes yes no
bootleq/vim-cycle yes yes yes
zef/vim-cycle no no yes
switch.vim yes no yes
toggle.vim only toggle
no inc/dec
no yes

I guess I will give bootleq/vim-cycle a shot.

Update regarding first experiences with bootleq/vim-cycle:

By default 0/1 is toggled. Intefers with forwarding to speeddating. Remove it from the default list. My first configuration together with speeddating looks like:

" Plugins {{{1:
call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-speeddating'
Plug 'bootleq/vim-cycle'
call plug#end()
" Plugin Settings: {{{1
" Cycle: {{{2
nmap <silent> <C-A> <Plug>CycleNext
nmap <silent> <C-X> <Plug>CyclePrev
vmap <silent> <C-A> <Plug>CycleNext
vmap <silent> <C-X> <Plug>CyclePrev
map <silent> <Plug>CycleFallbackNext <Plug>SpeedDatingUp
map <silent> <Plug>CycleFallbackPrev <Plug>SpeedDatingDown
let g:cycle_default_groups = [
        \   [['true', 'false']],
        \   [['yes', 'no']],
        \   [['on', 'off']],
        \   [['+', '-']],
        \   [['>', '<']],
        \   [['"', "'"]],
        \   [['==', '!=']],
        \   [['and', 'or']],
        \   [["in", "out"]],
        \   [["up", "down"]],
        \   [["min", "max"]],
        \   [["get", "set"]],
        \   [["add", "remove"]],
        \   [["to", "from"]],
        \   [["read", "write"]],
        \   [["only", "except"]],
        \   [['without', 'with']],
        \   [["exclude", "include"]],
        \   [["asc", "desc"]],
        \   [["#", "##", "###"]],
        \   [['是', '否']],
        \   [['{:}', '[:]', '(:)'], 'sub_pairs'],
        \   [['(:)', '「:」', '『:』'], 'sub_pairs'],
        \   [['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday',
        \     'Friday', 'Saturday'], 'hard_case', {'name': 'Days'}],
        \ ]
" 2013-01-01
" #
" +
" true

And yes, everything I've tried works as expected: dot repeat of increment with count, non-alpha chars, forwarding to speeddating.

kiryph commented 8 years ago

Another note regarding incrementing/decrementing markdown header levels:

The plugin https://github.com/plasticboy/vim-markdown provides the functions :HeaderIncrease and :HeaderDecrease. However, I am not sure whether they can chained into ctrl-a/x as done with speeddating.