Align plugin - white space separators

9 views
Skip to first unread message

Chris Jones

unread,
Dec 25, 2009, 9:17:19 PM12/25/09
to vim...@googlegroups.com
Prettifying a color scheme, which looks like so:

------------------------------------------------------------------------
15 hi ErrorMsg ctermfg=9 cterm=none ctermfg=red etc...
16 hi Visual ctermbg=61 cterm=none ctermfg=bg
17 hi VisualNOS ctermbg=61 cterm=none ctermfg=bg
18 hi Underlined ctermfg=fg ctermbg=bg term=underline
------------------------------------------------------------------------

I wanted to end up with this:

------------------------------------------------------------------------
15 hi ErrorMsg ctermfg=9 cterm=none ctermfg=red
16 hi Visual ctermbg=61 cterm=none ctermfg=bg
17 hi VisualNOS ctermbg=61 cterm=none ctermfg=bg
18 hi Underlined ctermfg=fg ctermbg=bg term=underline
------------------------------------------------------------------------

I gave the Align plugin a shot and eventually did the following:

15,18s/\ \ \+/@/g
15,18s/\ /@/g
15,18Align @
15,18s/@/\ /g

Is there a more 'standard' way to do this?

Thanks,

CJ


Charles E Campbell Jr

unread,
Dec 26, 2009, 11:20:09 PM12/26/09
to vim...@googlegroups.com

:help alignmap-tsp

might help.

Regards,
Chip Campbell

Chris Jones

unread,
Dec 27, 2009, 4:09:49 AM12/27/09
to vim...@googlegroups.com

I had already read this, and experimented with it.

I selected the text via a Ctrl-V and issued a: ":Align \tsp" and nothing
happened.

Since I had tried many other things to get the plugin to align on white
spaces before I found alignmap-tsp, I did it again just to make sure and
saw the same result: the buffer is not modified.

I read (again) the intro at :h align-maps, sourced AlignMaps.vim to be
on the safe side, repeated the experience a couple of times, once with a
different test file containing:

------------------------------------------------------------------------
a b c d
a b c d
a b c d
------------------------------------------------------------------------

.. and still nothing happens.

I'm running Vim 7.1 on a debian lenny system and the plugin was
installed like so:

# vim-addons -v -w install align

In other words, it's the version of the plugin that ships with Vim,
installed by root, system-wide.

Thank you for your comments,

CJ

Charles Campbell

unread,
Dec 28, 2009, 10:35:01 AM12/28/09
to vim...@googlegroups.com

That's odd -- because it works for me, with your example as given
below. Now, although the Align command itself works with visually
selected blocks, the maps don't work with ctrl-v selected blocks (ie.
such visual blocks are treated as visually selected line ranges, like
"V"). One way to get the maps to work with visual blocks is with
vis.vim; you can get vis.vim from:

http://vim.sourceforge.net/scripts/script.php?script_id=1195 (stable)
http://mysite.verizon.net/astronaut/vim/index.html#VIS
(cutting edge)

With it, use ctrl-v to select the visual block and then :B \tsp (for
example).

> Since I had tried many other things to get the plugin to align on white
> spaces before I found alignmap-tsp, I did it again just to make sure and
> saw the same result: the buffer is not modified.
>
> I read (again) the intro at :h align-maps, sourced AlignMaps.vim to be
> on the safe side, repeated the experience a couple of times, once with a
> different test file containing:
>
> ------------------------------------------------------------------------
> a b c d
> a b c d
> a b c d
> ------------------------------------------------------------------------
>
> .. and still nothing happens.
>
> I'm running Vim 7.1 on a debian lenny system and the plugin was
> installed like so:
>
> # vim-addons -v -w install align
>
> In other words, it's the version of the plugin that ships with Vim,
> installed by root, system-wide.
>
>

