Wednesday, March 24, 2010

Re: How to remember end of line when quitting/reopening in insert mode

Am 24.03.2010 16:03, schrieb Jean Johner:
> On Mar 24, 3:33 pm, Tony Mechelynck<antoine.mechely...@gmail.com>
> wrote:
> ...
>
> Sorry. I did not want to be offending or authoritary.
>
> I just wanted to outline that the fact that easy gvim (with the
> present vimrc_example.vim) does not remember end of lines is an
> obvious imperfection which gives a bad image of the code, especially
> to beginners. Let me recall again that gnome/gedit does it perfectly.
>
> set virtualedit=onemore works but has unpleasant side-effects in
> normal mode.
>
> Finding another solution appears to be an interesting programming
> problem (see Gary's mail)
>
> Not being myself a vim expert nor a C programmer (I am in fact a
> physicist), I encourage the vim community to eliminate this "bug".
>
> Best regards
> Jean

It's a bit tricky, but you can try the following code:


augroup LastPos
au! BufReadPost * call s:LastPos(&insertmode)
augroup END

func! s:LastPos(mode)
if a:mode == 2
au! LastPos InsertEnter
call feedkeys("\<C-R>=''[setpos('.',getpos(\"'\\\"\"))]\r", "n")
elseif line("'\"") >= 1 && line("'\"") <= line("$")
if a:mode == 1
au LastPos InsertEnter * call s:LastPos(2)
else
exe "normal! g`\""
endif
endif
endfunc


--
Andy

--
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

To unsubscribe from this group, send email to vim_use+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

No comments: