4

Sometimes, I need to delete until a character up or down the same column.

Consider a file with the following content:

abc
def
hij

When cursor is on b, doing a column-wise dfi should remove characters b, e and i. That means only the 1-character-width column of characters should be deleted.

Is it possible to do column-wise find and till?

  • Should only the 1-character-width column of characters be deleted, or all text in between the current cursor position and the target character in the same column? – Janis Jul 13 '15 at 0:59
5

You can use the vim-columnmove plugin and visual-mode block-wise selection to do this. The plugin imitates various groups of motions, and in this case:

columnmove-f


columnmove-f and its variants are the commands for bringing cursor to the position assigned by a character in the same column.

This group has six keymappings, that is, columnmove-f, columnmove-t, columnmove-F, columnmove-T, columnmove-;, columnmove-,. Each of them are the imitations of f, t, F, T, ;, , commands, but work in vertical direction.

The motions are mapped to <M-f/F/t/F> by default, but since those combinations were interpreted as something else in my case, I used <Leader>:

map <leader>f <Plug>(columnmove-f)
map <leader>F <Plug>(columnmove-F)
map <leader>t <Plug>(columnmove-t)
map <leader>T <Plug>(columnmove-T)

Then, by pressing d<C-v>\ti, I could delete the characters b, and e. Without block visual mode, it deletes the first and second lines.

  • columnmove-f may be remapped in order to achieve things like d<m-f>i to delete along the column until the i character. I.e., one can do omap <m-f> <c-v><plug>(columnmove-f) (and similar for the other motions). I find this to be quite useful. – Karl Yngve Lervåg Jul 14 '15 at 21:18
2

To quickly do this without the need for plugins:

<C-v>/i<cr>x

<C-v> to enter column mode

/i<cr> to search for i

x to delete the visually selected block

  • This works great when "i" is the only character between cursor and the target. Consider: abci\nhij, when cursor in on b. two search for i is necessary to get to the target character since search is linewise. – cychoi Jul 14 '15 at 20:18
  • If you want to "delete from the current position to the next instance of i on another line starting on the current column" then just stick a j after the <C-v>. – user859 Jul 14 '15 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.