Bug 2404651 - Autocommand to restore last cursor position does not check for certain file types
Summary: Autocommand to restore last cursor position does not check for certain file t...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: vim
Version: 42
Hardware: x86_64
OS: Linux
unspecified
low
Target Milestone: ---
Assignee: Zdenek Dohnal
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2025-10-17 04:06 UTC by Issa Rice
Modified: 2025-11-08 01:32 UTC (History)
3 users (show)

Fixed In Version: vim-9.1.1888-1.fc43 vim-9.1.1888-1.fc41 vim-9.1.1888-1.fc42
Clone Of:
Environment:
Last Closed: 2025-11-04 04:13:23 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Issa Rice 2025-10-17 04:06:59 UTC
Currently, the system vimrc file at /etc/vimrc contains the following autocommand:

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

This autocommand does not check for certain file types like whether the buffer is a Git commit message, so it jumps to the last cursor position even when it shouldn't (when Vim opens a Git commit message window, one is writing a new commit, so the cursor should be at the top, not some random place in the middle of the buffer where the cursor last happened to be at the end of writing the previous commit message).

Vim's :help restore-cursor has the following implementation, which I think is a lot better, as it checks for these file types before jumping to the last cursor position:

    augroup RestoreCursor
      autocmd!
      autocmd BufReadPost *
        \ let line = line("'\"")
        \ | if line >= 1 && line <= line("$") && &filetype !~# 'commit'
        \      && index(['xxd', 'gitrebase'], &filetype) == -1
        \      && !&diff
        \ |   execute "normal! g`\""
        \ | endif
    augroup END

I've been working around this issue by deleting the autocommand, with something like:

    if exists('#fedora#BufReadPost *')
      autocmd! fedora BufReadPost *
    endif

It might also be worth thinking about not including this autocommand at all; the better implementation is already in defaults.vim so users can source that file if they want this feature, and I was able to find at least one person who didn't want this and couldn't figure out how to disable it: https://unix.stackexchange.com/questions/559328/is-there-a-vimrc-setting-that-will-cause-vim-to-open-files-at-the-first-line

Reproducible: Always

Steps to Reproduce:
1. Make some changes to a file in a git repository, stage the changes, and then type git commit at the command line. (Make sure $EDITOR is vim so that Vim opens up for writing the commit message.)
2. Move the cursor around.
3. Type :q to abort the commit message.
4. Type git commit again.
Actual Results:
The cursor is not at position 1,1.

Expected Results:
The cursor should be at position 1,1.

Additional Information:
Tested on Vim 9.1.1818 on Fedora 42, using the vim-X11 package.

Comment 1 Zdenek Dohnal 2025-10-17 07:51:11 UTC
Hi Issa,

thank you for reporting the issue and the pointer!

Looking into the state you described, I will update the system vimrc - remove the current Fedora autocommand and include the one from Vim project, because letting adding the autocommand or sourcing default.vim on users would cause disruption for them - they would have to set something which they did not have to, which should not happen based on decision made by preference.

I'll try to get to it next week.

Comment 2 Zdenek Dohnal 2025-10-31 07:29:51 UTC
I'm going to land fixed vimrc in the new update I'll build today - however the fix won't be applied on systems where user already changed /etc/vimrc, so such cases have to be handled via 'rpmconf'.

Comment 3 Fedora Update System 2025-10-31 08:17:14 UTC
FEDORA-2025-1980bf1f93 (vim-9.1.1888-1.fc43) has been submitted as an update to Fedora 43.
https://bodhi.fedoraproject.org/updates/FEDORA-2025-1980bf1f93

Comment 4 Fedora Update System 2025-10-31 08:47:30 UTC
FEDORA-2025-42efe01f7d (vim-9.1.1888-1.fc42) has been submitted as an update to Fedora 42.
https://bodhi.fedoraproject.org/updates/FEDORA-2025-42efe01f7d

Comment 5 Fedora Update System 2025-10-31 09:15:43 UTC
FEDORA-2025-99ae55302d (vim-9.1.1888-1.fc41) has been submitted as an update to Fedora 41.
https://bodhi.fedoraproject.org/updates/FEDORA-2025-99ae55302d

Comment 6 Fedora Update System 2025-11-01 03:08:31 UTC
FEDORA-2025-1980bf1f93 has been pushed to the Fedora 43 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2025-1980bf1f93`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2025-1980bf1f93

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 7 Fedora Update System 2025-11-01 03:24:52 UTC
FEDORA-2025-42efe01f7d has been pushed to the Fedora 42 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2025-42efe01f7d`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2025-42efe01f7d

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 8 Fedora Update System 2025-11-01 03:41:28 UTC
FEDORA-2025-99ae55302d has been pushed to the Fedora 41 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2025-99ae55302d`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2025-99ae55302d

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 9 Fedora Update System 2025-11-04 04:13:23 UTC
FEDORA-2025-1980bf1f93 (vim-9.1.1888-1.fc43) has been pushed to the Fedora 43 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 10 Fedora Update System 2025-11-05 04:15:55 UTC
FEDORA-2025-99ae55302d (vim-9.1.1888-1.fc41) has been pushed to the Fedora 41 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 11 Fedora Update System 2025-11-08 01:32:17 UTC
FEDORA-2025-42efe01f7d (vim-9.1.1888-1.fc42) has been pushed to the Fedora 42 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.