idbrii / textobj-word-column.vim

Adds text-objects for word-based columns in Vim.
17 stars 4 forks source link

Questions #5

Closed mg979 closed 4 years ago

mg979 commented 6 years ago

With this code:

""""""""""""""""""""""""""""""""""""""""""""""""""
" q/Q
""""""""""""""""""""""""""""""""""""""""""""""""""

nmap <C-q>      <Plug>RecordMacro
nmap Q          @q
nmap qq         <C-q>q

nmap qw         ciw
nmap qF         :CtrlSF <C-r><C-w><cr>
nmap qp         <C-d>mip
nmap qf         <C-d>mif
nmap qcp        vip<C-c>
nmap qci        vii<C-c>
nmap qcf        vif<C-c>
nmap qcc        vic<C-c>
nmap q}         v}h<C-c>
nmap q]         gw
nmap q[         gW
xmap q]         gw
xmap q[         gW
nnoremap qt     xp

Assuming cursor is at line 14 col 1, is it possible to make it behave like this?

Imgur

Currently it does the same for vic and viC (and vac / vaC), I would have at least expected that vic selected a block of the width of the nmap word, if pressed on it. Instead it gets the width of nnoremap. Also, I have a bug: if I put the cursor on line 22 (on nnoremap) and press vac two times, it selects different block widths.

idbrii commented 6 years ago

First question: what commit are you on?

vic: No, because vic would select all 4-character maps including ones above your cursor.

vac: No, because it should include ones above your cursor. (I would have expected it to select the whitespace.)

viC: No, because it should expand the search to all nonwhitespace (WORD), so it wouldn't expand beyond the space.

vaC: No, because it should expand the search to all nonwhitespace (WORD).

The commands map to the iw/iW motions: They should work as if you did the w equivalent, and then looked up and down for matches. So vic would be like viw followed by column pattern matching.

I can't remember if vac is supposed to be like vaw (docs say it is, behavior says otherwise) or if it's supposed to be a more precise match.

If you want to see the difference between vic and viC, try putting on line 18 col 6. You should see all q selected or both characters selected.

In terms of customizing word-column to do what you want, I don't see how you'd detect to skip the first whitespace without skipping the second whitespace and then just select the whole line. Allow skipping one whitespace character?

Instead, you can vic to find the largest matching column, which is adjacent to text that makes a larger column (nnoremap). Use o to flip to the bottom of selection, move down one to nnoremap, leave visual mode, and vic to get your selection. This workflow could be improved by making ic in visual mode just leave visual mode and execute vic.

vic selected a block of the width of the nmap word, if pressed on it. Instead it gets the width of nnoremap

Hm. That's not the behaviour I see. You're just using :TextobjWordcolumnDefaultKeyMappings and no configuration? Can you post a screenshot of what you see? Does it occur with barebones vim (just tpope/sensible.vim and kana/vim-textobj-user and idbrii/textobj-word-column.vim)?

Also, I have a bug: if I put the cursor on line 22 (on nnoremap) and press vac two times, it selects different block widths.

Try doing vipvip. That's not how vim's selection works: You only do v once. However, word-column doesn't properly support expanding search (I think it redoes the search at the start of the selection). The above workflow improvement might be a good way of nonbroken support for "expanding" search.