LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Debian (https://www.linuxquestions.org/questions/debian-26/)
-   -   Remember last cursor position in VIM (https://www.linuxquestions.org/questions/debian-26/remember-last-cursor-position-in-vim-552503/)

rangalo 05-09-2007 02:58 AM

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.

jschiwal 05-09-2007 04:09 AM

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


rangalo 05-12-2007 08:31 AM

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


jschiwal 05-12-2007 09:17 AM

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


rangalo 05-12-2007 09:52 AM

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


All times are GMT -5. The time now is 08:38 AM.