I'm trying to do two things involving blank lines (empty lines or lines with only white-space on them).
- Move to the next blank line (or EOF if none)
- Filter (using
!
) to the next blank line (or EOF if none)
Number 1 is similar to }
, but allows for lines with only white-space. I thought number 2 would be easy if I could do number 1. But unfortunately, reality has intervened.
Here is the .vimrc
that I have so far to test my mapping (using nl -ba
as a test filter):
set nocompatible
set list " to distinguish empty lines from blank lines
map } :<C-u>call search('^\s*$\\|\%$', 'W')<CR>
map - !}nl -ba<CR>}
Creating a test file with some data, some empty lines and some white-space only lines, I notice the following:
- My new
}
motion command seems to work just as I would like. - The filter command (
-
) works fine, except if the last line of the file has only a single character on it, which is treated as its own independent "paragraph" and not included along with the previous lines. This is unlike the way the}
motion command works. - However, the filter command hangs for many seconds (or indefinitely?) on some machines which are running different versions of vim 7.4 (I never did get an opportunity to isolate this hanging issue and it ended up disappearing in my solution below).
I've tried various combinations of map
, noremap
, etc. but that doesn't seem to help, except to prevent my }
motion mapping from being recognized inside the filter mapping, which is obviously not what I want.
So, how can I map }
to also find blank lines and still use it properly in a filter (!
) command. Hopefully the changes will also avoid the hanging that I'm experiencing on some machines (which obviously makes those solutions unusable). Lacking the ability to make }
work reliably inside filter commands, I would be willing to use something else in those filter commands that would accomplish what I'm looking for.
v
to this map:map - !v}nl -ba<CR>}
.map - !V}nl -ba<CR>}
should also work