I am trying to write a function that will only let me call nmap b when the cursor is not on the first column in the current window. This is to make b only work on the current line and encourage more efficient navigation bindings.
I wrote a function which does what I want:
function CurrentLineB()
let column = getcurpos()[2]
echo column
if column != 1
normal b%
endif
endfunction
When I call it with :call CurrentLineB()
without binding it to b
, it works as expected. When I map the function with nnoremap b :call CurrentLineB()
the function keeps recurring without exiting.
How can I avoid this recursion, and make the function work as it did when it was not bound to b?
normal!
instead ofnormal
to make that call non-recursive. (I don't get the%
there, is that a typo?)nnoremap <expr> b col('.') > 1 ? 'b' : ''
%
is indeed a typo, can you please edit your question to remove it? (If it's not a typo, can you explain why you had it?)