Search code examples
bashvimvicd

Is this a bug in bash when editing command line in editor through vi, or expected behavior?


I have this setting in my ~/.inputrc file:

set editing-mode vi

but the behavior is the same if I have

set -o vi

in `~/.bashrc. In addition I also have

export VISUAL=vim
export EDITOR="$VISUAL"

in the latter file.

The buggy behavior I observed is reproducible as follows:

  1. fill the command line with a valid change directory command, e.g. cd existingFolder,
  2. press Escape to exit insert mode and enter normal mode,
  3. press v to open vi/vim,
  4. accept the command by :wqEnter

Result: the current directory has changed, but the prompt, if it shows the currect directory, has not updated to reflect the change of it.

Is this a bug or an expected behavior?

A screencast is better than a thousand words:

asciicast


Solution

  • This happens independently of vim, vi, or bash's vi mode.

    A MCVE is this:

    $ cd /usr && env -i EDITOR='touch' PS1='\w \$ ' bash --norc
    /usr $ cd bin   # press Ctrl-X Ctrl-E instead of Enter here
    cd bin
    /usr $ pwd      # Bug visible here, prompt should say `/usr/bin`
    /usr/bin
    /usr/bin $      # Prompt now showing expected value
    

    The prompt fails to update, and PROMPT_COMMAND is not executed. Upstream git commit 6c6454cb1 from 2020-02-07 shows the same behavior.

    So to answer the question, yup, looks like a bug.