Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: block text object #25

Open
IngoMeyer441 opened this issue Jul 3, 2020 · 0 comments
Open

Feature request: block text object #25

IngoMeyer441 opened this issue Jul 3, 2020 · 0 comments

Comments

@IngoMeyer441
Copy link

Thank you very much for this project. It makes working with source code much easier. 🙂
Often, I find myself positioning the text cursor on the top line of an indent region (the line before the next indent level starts). So, I have to go down one line before I can use ii, ai and so on. So I created a simple patch to add block mappings (ab, ib, aB, iB) which increment the line number by one and then call your mappings. That works quite well, but it is an ugly hack. That is my current patch:

diff --git a/plugin/indent-object.vim b/plugin/indent-object.vim
index bd4075e..d276f81 100644
--- a/plugin/indent-object.vim
+++ b/plugin/indent-object.vim
@@ -36,6 +36,20 @@ onoremap <silent>iI :<C-u>cal <Sid>HandleTextObjectMapping(1, 1, 0, [line("."),
 vnoremap <silent>aI :<C-u>cal <Sid>HandleTextObjectMapping(0, 1, 1, [line("'<"), line("'>"), col("'<"), col("'>")])<CR><Esc>gv
 vnoremap <silent>iI :<C-u>cal <Sid>HandleTextObjectMapping(1, 1, 1, [line("'<"), line("'>"), col("'<"), col("'>")])<CR><Esc>gv
 
+" Simple extra mappings for a block object (the current/selected line is interpreted as top line)
+" Mappings excluding line below.
+onoremap <silent>ab :<C-u>cal <Sid>HandleTextObjectMapping(0, 0, 0, [line(".")+1, line(".")+1, col("."), col(".")])<CR>
+onoremap <silent>ib :<C-u>cal <Sid>HandleTextObjectMapping(1, 0, 0, [line(".")+1, line(".")+1, col("."), col(".")])<CR>
+vnoremap <silent>ab :<C-u>cal <Sid>HandleTextObjectMapping(0, 0, 1, [line("'<")+1, line("'>")+1, col("'<"), col("'>")])<CR><Esc>gv
+vnoremap <silent>ib :<C-u>cal <Sid>HandleTextObjectMapping(1, 0, 1, [line("'<")+1, line("'>")+1, col("'<"), col("'>")])<CR><Esc>gv
+
+" Mappings including line below.
+onoremap <silent>aB :<C-u>cal <Sid>HandleTextObjectMapping(0, 1, 0, [line(".")+1, line(".")+1, col("."), col(".")])<CR>
+onoremap <silent>iB :<C-u>cal <Sid>HandleTextObjectMapping(1, 1, 0, [line(".")+1, line(".")+1, col("."), col(".")])<CR>
+vnoremap <silent>aB :<C-u>cal <Sid>HandleTextObjectMapping(0, 1, 1, [line("'<")+1, line("'>")+1, col("'<"), col("'>")])<CR><Esc>gv
+vnoremap <silent>iB :<C-u>cal <Sid>HandleTextObjectMapping(1, 1, 1, [line("'<")+1, line("'>")+1, col("'<"), col("'>")])<CR><Esc>gv
+
+
 let s:l0 = -1
 let s:l1 = -1
 let s:c0 = -1

What do you think? Is this a feature that would be useful to others? Does a simple way exist to integrate this in your existing code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant