Hello all!
I'm new to programming and enjoying Vim.

I'm trying to code a function that prints 2 chars and moves the cursor
between those 2 chars.

Previously, I've been doing it that way:
autocmd bufenter *.rb imap é( (æ)<esc>?æ<cr>s<c-o>:call getchar()
<cr><cr>

But I would like to do something more flexible (in ruby):

############################
imap <cr> <c-o>:call Inside_token("[]")<cr>
map <cr> :call Inside_token("[]")<cr>

fun! Inside_token(token)
ruby << EOF
  token = VIM::evaluate("a:token")
  cb = VIM::Buffer.current
  cw = VIM::Window.current
  row, col = cw.cursor
  # VIM::message("#{col}")                                   # silent
message
  line = cb.line
  line.insert(col, "#{token}")
  VIM::Buffer.current.line = line
  VIM::Window.current.cursor = [row, col+1]                # +1 to
move between the tokens
  # a[test]
  # a [test]      #
EOF
endfun
#############################

The problem is with the last character when in insert mode, <C-O> and
<ESC> both move the cursor one step to the left when invoked on the
last character of a line.
I have no way to determine the proper cursor position. I get the same
returned value whether I call the function in insert mode "i" while on
the last "visible" char or if on last char+1 in "a" insertion mode.
I hope I'm clear enough.
Is there a way to get around this problem?
Thank you all.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to