LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices



Reply
 
Search this Thread
Old 05-09-2007, 03:58 AM   #1
rangalo
Member
 
Registered: Jan 2005
Posts: 189

Rep: Reputation: 30
Remember last cursor position in VIM


Hi all,

I know this is not a vim forum, but I am tempted to ask the question because I have this problem only with debian.

On my slackware system (at work), if I close a file and open it again after some time in vim, the cursor is at the same position where I left it the last time. But on my debian system (at home), when I open the file, every time the cursor is at the beginning. For a large code files it is really quite a lot of work to go to the last position where I changed something.

Any ideas ? Anything I can add to my ~/.vimrc ?

thanks and regards,
Hardik

PS: On slackware I have 7.0.109, i don't remember the VIM version on debian, but it is certainly higher or equal.
 
Old 05-09-2007, 05:09 AM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
The settings are in your ~/.vimrc file, so you could check the .vimrc file at work. Here is a fragment of mine:
Code:
augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  autocmd BufReadPost *
    \ if line("'\"") > 0 && line("'\"") <= line("$") |
    \   exe "normal g`\"" |
    \ endif

  augroup END
 
Old 05-12-2007, 09:31 AM   #3
rangalo
Member
 
Registered: Jan 2005
Posts: 189

Original Poster
Rep: Reputation: 30
Hi,

Thanks for your reply. This did not help. One thing, my .vimrc on slackware doesn't contain such commands and including them in .vimrc on debian didn't change anything.

I attach here the complete .vimrc. If my syntax is wrong, please correct it.

thanks & regards
Hardik

Code:
if has("terminfo")
  set t_Co=8
  set t_Sf=^[[3%p1%dm
  set t_Sb=^[[4%p1%dm
  fixdel
else
  set t_Co=8
  set t_Sf=^[[3%dm
  set t_Sb=^[[4%dm
endif
if &term == "Eterm"
    set t_kD=^[[3~
    set t_kb=^?
endif
set background=dark
highlight Normal guibg=Black guifg=White
syntax on
set nocompatible
set bs=2
set expandtab
set tabstop=4
set noerrorbells
set visualbell t_vb=
set exrc
set autowrite
set showmatch
set smarttab
set smartindent
set autoindent
set shiftwidth=4
set showcmd
set ruler
set nobackup
set number
autocmd BufRead *.upl set syntax=html
autocmd BufRead *.cgi set syntax=per
autocmd BufRead *.grm set syntax=yacc
augroup vimrcEx
    au!

    " For all text files set tetwidth to 78 characters.
    autocmd FileType text setlocal textwidth=78

    " When editing a file, always jump to the last known position.
    " Don't to it when the position is invalid or when inside an event handler
    " (happens when dropping a file on gvim).
    autocmd BufReadPost *
      \ if line("'\"") > 0 && line("'\"") <= line($) |
      \     exe "normal g`\"" |
      \ endif
augroup END
 
Old 05-12-2007, 10:17 AM   #4
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
Here is information on the .viminfo file. That is where the cursor and command history is saved. Your version of vim at home might have been built without .viminfo support.

http://vim.sourceforge.net/tips/tip.php?tip_id=80

Make sure that on debian, that vim isn't aliased like:
vim='vim -i --'
I can't imagine that it would be.
Here is my entire .vimrc file. Also remember that vim and gvim are different and have different startup files.

Code:
" An example for a vimrc file.
"
" Maintainer:   Bram Moolenaar <Bram@vim.org>
" Last change:  2002 Sep 19
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"             for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"           for OpenVMS:  sys$login:.vimrc

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
  finish
endif

" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

if has("vms")
  set nobackup          " do not keep a backup file, use versions instead
else
  set backup            " keep a backup file
endif
set history=50          " keep 50 lines of command line history
set ruler               " show the cursor position all the time
set showcmd             " display incomplete commands
set incsearch           " do incremental searching

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" This is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
"vnoremap p "_dp

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  autocmd BufReadPost *
    \ if line("'\"") > 0 && line("'\"") <= line("$") |
    \   exe "normal g`\"" |
    \ endif

  augroup END

else

  set autoindent                " always set autoindenting on

endif " has("autocmd")

map <F3> : call CompileGcc()<CR>
func! CompileGcc()
          exec "w"
            exec "!latex %"
    endfunc

Last edited by jschiwal; 05-12-2007 at 11:07 AM.
 
Old 05-12-2007, 10:52 AM   #5
rangalo
Member
 
Registered: Jan 2005
Posts: 189

Original Poster
Rep: Reputation: 30
Hi,

Thanks, jschiwal.

I have .viminfo file created on my system, so I seem to have this support, I am not sure though. How to check if vim is compiled with viminfo or not ?

Another strange thing is that, I can run the command: '" from inside of vim and it takes me to the correct position (previous one).

I guess the scrptlet you sent me is not being executed.

regards,
Hardik
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
ARRgh Windows wont remember position... Mystical Itachi Suse/Novell 4 02-26-2007 04:18 AM
vim: startup at last cursor position chrism01 Solaris / OpenSolaris 3 02-20-2007 12:25 PM
is it possible for myth client to share (remember position,etc..) video library on al zeltak Linux - Software 0 01-23-2007 04:30 AM
Gaim wont remember window position LinuxNewbie2005 Puppy 2 06-28-2006 07:00 PM


All times are GMT -5. The time now is 08:29 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration