Skip to content

Feature request: block text object#25

Description

@IngoMeyer441

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions