Indenting in The Art of Vim shortcut

Hi, this question is about Ben Orenstein’s screencast on indenting in The Art of Vim.
He shares a shortcut which should be mapped to the <Leader> + i combination.

map <Leader>i mmgg=G`m

The problem I’m having is that pressing “i” right after my <Leader> key puts me right into insert mode and so the mapping does nothing.

Hi, @fdelacruz! I think the mapping is:

map <leader>i mmgg=G`m<CR>

This will require a call to your leader first and then to i, which will prevent you from going into insert mode when calling that super nice formatting command.

Oh, and a small word of warning. This mapping does overwrite whatever may have been in your ‘m’ marker when you run it. It was no show stopper for me, and it is simple to change it to another marker if you wanted to. In this example I changed the marker to ‘x’:

map <leader>i mxgg=G`x<CR>

The only reason I mention it is that a lot of vimmers like to just double tap ‘m’ for a quick marker while they’re working around a file.

1 Like

Oh… That’s strange. The code tag here takes away the most important part of that post, that it needs to have the leader in it. It shows in the preview but doesn’t in the actual posting. Sorry about that!

Here’s a gist of what those two should actually be:

Thanks @geopet, my problem was that I was setting my <Leader>, “,” in my case, way after the mapping so it was NOT being set after all. Once I moved it above the mapping I was able to indent away with just two fingers. :slight_smile:

@fdelacruz Gotchya! Glad you got it figured out! :smiley: