LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-21-2009, 01:59 AM   #1
centguy
Member
 
Registered: Feb 2008
Posts: 627
Blog Entries: 1

Rep: Reputation: 48
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>: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>: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.
 
Old 06-21-2009, 02:16 AM   #2
centguy
Member
 
Registered: Feb 2008
Posts: 627

Original Poster
Blog Entries: 1

Rep: Reputation: 48
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
 
Old 06-21-2009, 02:50 AM   #3
centguy
Member
 
Registered: Feb 2008
Posts: 627

Original Poster
Blog Entries: 1

Rep: Reputation: 48
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
 
Old 06-21-2009, 07:55 AM   #4
centguy
Member
 
Registered: Feb 2008
Posts: 627

Original Poster
Blog Entries: 1

Rep: Reputation: 48
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 !!
 
Old 06-22-2009, 01:06 AM   #5
centguy
Member
 
Registered: Feb 2008
Posts: 627

Original Poster
Blog Entries: 1

Rep: Reputation: 48
ubuntu folks can you please me ? thanks!
 
Old 06-22-2009, 07:46 AM   #6
centguy
Member
 
Registered: Feb 2008
Posts: 627

Original Poster
Blog Entries: 1

Rep: Reputation: 48
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
 
Old 06-22-2009, 08:02 AM   #7
centguy
Member
 
Registered: Feb 2008
Posts: 627

Original Poster
Blog Entries: 1

Rep: Reputation: 48
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...
 
Old 06-22-2009, 08:23 AM   #8
centguy
Member
 
Registered: Feb 2008
Posts: 627

Original Poster
Blog Entries: 1

Rep: Reputation: 48
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!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Switching from vim to vim -g from inside vim iDragoon Linux - Software 4 05-15-2009 11:46 AM
Editor comparison: vim VS vim-lite, Cleaning vim Ruler2112 *BSD 4 04-13-2009 04:26 PM
Remember last cursor position in VIM rangalo Debian 4 05-12-2007 09:52 AM
LXer: Cream for Vim - Making Vim more user friendly LXer Syndicated Linux News 0 06-17-2006 11:54 PM
Nautilus 2.8.1 remember size and location? tretneo Fedora 0 01-17-2005 05:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration