I'm trying to make a vmap that takes a count and then indents all the highlighted lines so that the top one is more than the line above it, while keeping all the lines' relative indentation. I have made it to this function and I'm experiencing some behaviour I don't know how to figure out. For some reason, this function will only indent the top line of the selection. I've tested it using echomsg
instead of execute
, and then just pasting the commands in explicitly and it works just fine. But for some reason when it's in this for loop, it only executes the first one.
function! Test()
let above = line("'<") - 1
for line in range(line("'<"), line("'>"))
execute line . "left " . (indent(above) + 4 + indent(line) - indent("'<"))
endfor
endfunction
Also, if there's a plugin that'll already do this for me, feel free to let me know.
Edit:
Putting this function at the top of the file, changing execute
to echomsg
, highlighting the function body, and then running :cal Test()
give the following ouput
2left 4
3left 0
4left 4
5left 8
6left 4
Which is expected, so I don't understand what's going wrong when I use execute
.
range
to the function definition (after theTest()
) fix your issue?:cal Test()
with this exact function.'<
and'>
. And to be clear, I ran literally:cal Test()
, not:'<,'>call Test()
. Also, like I mentioned, when usingechomsg
instead ofexecute
the commands come out as expected.:messages
" show? It could be that Vim is overlaying each echomsg with the next. I can't reproduce the behavior you're seeing but I also don't think the function is working right.