Loading ...
Sorry, an error occurred while loading the content.

65342Re: split

Expand Messages
  • Gerald Lai
    Feb 1, 2006
    • 0 Attachment
      On Tue, 31 Jan 2006, iler_ml@... wrote:

      [snip]
      > 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.
      > :-x)
      >
      > 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:

      fun Test()
      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))
      return vs.rep.ve
      endfun
      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
      (untested):

      cnoremap / <C-r>=getcmdpos() == 1 ? "replaced" : "/"<CR>

      Hope this helps.
      --
      Gerald
    • Show all 5 messages in this topic