12

When I type the character q on my keyboard in vim, it exits vim. Why?

Today I tried it edit a file with the file extension .man. I wanted to edit the file with a macro, so I tried to type qq -- but when the first q was entered, vim closed!

vim test.man 

This is on a fresh install on Debian 12. I do not have a .vimrc defined.

I renamed the same file with a .man extension to have a .txt extension, and this time I could create a macro as expected -- typing a q doesn't cause vim to exit.

mv test.man test.txt vim test.txt 

Why is vim exiting when typing a q when trying to edit a file with a .man file extension? And how do I stop this behaviour?

1
  • 2
    Ugh. This type of automagic for a fresh install is not to be encouraged. Commented Mar 27, 2024 at 19:26

1 Answer 1

24

The Vim editor will load the man filetype plugin (ft-man-plugin) whenever it opens a file which has a .man filename suffix.

A more usable way of using this plugin is by loading it with

:runtime ftplugin/man.vim 

... and then using the :Man command, e.g.,

:Man ls 

One of the things the man filetype plugin changes is that it maps q to :quit. It does this because the :Man command usually runs within Vim, and quitting it brings you back to whatever other document you were writing at the time, and someone decided it would be handier to just have to type q, as you would usually do to exit out of the manual pager in the terminal.

For more information, see :help ft-man-plugin in Vim.

To avoid loading this plugin for .man files, set the filetype of files with this filename suffix to something else, e.g., text, in your Vim startup file (~/.vimrc or wherever you configure Vim):

autocmd BufRead,BufNewFile *.man set filetype=text 

Or, remove the filetype detection completely for these files:

autocmd! filetypedetect BufRead,BufNewFile *.man 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.