# Include global defaults (if they exist). Hopefully they deal with platform
# specific quirks.
$include /usr/share/readline/inputrc
$include /etc/inputrc

# Use vi editing mode.
set editing-mode vi

# Disable keyseq timeout.
set keyseq-timeout 0

# Force eight bit cleanliness regardless of terminal.
set input-meta On
set output-meta On
set convert-meta Off

# Turn off the audible bell.
set bell-style visible

# Prevent inadvertent execution of pasted commands.
# <http://www.xfree86.org/current/ctlseqs.html#Bracketed Paste Mode>
set enable-bracketed-paste On

# List certain completion matches immediately instead of ringing the bell.
# set show-all-if-ambiguous On
set show-all-if-unmodified On

# Use `LS_COLORS` to indicate file type when listing possible completions.
set colored-stats On

# Use colors to mark the common prefix during completion.
set colored-completion-prefix On
set menu-complete-display-prefix On

# Append slash to completed directory names even if they are symbolic links.
set mark-symlinked-directories On

# When in the middle of a word, do not insert characters from the completion
# that match characters after the point in the word being completed.
set skip-completed-text On

# Help identify matching parentheses when typing.
set blink-matching-paren On

# Do not echo a character corresponding to a signal generated from the
# keyboard.
set echo-control-characters Off

# Do not retain changes to history lines.
set revert-all-at-newline On

# Do not override control characters.
set bind-tty-special-chars Off

# Indicate vi mode with cursor shape.
set show-mode-in-prompt On
# $if term=xterm
  # https://vt100.net/docs/vt510-rm/DECSCUSR
  # http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
  set vi-cmd-mode-string \1\e[1 q\2
  set vi-ins-mode-string \1\e[5 q\2
  set emacs-mode-string  \1\e[5 q\2
# $endif
$if term=linux
  # https://www.kernel.org/doc/Documentation/admin-guide/vga-softcursor.rst
  set vi-cmd-mode-string \1\e[?8c\2
  set vi-ins-mode-string \1\e[?2c\2
  set emacs-mode-string  \1\e[?2c\2
$endif

# Override the defaults for `previous-history` and `next-history` to use
# `history-search-backward` and `history-search-forward` instead. These take
# into account text already typed.
set keymap emacs-standard
"\e[A": history-search-backward
"\e[B": history-search-forward
"\eOA": history-search-backward
"\eOB": history-search-forward
"\C-p": history-search-backward
"\C-n": history-search-forward
set keymap vi-insert
"\e[A": history-search-backward
"\e[B": history-search-forward
"\eOA": history-search-backward
"\eOB": history-search-forward
"\C-p": history-search-backward
"\C-n": history-search-forward
set keymap vi-command
"\e[A": history-search-backward
"\e[B": history-search-forward
"\eOA": history-search-backward
"\eOB": history-search-forward
"\C-p": history-search-backward
"\C-n": history-search-forward
"k": history-search-backward
"j": history-search-forward

# Change vi mode `C-w` from `vi-unix-word-rubout` to the more useful
# `unix-filename-rubout`.
set keymap vi-insert
"\C-w": unix-filename-rubout
set keymap vi-command
"\C-w": unix-filename-rubout

# Ctrl-L clears display (including scrollback buffer).
set keymap emacs-standard
"\C-l": clear-display
set keymap vi-insert
"\C-l": clear-display
set keymap vi-command
"\C-l": clear-display

# Ctrl-C sends Escape. Note that `stty intr ''` probably has to be run before
# readline reads a line for Ctrl-C to reach readline. It is a good idea to
# reset it with `stty intr '^c'` after the line has been read.
set keymap vi-insert
"\C-c": "\e"

# `readline-vim`.
$include ~/.inputrc.d/readline-vim.inputrc