[patch] Text object for entire buffer

11 views
Skip to first unread message

Andy Spencer

unread,
Apr 13, 2009, 3:18:43 AM4/13/09
to vim...@vim.org
This adds a text object ('aa' or 'ii') for the entire buffer. I don't
know if this is worthy of being included by default, but I find it
convenient for things such as gqaa and =aa.
vim-aa.patch

Ingo Karkat

unread,
Apr 13, 2009, 6:04:07 AM4/13/09
to vim...@googlegroups.com

Nice idea, certainly useful! I'm not sure whether this should be implemented in
the C code, though, as it could also be done with Vimscript.
One suggestion: How about changing 'ii' so that it excludes empty lines at the
beginning and end of the buffer, similar to what the other text objects do? I
don't like it when outer and inner text object versions are identical.

-- regards, ingo

Erik Falor

unread,
Apr 14, 2009, 12:22:05 PM4/14/09
to vim...@googlegroups.com
On Mon, Apr 13, 2009 at 12:04:07PM +0200, Ingo Karkat wrote:
>
> On 13-Apr-09 9:18, Andy Spencer wrote:
> > This adds a text object ('aa' or 'ii') for the entire buffer. I don't
> > know if this is worthy of being included by default, but I find it
> > convenient for things such as gqaa and =aa.
>
> Nice idea, certainly useful! I'm not sure whether this should be implemented in
> the C code, though, as it could also be done with Vimscript.

It may as well be in the C code alongside all of the other text
objects. Notice the cases just below his patch which are waiting to
be implemented.


> One suggestion: How about changing 'ii' so that it excludes empty lines at the
> beginning and end of the buffer, similar to what the other text objects do? I
> don't like it when outer and inner text object versions are identical.

I agree with Ingo here. The 'ii' object should trim leading and
trailing whitespace.

--
Erik Falor
Registered Linux User #445632 http://counter.li.org

Andy Spencer

unread,
Apr 15, 2009, 1:22:17 AM4/15/09
to vim...@googlegroups.com
> > Nice idea, certainly useful! I'm not sure whether this should be
> > implemented in the C code, though, as it could also be done with
> > Vimscript.
>
> It may as well be in the C code alongside all of the other text
> objects. Notice the cases just below his patch which are waiting to
> be implemented.

I agree that it should be done in the same place as the rest of the text
objects. However, I'm curious how it would be implemented in vimscript?
I didn't know it was even possible to implement something like text
objects in vimscript.


> One suggestion: How about changing 'ii' so that it excludes empty
> lines at the beginning and end of the buffer, similar to what the
> other text objects do? I don't like it when outer and inner text
> object versions are identical.

I guess consistency would be nice. I've attached an updated patch.

vim-aa-r1.patch

Tony Mechelynck

unread,
Apr 15, 2009, 1:41:29 AM4/15/09
to vim...@googlegroups.com
On 15/04/09 07:22, Andy Spencer wrote:
>>> Nice idea, certainly useful! I'm not sure whether this should be
>>> implemented in the C code, though, as it could also be done with
>>> Vimscript.
>>
>> It may as well be in the C code alongside all of the other text
>> objects. Notice the cases just below his patch which are waiting to
>> be implemented.
>
> I agree that it should be done in the same place as the rest of the text
> objects. However, I'm curious how it would be implemented in vimscript?
> I didn't know it was even possible to implement something like text
> objects in vimscript.

I believe the following are relevant:

:help omap-info
:help v:operator

Best regards,
Tony.
--
login: yes
password: I don't know, please tell me
password is incorrect
login: yes
password: incorrect

ka...@whileimautomaton.net

unread,
Apr 15, 2009, 1:59:00 AM4/15/09
to vim...@googlegroups.com
On Apr 15, 2:22 pm, Andy Spencer <spenc...@rose-hulman.edu> wrote:
> I agree that it should be done in the same place as the rest of the text
> objects. However, I'm curious how it would be implemented in vimscript?
> I didn't know it was even possible to implement something like text
> objects in vimscript.
Here you are.
Note that it requires textobj-user: http://www.vim.org/scripts/script.php?script_id=2100
vim-textobj-entire-0.0.0.zip

Andy Wokula

unread,
Apr 15, 2009, 3:43:04 AM4/15/09
to vim...@googlegroups.com
Andy Spencer schrieb:

" these text objects are linewise

noremap <silent> aa :<C-U>norm! ggVG<CR>
noremap <silent> ii :<C-U>call InnerBuf()<CR>

nunmap aa
sunmap aa
nunmap ii
sunmap ii

func! InnerBuf()
let line1 = nextnonblank(1)
if line1 == 0
" the buffer is blank, select it like with aa
norm! ggVG
return
endif
exec "norm!" line1."ggV". prevnonblank("$")."G"
endfunc


--
Andy

Ingo Karkat

unread,
Apr 16, 2009, 5:21:34 AM4/16/09
to vim...@googlegroups.com
On 13-Apr-09 9:18, Andy Spencer wrote:

I've given this some more thought, and I would like to propose different keys
for this feature. First off, 'aa' and 'ii' look like suitable keys, but all
other Vim text objects use the same second key to describe the object, and
prepend 'a' / 'i' to mean "a" or "inner" scope, respectively. (E.g. 'ap' / 'ip'
: a / inner paragraph. )
Secondly, I have a script (posted long ago as a vimtip) that defines 'ai' / 'ii'
text objects for selection of outer / inner indent. I think that something like
"inner indent" is a better fit for the 'ii' mnemonic than "entire buffer,
excluding leading / trailing empty lines".
How about using 'b' for buffer, resulting in 'ab' and 'ib' keys? 'b' already
stands for "buffer" in commands like :bnext, the resulting mnemonics would fit
into the existing naming scheme for text object, they're still free, and only
slightly more awkward to type.
As always, users who want 'aa' / 'ii' or any other keys can define a simple
mapping to remap 'ab' / 'ib'; but IMO the default keys should be consistent with
the other text objects.

-- regards, ingo

Maxim Kim

unread,
Apr 16, 2009, 8:17:50 AM4/16/09
to vim_dev
On 16 апр, 13:21, Ingo Karkat <sw...@ingo-karkat.de> wrote:
> How about using 'b' for buffer, resulting in 'ab' and 'ib' keys? 'b' already
> stands for "buffer" in commands like :bnext, the resulting mnemonics would fit
> into the existing naming scheme for text object, they're still free, and only
> slightly more awkward to type.

I would like 'ab' and 'ib' keys to have the same meaning as of today
-- a/inner block.
:h ib

Regards, Maxim.

Ingo Karkat

unread,
Apr 16, 2009, 9:36:03 AM4/16/09
to vim...@googlegroups.com
Oops, didn't know about that overload of 'a)'... So, any other suggestions? 'af'
(for "file"), 'aB' (captial B for "big buffer")?

As memorizable keys become scarce, maybe it would be best to just take the
Vimscript implementation that Matt has posted, and just define <Plug> mappings,
so that everyone is free to select whatever keys suit him/her.

-- regards, ingo

Maxim Kim

unread,
Apr 16, 2009, 9:47:56 AM4/16/09
to vim_dev
On 16 апр, 17:36, Ingo Karkat <sw...@ingo-karkat.de> wrote:
> On 16-Apr-09 14:17, Maxim Kim wrote:> On 16 апр, 13:21, Ingo Karkat <sw...@ingo-karkat.de> wrote:
> Oops, didn't know about that overload of 'a)'... So, any other suggestions? 'af'
> (for "file"), 'aB' (captial B for "big buffer")?
No luck with "big buffer" too
:h aB

But 'af' is free of use now.

Regards, Maxim.

Ingo Karkat

unread,
Apr 16, 2009, 10:28:01 AM4/16/09
to vim...@googlegroups.com
It's really unfortunate that so many text object mappings are already taken.
'a{', 'a}' and 'aB' all represent the same text object, yet I have never used
any of them (yet). Fortunately, it is possible to :noremap things so that they
suit one's personal mental model.
As there are quite some ideas and pending TODOs for text objects, this problem
(of finding memorizable mappings) will only get worse, I'm afraid.

-- regards, ingo

Kana Natsuno

unread,
Apr 16, 2009, 11:05:30 AM4/16/09
to vim...@googlegroups.com
On Thu, 16 Apr 2009 22:36:03 +0900, Ingo Karkat <sw...@ingo-karkat.de> wrote:
> Oops, didn't know about that overload of 'a)'... So, any other suggestions? 'af'
> (for "file"), 'aB' (captial B for "big buffer")?
>
> As memorizable keys become scarce, maybe it would be best to just take the
> Vimscript implementation that Matt has posted, and just define <Plug> mappings,
> so that everyone is free to select whatever keys suit him/her.

I use af/if for text objects to select a function.
So, how about ae/ie as alternatives?
Because the text objects are to select the *E*ntire buffer.

Anyhow, for some reason, my previous post to this thread
seemed not to be sent as an e-mail. How about this?
http://groups.google.com/group/vim_dev/msg/36535509c06564c1


--
To Vim, or not to Vim.
http://whileimautomaton.net/

Ingo Karkat

unread,
Apr 16, 2009, 11:33:46 AM4/16/09
to vim...@googlegroups.com
On 16-Apr-09 17:05, Kana Natsuno wrote:
> I use af/if for text objects to select a function.
Funny, I use 'am' / 'im' ("method"), similar to the ]m movements.

> Anyhow, for some reason, my previous post to this thread
> seemed not to be sent as an e-mail. How about this?
> http://groups.google.com/group/vim_dev/msg/36535509c06564c1

I received your email; Matt later posted a very short Vimscript that seems to
achieve the same with less dependencies.

-- regards, ingo

Tony Mechelynck

unread,
Apr 17, 2009, 9:07:23 AM4/17/09
to vim...@googlegroups.com

What about iG

because G goes to the end of the buffer (linewise to the last line), and
1G (or gg) to its beginning.

I've checked that there's no iG help tag.


Best regards,
Tony.
--
Has your family tried 'em?

POWDERMILK BISCUITS

Heavens, they're tasty and expeditious!

They're made from whole wheat, to give shy persons the
strength to get up and do what needs to be done.

POWDERMILK BISCUITS

Buy them ready-made in the big blue box with the picture of the
biscuit on the front, or in the brown bag with the dark stains
that indicate freshness.

Reply all
Reply to author
Forward
0 new messages