1

I want a way in which we can access a history of commands in terminal mode (and Vim/NeoVim's internal command line), just like in a normal bash terminal; i.e. if I press the up key it will scroll through previously executed commands.

Currently if I press any directional keys in terminal mode, it will close the terminal.

Any guidance on this would be greatly appreciated.

Maybe I have to write a new plugin?

EDIT: For :term/:terminal mode, the answer is to Use ConqueTerm from this repo.

EDIT: As you can see the above is not the answer.

EDIT (problem solved): I had previously mapped the key in terminal mode, so that I could exit terminal with a simple keystroke.

closed as off-topic by Rich, Herb Wolfe, muru, D. Ben Knoble, statox Dec 26 '18 at 16:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers." – Rich, Herb Wolfe, muru, D. Ben Knoble, statox
If this question can be reworded to fit the rules in the help center, please edit the question.

  • I've just come across the read-only registers. It seems that every command is stored in the ": register. This is the obvious place to start for building a plugin. I've never done this before, so if anyone has any obvious pointers, feel free to shout at me. I'm also using 'vim the hard way' as a guide. I'll post a link when I'm finished. – BitShift Dec 19 '18 at 3:40
  • No need to write a new plugin; see my answer below for some pointers to get started. – D. Ben Knoble Dec 19 '18 at 4:54
  • No, the answer is not to use ConqueTerm. As this is an alternative terminal like implementation that has been unmaintained for several years. Go with the default :terminal implementation of your Vim and find out, why your keys behave unexpected – Christian Brabandt Dec 19 '18 at 6:39
  • I see. I didn't realise this is not expected behaviour. Will do. Thanks – BitShift Dec 19 '18 at 6:48
0

As a brief start at an answer:

Vim has command-line history on the Ex command line (what you get from :). You can access it many ways; e.g.,

  1. <C-n> and its cousin <C-p> to search forward and backward in history
  2. q: to access the command line window, a vim window with lots of power.

In a split provided by :terminal, however, it depends entirely on the program running and in general becomes off-topic for this site. Consult the man pages. For example, in bash, there exist history, history expansions via !, and fc, useful tricks to know. Combine with <C-r> recursive search for more fun. In vi input mode, the <C-n/p> trick works as well.


Addendum

If your arrow keys dont work in a :terminal split, there are lots of potential sources. Check e.g. $TERM and possibly open a new question focused on just this issue.

  • Thanks Ben! I will use <C-p> and <C-n> for the vim command line. As for :term/:terminal, I found my answer with ConqueTerm, instead of using the native terminal. There is an accessible history there simply by using the arrow keys... Now if I could just map those keys to the usual hjkl then I'm off to the races :) – BitShift Dec 19 '18 at 6:04
  • If you use bash, try set -o vi, and hit esc to use vi normal mode bindings. – D. Ben Knoble Dec 19 '18 at 15:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.