LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Arch
User Name
Password
Arch This Forum is for the discussion of Arch Linux.

Notices


Reply
  Search this Thread
Old 01-14-2020, 12:16 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
Vim 8.1: cursor position not saved.


Hi: I am within vim editing a file and the cursor is in a given position. Now I exit (:wq command). The next time I edit that file, that is when I invoke vim with the same file name, the cursor appears in line 1 column 1. This happens every time I run vim on a file already edited with vim. How can this be? I thought vim always saved the cursor position and, in fact, this was the case when I ran vim under Slackware.
 
Old 01-14-2020, 08:27 PM   #2
Mechanikx
Member
 
Registered: Jul 2018
Distribution: Slackware
Posts: 351

Rep: Reputation: 258Reputation: 258Reputation: 258
The cursor position is saved in ~/.viminfo. Maybe it's not able to write to this file for some reason? Try checking the file permissions of ~/.viminfo. Maybe the new distro you're running vim under doesn't have the write permission set.
 
Old 01-14-2020, 10:08 PM   #3
Geist
Member
 
Registered: Jul 2013
Distribution: Slackware 14 / current
Posts: 442

Rep: Reputation: 196Reputation: 196
It's an autocommand...defined in the /defaults.vim script on the system wide vim directory (for me it's /usr/share/vim/vim81/defaults.vim )

If yours lacks this, this is the command you could just put in your vimrc.

Code:
autocmd BufReadPost *
  \ if line("'"") >= 1 && line("'"") <= line("$") |
  \   exe "normal! g`"" |
  \ endif
If this doesn't work, it might be related to "+eval", as per the defaults.vim file:
Code:
" Only do this part when Vim was compiled with the +eval feature.
Or something entirely different.

But try it for yourself, if you want.

Last edited by Geist; 01-14-2020 at 10:23 PM.
 
Old 01-15-2020, 12:37 PM   #4
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
My /usr/share/vim/vim81/defaults.vim has this block in it:
Code:
" 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.
  " Revert with ":filetype off".
  filetype plugin indent on

  " Put these in an autocmd group, so that you can revert them with:
  " ":augroup vimStartup | au! | augroup END"
  augroup vimStartup
    au!

    " When editing a file, always jump to the last known cursor position.
    " Don't do it when the position is invalid, when inside an event handler
    " (happens when dropping a file on gvim) and for a commit message (it's
    " likely a different one than last time).
    autocmd BufReadPost *
      \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
      \ |   exe "normal! g`\""
      \ | endif

  augroup END

endif " has("autocmd")
Perhaps vim was compiled without support for autocommands?
 
Old 01-15-2020, 02:15 PM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,786

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
Code:
vim --version
will tell you the configuration, you need to look for +autocmd (or -autocmd).
 
1 members found this post helpful.
Old 01-15-2020, 02:32 PM   #6
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by pan64 View Post
you need to look for +autocmd (or -autocmd).
Another setting (within vim itself) is the one for 'viminfo', if that outputfile is not enabled
Code:
(viminfo=)
as in my installation, of course no info is saved for a next session.
 
1 members found this post helpful.
Old 01-16-2020, 06:47 AM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Quote:
Originally Posted by pan64 View Post
Code:
vim --version
will tell you the configuration, you need to look for +autocmd (or -autocmd).
It says +autocmd.
 
Old 01-16-2020, 07:54 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,786

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
that means it is enabled. So there should be an error somewhere
 
  


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
[SOLVED] How to get the cursor position line at the mid of the windows in vim? cola Linux - Newbie 5 03-28-2010 10:18 AM
Vim cursor position Tischbein Linux - Newbie 4 03-31-2008 01:32 AM
Remember last cursor position in VIM rangalo Debian 4 05-12-2007 09:52 AM
vim: startup at last cursor position chrism01 Solaris / OpenSolaris 3 02-20-2007 11:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Arch

All times are GMT -5. The time now is 02:25 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
Open Source Consulting | Domain Registration