Hi,

I'm trying to build a function for solving some completion hacking.
I mean, I would like to quickly move my cursor in insertmod backward in
the current line and cycle though the positions.

My idea is to define 2 key bindings:

imap <c-left> which will detect some char in the current line [=/]
imap <c-right> which will delete one space backward

hitting c-left would bring my cursor in insert mode just after the char
matched:

I represent the cursor with a pipe

var=pipo/molo|
             
var=pipo/|molo

var=|pipo/molo

             

and each c-left cycle through matchable character, and back where we
started the mapping

I would know if I can imap <esc> temporary so it will finish my cycle
and move the cursor back to the started position, saved in a mark (may
be some offset compute, because I inserted space).
That way I can come back to insert mode and hit <c-x><c-f> to have file
completion fore example, with the modified path and having filename
completed with current path.

Do I need to handle the imap <esc> myself or it there some instant
one-shot mapping?

Here is my function draft:

" supprime l'espace dans la completion "test_ nom_class<c-f>"
imap <c-left> <esc>miF x`ia
" insert l'espace sur in char
[=/]                                             
imap <c-right> <esc>:call Lookup_back()<cr>a

" var=pipo/molo
func! Lookup_back()
  let l = getline('.')
  let s = 0
  " save the line txt in g:last_l, will be our memory + g:last_match
  if exists("g:last_l")
    if l == g:last_l
      let s = g:last_match + 1
    else
      let g:last_l = l
    endif
  else
    " init
    norm mi
    let g:last_l = l
  endif

  " reverse it
  let r = join(reverse(split(l, '\zs')), '')
  let p = match(r, '[=/][^ ]', s)
  let g:last_match = p

  if p > -1
    call cursor(line('.'), col("'i") - p)
  else
    let g:last_l = ""
    " put back at 'i
    "call cursor(line('.'), col("'i"))
  endif
  echo p
endf

-- 
-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_use+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to