Well, align/alignmaps doesn't come with vim, although it appears that
debian lenny adds it in on their own. That install procedure is also
not the standard way to install align/alignmaps, its a debian-lenny
"thing", and so I'm not familiar with it (I use fedora, myself). So to
determine why the alignmaps aren't working will take some investigation
(are plugin/AlignMapsPlugin.vim, autoload/AlignMaps.vim, etc in the
proper places, what is the result of :verbose map \tsp? etc), or
perhaps you could simply get the latest version
(http://mysite.verizon.net/astronaut/vim/index.html#ALIGN) and install it:

vim align.vba.gz
:so %
:q

Regards,
Chip Campbell


Chris Jones

unread,
Dec 29, 2009, 3:06:35 PM12/29/09
to vim...@googlegroups.com
On Mon, Dec 28, 2009 at 10:35:01AM EST, Charles Campbell wrote:
> Chris Jones wrote:

[..]

> > I selected the text via a Ctrl-V and issued a: ":Align \tsp" and
> > nothing happened.

------------------------------------------------------------------------


15 hi ErrorMsg ctermfg=9 cterm=none ctermfg=red etc...
16 hi Visual ctermbg=61 cterm=none ctermfg=bg
17 hi VisualNOS ctermbg=61 cterm=none ctermfg=bg
18 hi Underlined ctermfg=fg ctermbg=bg term=underline
------------------------------------------------------------------------

Actually, when I indent a few lines such as l. 15 and l. 17 above, the
plugin realigns them, so to speak.

------------------------------------------------------------------------
15 hi ErrorMsg ctermfg=9 cterm=none ctermfg=red etc...
16 hi Visual ctermbg=61 cterm=none ctermfg=bg
17 hi VisualNOS ctermbg=61 cterm=none ctermfg=bg
18 hi Underlined ctermfg=fg ctermbg=bg term=underline
------------------------------------------------------------------------

So it looks like it's doing something but it's limited to aligning the
each line's leading white space?

Or am I misunderstanding what the plugin does or can do when the
separator is white space?

If you take line 15 above for instance, there are seven spaces after
ErrorMSg, while line 16 has fourteen between Visual and ctermbg=61.

What's the plugin supposed to do?

The right thing to do as I see it would be to collapse all contiguous
spaces so that there is only one space separating fields, and then
expand them so that field1, field2, field3, etc. on each line starts in
the same column.

But then that's because that's what _I_ want the plugin to do for me in
this particular case.. :-)

> That's odd -- because it works for me, with your example as given
> below.

Never underestimate the creative powers of the User.

> Now, although the Align command itself works with visually selected
> blocks, the maps don't work with ctrl-v selected blocks (ie. such
> visual blocks are treated as visually selected line ranges, like "V").
> One way to get the maps to work with visual blocks is with vis.vim;
> you can get vis.vim from:

> With it, use ctrl-v to select the visual block and then :B \tsp (for
> example).

Yes, but I'm not using any kind of selection - I'm using the syntax as
defined in the help file:

:[range]Align \tsp
:[range]Align \Tsp
:[Range]Align \tsq ... etc.

[..]

> So to determine why the alignmaps aren't working will take some
> investigation (are plugin/AlignMapsPlugin.vim, autoload/AlignMaps.vim,
> etc in the proper places, what is the result of :verbose map \tsp?
> etc), or perhaps you could simply get the latest version

> (http://mysite.verizon.net/astronaut/vim/index.html#ALIGN)

> and install it:
>
> vim align.vba.gz
> :so %
> :q

Had done that just in case, but it gets me a screenful of messages where
all the <leader>xx's installed by the plugin are already mapped. I had
removed the 'lenny' version, and started a fresh instance of Vim, so I
don't know.

Anyway the version from your web site does exactly the same, just
removes leading blanks on every line that happens to have them.

The more I think about it, it's probably me misunderstanding what the
plugin should be doing when spaces are used as separators.

Thanks,

CJ

Charles Campbell

unread,
Dec 29, 2009, 3:34:15 PM12/29/09
to vim...@googlegroups.com
Sorry about the html, folks -- but to show alignment properly, the email can't be using variable width fonts...


Chris Jones wrote:
------------------------------------------------------------------------
15 hi ErrorMsg ctermfg=9 cterm=none ctermfg=red etc...
16 hi Visual ctermbg=61 cterm=none ctermfg=bg
17            hi VisualNOS           ctermbg=61  cterm=none ctermfg=bg   
18 hi Underlined     ctermfg=fg ctermbg=bg  term=underline   
-----------------------------------------------------------------------
This is what I got after using \tsp:

  
-----------------------------------------------------------------------
15 hi ErrorMsg   ctermfg=9  cterm=none ctermfg=red    etc...
16 hi Visual     ctermbg=61 cterm=none ctermfg=bg
17 hi VisualNOS  ctermbg=61 cterm=none ctermfg=bg
18 hi Underlined ctermfg=fg ctermbg=bg term=underline
------------------------------------------------------------------------

So it looks like it's doing something but it's limited to aligning the
each line's leading white space?
  

Hardly.  The fields, as shown above, are aligned with spaces appropriately intercalated.  Initial whitespace is another issue; there are three options for dealing with it (see :help alignctrl-w, alignctrl-W, and alignctrl-I).

Or am I misunderstanding what the plugin does or can do when the
separator is white space?
  

I suspect that you have some option set that I don't (or possibly vice versa) that's interfering.  Perhaps you could try having the following in a file called "simple.vimrc":

set nocp
syn on
filetype plugin on

and using   vim -u simple.vimrc yourtestfile

and \tsp with it.  This will still load all your current plugins, one of which may somehow be interfering with Align.



Yes, but I'm not using any kind of selection - I'm using the syntax as
defined in the help file:

:[range]Align \tsp
:[range]Align \Tsp
:[Range]Align \tsq ... etc.

[..]
  

From an earlier note you'd said that you selected lines using ctrl-v.  That's visual block selection; the alignmaps will treat that the same as "V" (visual line selection).  It results in a range of lines.

  
So to determine why the alignmaps aren't working will take some
investigation (are plugin/AlignMapsPlugin.vim, autoload/AlignMaps.vim,
etc in the proper places, what is the result of   :verbose map \tsp?
etc), or perhaps you could simply get the latest version 
    
  
(http://mysite.verizon.net/astronaut/vim/index.html#ALIGN) 
    
  
and install it:

  vim align.vba.gz
  :so %
  :q
    
Had done that just in case, but it gets me a screenful of messages where
all the <leader>xx's installed by the plugin are already mapped. I had
removed the 'lenny' version, and started a fresh instance of Vim, so I
don't know.
  

Something in your setup is definitely odd.  All of the vim script portions of the various Align files are protected against double-loading; ie. for autoload/Align.vim, at the beginning is:

if exists("g:loaded_Align") || &cp
 finish
endif

This snippet essentially says that "if the autoload/Align.vim has already been loaded, don't load it again".  Your home directory is normally loaded first, so it should have prevented the systemwide lenny version from interfering.

Anyway the version from your web site does exactly the same, just
removes leading blanks on every line that happens to have them. 

The more I think about it, it's probably me misunderstanding what the
plugin should be doing when spaces are used as separators.
  
Again, what does

  :verbose map \tsp?

show (that question mark needs to be there)? 

Regards,
Chip Campbell

Chris Jones

unread,
Dec 29, 2009, 3:46:22 PM12/29/09
to vim...@googlegroups.com
On Tue, Dec 29, 2009 at 03:34:15PM EST, Charles Campbell wrote:

[..]

> Again, what does
>
> :verbose map \tsp?
>
> show (that question mark needs to be there)?

v \tsp :<BS><BS><BS><CR>ma'>\tsp
Last set from ~/.vim/plugin/AlignMaps.vim
no \tsp <SNR>11_WS:'a,.s/^\(\s*\)\(.*\)/\=submatch(1).escape(substitute(submatch(2),'\s\+','@','g'),'\')/<CR>:AlignCtrl mI=lp0P0 @<CR>:'a,.Align<CR>:'y+1,'z-1s/@/ /g<CR><SNR>11_WE
Last set from ~/.vim/plugin/AlignMaps.vim

Thanks,

CJ

Reply all
Reply to author
Forward
0 new messages