0

Okay so I want to create a custom command (and place it in my .vimrc file using the :command command, if possible) which basically indents the line which the cursor is on and then moves to the next line. Any idea on how to do this?

SilentDev
  • 15,207
  • 26
  • 87
  • 180
  • 1
    Why do you want a command to do this? If you are trying to indent a block of text use `>>` (Example `10>>` to indent 10 lines). Or do you want to reindent the whole file `gg=G`? Or you can write a macro to indent the current line and move down one. Creating a command for this seems overkill – FDinoff Sep 25 '13 at 03:09
  • `:Q` is so much faster and efficient than `>>j`. – romainl Sep 25 '13 at 07:31

1 Answers1

1

Do this:

 :nnoremap Q >>j

This will map Q to do what you want.

You can replace Q with anything.

You can make the above mapping permanent by putting it in your .vimrc (with no : character).

For more info check out :h map

jahroy
  • 20,588
  • 9
  • 52
  • 104
  • 1
    You can use `>>` to indent the current line – FDinoff Sep 25 '13 at 02:56
  • @FDinoff right but I want a code which indents and then goes to the next line – SilentDev Sep 25 '13 at 03:06
  • @jahroy, will the code you provided override the original function of Q? – SilentDev Sep 25 '13 at 03:06
  • @user2719875 - yes, but please check out my edit: you can replace `Q` with anything you want (including control sequences) – jahroy Sep 25 '13 at 03:07
  • perfect, thanks! On a side note though, if I did put that code in my .vimrc file and override the original function of Q, if I later go and delete that code from the .vimrc file, will my original function for Q come back and will Q start doing what it originally was supposed to do again? – SilentDev Sep 25 '13 at 03:10
  • Yes, deleting that mapping from your `.vimrc` file would restore the default functionality to `Q`. – jahroy Sep 25 '13 at 03:18