Reputation: 11
using vim + janus (https://github.com/carlhuda/janus) is enabled by default in .vim/vimrc
filetype plugin indent on
i'm writing perl, every newline is indented by default.
how i can select a block (or the full document) and reindent automatically?
Upvotes: 1
Views: 883
Reputation: 40937
Since you're asking about perl I'm assuming "blocks" are identified by {
and }
. If that's the case, I'd suggest indenting the block by using one of the following from somewhere inside the block:
>i{
to forcibly indent all lines by one shiftwidth
=i{
to reindent the block per the indent rules for perlI personally prefer the latter, but if you have some non-standard indentation you don't want to screw up inside the block then you'd want to use the prior.
This takes advantage of vim's "Block" text objects to operate on only the desired text.
Upvotes: 3
Reputation: 42238
To apply the same formatting to the whole document you can use:
gg=G
which means "go to the beginning", "reformat" until "end of document".
You can use :help =
to get more information on reformatting.
If your block is a paragraph separated by empty line you, can use vip
to select it quickly.
See :help text-objects
for more information.
Upvotes: 3
Reputation: 5606
You can select the block by going to visual mode (press v
or Shift + v
or Ctrl + v
in normal mode). Reindent can be done pressing =
after selection of the block.
Upvotes: 3