On 12/06/11 9:20 AM, Bee wrote:
On Jun 11, 9:21 am, Bee<[email protected]> wrote:
On Jun 11, 1:55 am, Ben Schmidt<[email protected]> wrote:
" Jump to start of nth or next block of 16 lines
nnoremap<expr> ]]
\ v:count
\ ? ":<C-U><cr>".(v:count*16+1)."Gzz"
\ : 17-line(".")%16."jzz"
Why is the :<C-U><CR> there? Doesn't that do nothing?
" Display line and block number
nnoremap ][ :echo (line(".")-1)%16 line(".")/16 "List"<cr>
BUT this function is not working:
fu! List()
" Jump to start of nth or next block of 16 lines
v:count ? ":<C-U><cr>".(v:count*16+1)."Gzz" : 17-line(".")%16."jzz"
" Display line and block number
echo (line(".")-1)%16 line(".")/16 "List"<cr>
endfu
nnoremap ]] :call List()<cr>
In a function, you actually have to run the commands, not just return
keystrokes like in an expr mapping. Something like this:
fu! List()
" Jump to start of nth or next block of 16 lines
if v:count
execute "normal ".(v:count*16+1)."Gzz"
else
execute "normal ".(17-line(".")%16)."jzz"
endif
" Display line and block number
echo (line(".")-1)%16 line(".")/16 "List"
endfu
:help :if
:help :execute
:help :normal
Ben.
I added<C-U> to the call and the count works.
I also moved the echo to a function, by itself it works.
Still the echo does not work.
" Display line and block number
function! List()
let lz = line(".")-1
echo lz%16 lz/16 "List"
endfun
nnoremap ][ :call List()<cr>
" Jump to start of nth or next block of 16 lines
function! Block()
if v:count
execute "normal ".(v:count*16+1)."Gzz"
else
execute "normal ".(17-line(".")%16)."jzz"
endif
call List()
endfu
nnoremap ]] :<C-U>call Block()<cr>
I found the problem... a redraw in needed before the echo.
Excellent! Glad to hear you've solved it.
Ben.
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php