LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   vim to remember the last location (https://www.linuxquestions.org/questions/linux-software-2/vim-to-remember-the-last-location-734501/)

centguy 06-21-2009 01:59 AM

vim to remember the last location
 
I tried out vi on ubuntu 8.04 and fedora 10, but don't seem to able to
fix the "return the previous cursor position" when i reopen a file.

Tried out google suggestions but they are not working.

Quote:


augroup JumpCursorOnEdit
au!
autocmd BufReadPost *
\ if expand("<afile>:p:h") !=? $TEMP |
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ let JumpCursorOnEdit_foo = line("'\"") |
\ let b:doopenfold = 1 |
\ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
\ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
\ let b:doopenfold = 2 |
\ endif |
\ exe JumpCursorOnEdit_foo |
\ endif |
\ endif
" Need to postpone using "zv" until after reading the modelines.
autocmd BufWinEnter *
\ if exists("b:doopenfold") |
\ exe "normal zv" |
\ if(b:doopenfold > 1) |
\ exe "+".1 |
\ endif |
\ unlet b:doopenfold |
\ endif
augroup END

or

Quote:


augroup JumpCursorOnEdit
au!
autocmd BufReadPost *
\ if expand("<afile>:p:h") !=? $TEMP |
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ let JumpCursorOnEdit_foo = line("'\"") |
\ let b:doopenfold = 1 |
\ if (foldlevel(JumpCursorOnEdit_foo) >
foldlevel(JumpCursorOnEdit_foo - 1)) |
\ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
\ let b:doopenfold = 2 |
\ endif |
\ exe JumpCursorOnEdit_foo |
\ endif |
\ endif
" Need to postpone using "zv" until after reading the modelines.
autocmd BufWinEnter *
\ if exists("b:doopenfold") |
\ exe "normal zv" |
\ if(b:doopenfold > 1) |
\ exe "+".1 |
\ endif |
\ unlet b:doopenfold |
\ endif
augroup END

Strange enough, the vim that comes with CentOS is working very well (comes even with nice text highlighting when I open a Fortran90 file). But I don't find .vimrc file that I can recycle.

Looks like I have a case where the old horse is better than the new ones.

Cheers.

centguy 06-21-2009 02:16 AM

After installing vim-enhanced
things are working fine on f10.

Quote:

[ckgan@f10-32-dell tex]$ rpm -qva | grep vim
vim-enhanced-7.2.148-1.fc10.i386
vim-minimal-7.2.025-2.fc10.i386
vim-common-7.2.148-1.fc10.i386
I really like to ditch vi since it confuses me quite a bit with vim.

Quote:

[ckgan@f10-32-dell tex]$ which vi
/bin/vi
[ckgan@f10-32-dell tex]$ which vim
/usr/bin/vim

centguy 06-21-2009 02:50 AM

CentOS folks are a bit more humane:

Quote:

[root@centos52-64-fuj profile.d]# cat /etc/profile.d/vim.sh
if [ -n "$BASH_VERSION" -o -n "$KSH_VERSION" -o -n "$ZSH_VERSION" ]; then
[ -x /usr/bin/id ] || return
[ `/usr/bin/id -u` -le 100 ] && return
# for bash and zsh, only if no alias is already set
alias vi >/dev/null 2>&1 || alias vi=vim
fi

centguy 06-21-2009 07:55 AM

ubuntu's vim is still no cooperating, its behavior is still like
standard vi.

I did

sudo apt-get install vim vim-common vim-gnome vim-gui-common vim-runtime


but still there is no progress.

Can't believe ubuntu is that unfriendly towards me !!

centguy 06-22-2009 01:06 AM

ubuntu folks can you please me ? thanks!

centguy 06-22-2009 07:46 AM

why is ubuntu so unclean? (or whatever you might call it)

After I purge and autoremove vim (hoping that i can get the latest vim),
the vim is still executable in the system.

Quote:

root@ubuntu804-32-dell:/etc# apt-get purge vim
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package vim is not installed, so not removed
The following packages were automatically installed and are no longer required:
vim-runtime
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 147 not upgraded.
root@ubuntu804-32-dell:/etc# apt-get autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
vim-runtime
The following packages will be REMOVED:
vim-runtime
0 upgraded, 0 newly installed, 1 to remove and 147 not upgraded.
After this operation, 23.3MB disk space will be freed.
Do you want to continue [Y/n]? Y
(Reading database ... 114011 files and directories currently installed.)
Removing vim-runtime ...
root@ubuntu804-32-dell:/etc# which vi
/usr/bin/vi
root@ubuntu804-32-dell:/etc# which vim
/usr/bin/vim


centguy 06-22-2009 08:02 AM

Found this in
https://bugs.launchpad.net/ubuntu/+s...vim/+bug/69611


Quote:




Binary package hint: vim-common

in /etc/vim/vimrc

the commented lines that allow one to jump to the last position when reopening a file are incorrect. It doesn't act properly if a user remaps g in their .vimrc . It needs an ! after the normal. It should read:

" Uncomment the following to have Vim jump to the last position when
" reopening a file
"if has("autocmd")
" au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
" \| exe "normal! g'\"" | endif
"endif

Notice the ! after normal, that needs to be added so that it doesn't remap the g. Obviously this is only a problem if someone uncomments those lines, and has g remapped in their .vimrc (or vimrc.local in my case).

to reproduce, uncomment those lines in /etc/vim/vimrc and add
noremap g >>j
to /etc/vim/vimrc.local

After doing what this says, I still have

Quote:

ckgan@ubuntu804-32-dell:~$ !v
vim
Error detected while processing /usr/share/vim/vimrc:
line 30:
E10: \ should be followed by /, ? or &
Press ENTER or type command to continue

I think I run of luck today. I am starting to doubt the friendliness of
you-know-what...

centguy 06-22-2009 08:23 AM

Solved.. borrow /etc/vimrc of CentOS5.2 and figure out to put everything
in one line to avoid backslash. And it works now.

Quote:

if has("autocmd")
" When editing a file, always jump to the last cursor position
autocmd BufReadPost * if line("'\"") > 0 && line ("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
what a pain!


All times are GMT -5. The time now is 10:48 PM.