Text objects for line and inner-line

1 Point

Karolis Koncevičius Karolis Koncevičius

4 years ago

Text objects for lines.

Results are similar to the _ motion, but differs in a few ways:

1) Separates "al" and "il": "al" works on whole line, while "il" preserves indentation and line break. e.g. dal would be the same as d_ but dil would preserve indentation and leave an empty line behind.

2) In visual mode select that many lines instead of extending the region. e.g. 2al in visual mode would select 2 lines, while 2_ in visual mode would extend the selection by one line, since it's a motion.

onoremap <silent> <expr> al v:count==0 ? ":<c-u>normal! 0V$h<cr>" : ":<c-u>normal! V" . (v:count) . "jk<cr>"
vnoremap <silent> <expr> al v:count==0 ? ":<c-u>normal! 0V$h<cr>" : ":<c-u>normal! V" . (v:count) . "jk<cr>"
onoremap <silent> <expr> il v:count==0 ? ":<c-u>normal! ^vg_<cr>" : ":<c-u>normal! ^v" . (v:count) . "jkg_<cr>"
vnoremap <silent> <expr> il v:count==0 ? ":<c-u>normal! ^vg_<cr>" : ":<c-u>normal! ^v" . (v:count) . "jkg_h<cr>"