I'd like to reproduce this zsh mapping:
smart_dot() {
if [[ $LBUFFER = *.. ]]; then
LBUFFER+=/..
else
LBUFFER+=.
fi
}
zle -N smart_dot
bindkey -M viins -- . smart_dot
At first I used this:
function! Smart_dot() abort
if getcmdtype() =~# '[:]'
let l:cmd=getcmdline()
if match(l:cmd, '\.\.$') !=-1
return '/..'
else
return "."
endif
else
return getcmdline()
endif
endfunction
cnoremap . <c-r>=Smart_dot()<CR>
but how do turn this into local function? I've tried many variants on this that wouldn't work because it complained <SID>
was not used in a script context. Do I need to use <c-r>=
or <c-\>e
? Do I need to use the expand(<sfile>)
trick to get the script number, described near the end of section :h script-local
? Or do I need to <Plug>
this? I'm confused.
" function! s:smart_dot() ...
cnoremap . <C-\>ecall(function('<SID>smart_dot()'), [])<CR>
:h :map-<expr>
.