7

Quite some programs have commands that output with less(e.g. git blame filename). I would like to use my vim configuration(e.g. <C-j> instead of using Pg Down to go down a page) whenever less is used. How do I set this?

According to this thread and the less man page putting export EDITOR=vim and export VISUAL=vim in my ~/.baschrc should use vim for less but I don't see any change after reloading a terminal session and launching less (I can't use my page down hotkey for example).

2
  • Your question is ambiguous. Do you want to use Vim in place of less, or do you somehow want your Vim configuration files to affect less's behavior? The former should be possible, but the latter isn't.
    – Heptite
    Mar 30, 2013 at 21:08
  • I wasn't sure if commands like git blame filename hardcoded the use of less or that they just passed output to the pager you are using. I just wanted to use my vim configuration when using a pager, wether its with less or not with less.
    – Bentley4
    Mar 30, 2013 at 22:27

3 Answers 3

5

The $EDITOR and $VISUAL variables define the editor to use (e.g. when you use the "edit" command inside less).

When programs run less, they run it as a pager, not as an editor – they're looking at the value of $PAGER.

Install vimpager, then:

export PAGER=vimpager
3
  • Awesome! Every time I launch vimpager though I get E21: Cannot make changes, 'modifiable' is off: retab Press ENTER or type command to continue. Any idea how I can set 'modifiable' to on or just simply stop displaying this message?
    – Bentley4
    Mar 30, 2013 at 22:22
  • I've put :set modifiable in my vimrc and it keeps outputting the same message.
    – Bentley4
    Mar 30, 2013 at 22:31
  • Nevermind, it worked after I commented out retab in my .vimrc. Don't know why though.
    – Bentley4
    Mar 30, 2013 at 22:36
3

If you don't want to install vimpager as the accepted answer recommends, there's two hackish sort of workarounds that I've found to just send stdout straight to vim.

1) As a non-global workaround, you can pipe everything that would go to less to
<command_outputting_to_less> | vi -.

2) More globally, you can set
export PAGER='vi -'.
A problem I ran into with this is that the cmd that's sending output to the pager may put color codes into it because it thinks the pager should be able to handle color codes. To correct this, you'll need to strip out the color codes either by a different program or the output program may have the option to remove color codes. For the one I was using (git), I changed this to get it to output correctly git config --global color.ui false.

1

I am not sure what you are exactly after but there are a lot of vi-like key bindings to use with less in its original installation. At least it is so on my Ubuntu Jaunty box. But if you are missing some particular functionality, you can use lesskey program to reassign your key bindings. Running this program will create a file named .less under your home directory. It will be a text file that you can cat or vi or even less to see the contents.

Check the man pages of less (look for KEY BINDINGS) and/or lesskey command to accomplish what you are trying to accomplish.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .