0

I find that one of my most common actions is to insert a space, therefore I am thinking about changing the spacebar to insert a space. Right now I rarely use the space bar in normal mode, which is tragic because it is the most accessible key on the board, so by logic it should be mapped to something useful.

The normal mode use is to move forward one space (like l), the difference being that l actually means "move right" and space means move one character forwards, which means that space can move forwards past end of line, but l cannot.

It would seem to make sense to change l to have the space behavior and change space to insert a space.

Are there any gotchas or non-obvious problems with this idea?

  • 3
    l can move wherever you want if you set virtualedit to all. Also, a popular mapping for Space is to toggle folds (i.e. an alias for za). For what it's worth. – Sato Katsura Jul 7 '16 at 15:50
  • 1
    In my opinion if you need to regularly use a right motion like l (or space in its original behavior) to go to the beginning of the next line, you're not using the motions properly. Also I don't understand how inserting a space can be a common task in normal mode. Now if you really feel like this is necessary to do these mappings you can always try them, their shouldn't be any problem... On a side note: you are right the space bar is the most accessible key so you remap it to something you use really often: I think your best bet is to make it your leader key. – statox Jul 7 '16 at 15:59
  • @statox Where did I say that I used L to go past end of line. In fact, I said the opposite, that I "rarely" use it. – Tyler Durden Jul 7 '16 at 16:04
  • 2
    @TylerDurden It would seem to make sense to change "l" to have the "space" behavior I understand that as nnoremap l <space> which would make l go to the next character including the first of the next line. My point was: 1) don't remap l let it work as it is meant to work 2) If you want to remap <space> to insert a space why not but making it your leader is -in my opinion- a better option. – statox Jul 7 '16 at 16:12
  • @statox Bit late to the party, but set whichwrap+=l is probably a better way of achieving [the thing you’re recommending not to do] ;). – Rich Nov 23 '18 at 12:31
5

I would recommande mapping space to the leader key instead.

The space key is such a huge key that it may be your "personal namespace" for normal mapping.

Depending on your configuration, you may find that you have a lot of mapping that are only making sens to you. So, having them inside a "namespace" (just an image, there is no relation).

You can set in your .vimrc:

let mapleader="\<Space>"

And then define new mapping with the "namespace" of the leader key:

nnoremap <leader>a ...
nnoremap <leader>b ...

Then if you use the action "insert a space" often you can map it like so:

nnoremap <leader>i i <ESC>
nnoremap <leader>a a <ESC>

To insert a space before and after the cursor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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