hi tim:
thanks for the improvement, I tested and your commands works.
I have 2 questions here:
1) about the magic "put_"
I couldn't understand, how come "put" a null register "_" will put a new
line?
my understanding is if it's a null then it shouldn't do anything "in
theory" right...
what's the idea behind this?
:[line]pu[t] [x] Put the text [from register x] after [line] (default
current line). This always works linewise, thus
this command can be used to put a yanked block
as new
lines.
The cursor is left on the first non-blank in
the last
new line.
The register can also be '=' followed by an
optional
expression. The expression continues until the
end of
the command. You need to escape the '|' and '"'
characters to prevent them from terminating the
command. Example: >
:put ='path' . \",/test\"
< If there is no expression after '=', Vim uses the
previous expression. You can see it with ":dis =".
2) now with the new way I have:
'<,'>g/^/put_
'<,'>g/^/exec "normal! gqq"
'<,'>s/^\s*\n\n\+/\r/
since I'm satisfied with this solution and I want to make it an easier
bind, so I make this:
function! FormatBook(...) range
exec a:firstline . "," . a:lastline . "g/^/put_"
exec a:firstline . "," . a:lastline . "g/^/exec " . "normal! gqq"
exec a:firstline . "," . a:lastline . "s/^\s*\n\n\+/\r/"
endf
com! -range=% -nargs=* FormatBook :<line1>,<line2>call
FormatBook(<f-args>)
map ,bf :FormatBook<CR>
but when I tested it report errors:
14 more lines
Error detected while processing function FormatBook:
line 2:
E121: Undefined variable: normal
E15: Invalid expression: normal! gqq
line 3:
E486: Pattern not found: ^s*^@^@+
seems something wrong with 2nd line:
exec a:firstline . "," . a:lastline . "g/^/exec " . "normal! gqq"
I know this is weired , but how to generalize this to make it work with
range via a simple key map?
thanks!