Clearing screen when using Vi keybindings on Bash command-line

1,134 views
Skip to first unread message

Srikanth Cherla

unread,
Mar 14, 2014, 1:02:11 PM3/14/14
to vim...@googlegroups.com
Hi,

I recently switched to using Vi keybindings in bash shell as described here http://vim.wikia.com/wiki/Use_vi_shortcuts_in_terminal. It's great, except that ^L (Ctrl + l) does not clear screen any more. I tried the two options mentioned in the link but neither of them works. I also tried adding the line

alias ^L='clear'

in my .bashrc but that didn't work. Can someone suggest what else I can do?

Thanks!

Tim Chase

unread,
Mar 14, 2014, 7:19:51 PM3/14/14
to vim...@googlegroups.com, frea...@gmail.com
On 2014-03-14 10:02, Srikanth Cherla wrote:
> http://vim.wikia.com/wiki/Use_vi_shortcuts_in_terminal. It's great,
> except that ^L (Ctrl + l) does not clear screen any more. I tried
> the two options mentioned in the link but neither of them works. I
> also tried adding the line

Control+L works in Emacs editing mode (which I tend to prefer for
general command-line operations), but seems to have strange behavior
in vi mode. In some contexts, it seems to correctly clear the
screen; but in other contexts (which I haven't completely sussed
out), it seems to ignore the control+L. You could try explicitly
adding

"\C-l": clear-screen

in your ~/.inputrc

> alias ^L='clear'
>
> in my .bashrc but that didn't work. Can someone suggest what else I
> can do?

The alias doesn't work for reasons I'd expect for multiple reasons.

-tim







Marcin Szamotulski

unread,
Mar 14, 2014, 8:36:45 PM3/14/14
to vim...@googlegroups.com
Just press <Esc> and then CTRL-L, at least it works for me in bash in an
xterm. It does not work in in the insert mode.

Cheers,
Marcin

Tim Chase

unread,
Mar 14, 2014, 8:50:40 PM3/14/14
to vim...@googlegroups.com
On 2014-03-15 00:36, Marcin Szamotulski wrote:
> On 18:19 Fri 14 Mar, Tim Chase wrote:
>> On 2014-03-14 10:02, Srikanth Cherla wrote:
>> > http://vim.wikia.com/wiki/Use_vi_shortcuts_in_terminal. It's
>> > great, except that ^L (Ctrl + l) does not clear screen any
>> > more. I tried the two options mentioned in the link but neither
>> > of them works. I also tried adding the line
>>
>> Control+L works in Emacs editing mode (which I tend to prefer for
>> general command-line operations), but seems to have strange
>> behavior in vi mode. In some contexts, it seems to correctly
>> clear the screen; but in other contexts (which I haven't
>> completely sussed out), it seems to ignore the control+L. You
>> could try explicitly adding
>>
>> "\C-l": clear-screen
>>
>> in your ~/.inputrc
>
> Just press <Esc> and then CTRL-L, at least it works for me in bash
> in an xterm. It does not work in in the insert mode.

Yeah, I just couldn't figure out how to get .inputrc to perform a
"clear-screen" on control+L in vi-insert mode in addition to
vi-command mode. And there were some edge cases where control+L
*did* work without hitting <esc> first (perhaps before entering a
command?).

-tim


John Little

unread,
Mar 15, 2014, 12:20:13 AM3/15/14
to vim...@googlegroups.com
On Saturday, March 15, 2014 6:02:11 AM UTC+13, Srikanth Cherla wrote:
>
> I recently switched to using Vi keybindings in bash shell ... ^L (Ctrl + l) does not clear screen any more.

With bash vi mode there are two keymaps, corresponding to vim's normal mode and insert modes, called vi-command and vi-insert. ctrl-L works by default in vi-command mode, so typing <esc><ctrl-l> will do it, but needs another keystroke "a" to get back to insert mode.

For ctrl-L to work in insert mode, you need a ~/.inputrc file, that specifies the keymap:

set keymap vi-insert
"\C-L": clear-screen

> alias ^L='clear'

You have to press enter to invoke an alias, and it has to be the first word on the line, not at all like the ctrl-L you're used to.

Regards, John Little

Srikanth Cherla

unread,
Mar 15, 2014, 4:44:09 AM3/15/14
to vim...@googlegroups.com
^L works after pressing <Esc>. I don't know how I missed that. I did try it a few times before posting the question and it didn't work then. My sincere apologies for posting the question, and thank you to those who replied.

Srikanth
Reply all
Reply to author
Forward
0 new messages