You are not logged in.
Pages: 1
Topic closed
Hey guys,
Every once and a while I switch my readline between emacs and vi mode just for the fun of messing up my fingermemory for the keymappings.
Today I decided it was time to switch back to vi mode, so I did (for those who don't know, add set editing-mode vi and set keymap vi to your input rc). So great but...
I have \C-p: history-search-backward in there as well to automatically search my current line whenever I press control P. This worked great in emacs mode. In vi mode I have to switch to command mode first (ESC) and then hit Control-P. I would like to know how to bind history-search-backward to Control-P in insert mode.
I figured out how to do this using a bash command:
bind -m vi-insert "\C-p":history-search-backward
Works like a charm... but I want this inputrc so I can get the same behaviour in my python interpreter as well. Any ideas?
Dusty
Offline
While I'm on the topic, is there a way to get a visual indicator of whether you're in vi-command or vi-insert mode while you're using bash? I'm thinking a hollow cursor for command mode and solid for insert...
Dusty
Offline
You can do:
$if mode=vi
"\C-p":history-search-backward
$endif
Offline
While I'm on the topic, is there a way to get a visual indicator of whether you're in vi-command or vi-insert mode while you're using bash? I'm thinking a hollow cursor for command mode and solid for insert...
Nope. That's one of the reasons I stopped using vi mode.
Offline
You can do:
$if mode=vi "\C-p":history-search-backward $endif
Hah! I had a bet with myself that it would be you who replied and looks like I won. ;-)
But...
It doesn't seem to work, nor variations without the quotes or changing to vi-insert...
Here's my inputrc at the moment:
set editing-mode vi
set keymap vi
set show-all-if-ambiguous on
set match-hidden-files off
set expand-tilde off
set print-completion-horizontally on
set convert-meta off
$if mode=vi
"\C-p": history-search-backward
$endif
If I type vi<control-P> I get:
vi^P
but if I type
vi<esc><control-P> I get:
vim .inputrc
Any ideas?
Offline
Dusty wrote:While I'm on the topic, is there a way to get a visual indicator of whether you're in vi-command or vi-insert mode while you're using bash? I'm thinking a hollow cursor for command mode and solid for insert...
Nope. That's one of the reasons I stopped using vi mode.
Rather than submitting a patch?
Dusty
Offline
I'm not on a linux box atm, but did you try:
$if editing-mode=vi
"\C-p": history-search-backward
$endif
archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson
Offline
phrakture wrote:Dusty wrote:While I'm on the topic, is there a way to get a visual indicator of whether you're in vi-command or vi-insert mode while you're using bash? I'm thinking a hollow cursor for command mode and solid for insert...
Nope. That's one of the reasons I stopped using vi mode.
Rather than submitting a patch?
Dusty
Me too. Are you sure the answer is "nope" though? If so, a patch is required, I'll see what I can do.
Offline
I'm also using bash in vi mode but wanted to save some of the emacs keybindings...especially ctrl-l to clear the screen. I ended up putting them in ~/.bashrc:
bind '"\C-p": history-search-backward'
The binding works in other readline enabled apps, not just bash.
Your topic, though got me thinking on this again. Looking at /etc/inputrc you can see bindings like:
"\e[1~": beginning-of-line
"\e[4~": end-of-line
so maybe we've just got the syntax wrong.
edit: apparently this only works without set keymap vi in ~/.inputrc
Last edited by PeteMo (2008-09-10 10:54:46)
Offline
phrakture wrote:Dusty wrote:While I'm on the topic, is there a way to get a visual indicator of whether you're in vi-command or vi-insert mode while you're using bash? I'm thinking a hollow cursor for command mode and solid for insert...
Nope. That's one of the reasons I stopped using vi mode.
Rather than submitting a patch?
Dusty
I have my zsh set up to show "-- INSERT --" or "-- NORMAL --" above my prompt depending on editing mode by using zle features; not sure if there's an equivalent in bash.
-nogoma
---
Code Happy, Code Ruby!
http://www.last.fm/user/nogoma/
Offline
I'm not on a linux box atm, but did you try:
$if editing-mode=vi "\C-p": history-search-backward $endif
That didn't work either
Me too. Are you sure the answer is "nope" though? If so, a patch is required, I'll see what I can do.
I did a search for 'readline vi visual mode indicator' on google and the top result was this thread. Similar searches don't yield any tutorials, but interestingly, they also don't yield any requests for this feature. I can't imagine I'm the first to think of it, so that must mean google sucks.
The binding works in other readline enabled apps, not just bash.
It doesn't work in python for me... ;/ vi mode is enabled, but putting the bind in .bashrc does not enable the ctrl-p keybinding in the python interpreter.
I'm starting to train myself to use <esc>/command and the n and p commands to move through results, but I really think the ctrl-P is a better option fro me. I use ctrl-P in vim all the time for completion, so it makes sense to use it on the commandline for the same purpose.
Dusty
Offline
I can't get the history-search-back and -forward to work.
My .inputrc:
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": history-search-backward
"\e[6~": history-search-forward
"\e[3~": delete-char
"\e[2~": quoted-insert
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
set completion-ignore-case off
set bell-style none
set expand-tilde on
set convert-meta off
set input-meta on
set output-meta on
set show-all-if-ambiguous on
set visible-stats on
Should there be an include command in any other file for .inputrc? Why my terminal (gnome-terminal atm) does not respond to the page up and down keys? In fact, it ignores page up and prints "~" when hitting page down. It seems that i can't fix that. What now?
Offline
Dusty wrote:While I'm on the topic, is there a way to get a visual indicator of whether you're in vi-command or vi-insert mode while you're using bash? I'm thinking a hollow cursor for command mode and solid for insert...
Nope. That's one of the reasons I stopped using vi mode.
I use screen and zsh. Zsh have a widget that is called every time you change the mode (from normal to insert) I used it to chance my hardstatus of screen to show the mode. Look at screenshot:
Full: http://www.soc.if.usp.br/~kazuo/zsh_vi_screen_f.png
You need to put something like this in zshrc:
show_mode() { printf '\e_--%s--\e\' $1 }
bindkey -v
show_mode INSERT
zle-keymap-select() {
if [[ $KEYMAP == vicmd ]]; then
show_mode NORMAL
else
show_mode INSERT
fi
}
zle -N zle-keymap-select
(I put some cases in showmode for other terms too...)
And put a '%h' at the end of you hardstatus in screenrc. Like this:
hardstatus alwayslastline " %{= kK}%-w%{+b W}%n %t%{-}%+w%=%{+b W}%h%{= dd} "
For me this is working great.
Offline
That's pretty nifty. Thanks.
archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson
Offline
Hello Arch-people!
This is my .inputrc file.
set editing-mode vi
$if mode=vi
set keymap vi-command
# these are for vi-command mode
"\e[A": history-search-backward
"\e[B": history-search-forward
set keymap vi-insert
# these are for vi-insert mode
"\e[A": history-search-backward
"\e[B": history-search-forward
$endif
It works.
Offline
Nikitka: You registered in 2007, yet haven't posted here until today?
Most useful first post!!
Your solution works flawlessly, thank you very much. I really appreciate it.
Dusty
Offline
While I'm on the topic, is there a way to get a visual indicator of whether you're in vi-command or vi-insert mode while you're using bash? I'm thinking a hollow cursor for command mode and solid for insert...
Dusty
I've created the readline patch along with some visualization script.
Have a look here.
Offline
mirci.... maybe you should create a thread in the Community Contributions. It will probably help out more users that way.
Closing this one for necro-bumping.
There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !
Offline
Pages: 1
Topic closed