Unable to use Vi mode in LLDB console on Linux

Hello,

I'm using LLDB installed as Arch Linux package.

% lldb -v
lldb version 10.0.0

% cat ~/.editrc
bind -v

I'm not able to use vi keybindings like j, k cycle through commands in
the lldb console.

It would be great if someone could help me with this issue.

Thanks,
Alvin

There are some posts about issues with using the "bind -v". It seems it will delete all other key bindings and LLDB does a bunch of bindings for custom things which you won't want to use.

Hello,

I'm using LLDB installed as Arch Linux package.

% lldb -v
lldb version 10.0.0

% cat ~/.editrc
bind -v

I'm not able to use vi keybindings like j, k cycle through commands in
the lldb console.

It would be great if someone could help me with this issue.

So it seems we hardcode to "emacs" key bindings in your EditLine.cpp source file in:

lldb/source/Host/common/Editline.cpp

Checkout the Editline::ConfigureEditor(bool multiline) function.

A few things I see:

- We disable EL_EDITMODE because we run multiple editline instances in the same program. Not sure if this will affect the editline "vi" mode:

  if (m_editline) {
    // Disable edit mode to stop the terminal from flushing all input during
    // the call to el_end() since we expect to have multiple editline instances
    // in this program.
    el_set(m_editline, EL_EDITMODE, 0);
    el_end(m_editline);
  }

- We use "emacs" by default right now:

  el_set(m_editline, EL_EDITOR, "emacs");

We could add a setting into lldb that would allow you to set this to "vi" mode. If you can download the LLDB sources and build with "vi" mode and see if that works as you would expect, we could then add a setting or environment variable to allow users to modify this.

I would suggest against using "bind -v" as this seems to clear out the many many custom key bindings that we add to the lldb editline instances and you really don't want to miss out on that.

If you do, some people online said that there is something that allows you to dump all of the current bindings, which you can then put into your ~/.editrc file after a "bind -v". One reason to not do this is if newer lldb binaries add new bindings, your ~/.editrc file will now be out of date and might miss out on new functionality.

So the best option would be the manually add any VI bindings in your ~/.editrc and avoid using "bind -v" for now. I customize my bindings manually and make sure any bindings are lldb specific:

$ cat ~/.editrc
lldb:bind '^[[5C' vi-next-word
lldb:bind '^[[5D' vi-prev-word
lldb:bind '^D' ed-delete-next-char
lldb:bind '^B' ed-command
lldb:bind '^P' ed-search-prev-history
lldb:bind '^N' ed-search-next-history

If you end up building LLDB and the modify 'el_set(m_editline, EL_EDITOR, "emacs")' to be 'el_set(m_editline, EL_EDITOR, "vi")' and this really helps, let us know and we can file a task to add a setting to LLDB so we can allow this to be changed.

Greg

Thank you for the tips. Building LLDB with 'el_set(m_editline,
EL_EDITOR, "vi")' didn't exhibit vi mode behaviors and disabled all
emacs keybindings like ESC-b to go to previous word (Without .editrc
presence).
Thank you for taking your time to answer my questions and I'll
continue my LLDB journey without worrying about using vi mode.

Alvin

You can enable as much vi mode as possible with your ~/.editrc file. Try doing:

$ man editor

There are many things you can add keyboard shortcuts for and this man page details them all. We seem to have a mixture of both emacs and a few vi keybindings by default. Everything is exposed and can be remapped in your ~/.editrc file. If you come up with a list of vi shortcuts you think others might want, send a reply email with what you found.

Greg