- Feb 1, 2006
On Tue, 31 Jan 2006, iler_ml@... wrote:
> Some weeeks ago, there was example of cmap/cabbrev that is expanded
> only at the beginning of the command line. I think this is very useful.
> Using such thing, you can safely redefine commands or define command
> containing characters which are normally not allowed in cmd name (e.g.
> I cannot find it in the archive at ther moment, or to reproduce it.
> ( It was about remapping the :/(slash at the beginning of cmd line)).
> How to make such mapping again ? Which expression checks if cursor
> is at the beginning of cmd line ?
Here's a quick hack:
let pos = getcmdpos()
let cmd = getcmdline()
let vs = strpart(cmd, 0, pos - 1)
let ve = strpart(cmd, pos - 1)
let rep = pos == 1 ? "replaced" : "/"
call setcmdpos(pos + strlen(rep))
cnoremap / <C-\>eTest()<CR>
Somehow, getcmdpos() doesn't work with c_ctrl-r_= in Vim 6.3. Probably
an old bug. Otherwise, the above function will simplified to just
cnoremap / <C-r>=getcmdpos() == 1 ? "replaced" : "/"<CR>
Hope this helps.
- << Previous post in topic