To indent HAML code I usually add or delete 2 spaces. Adding I do:
- Enter visual mode ( ctrl + v)
- jj to select the lines
- shift + i to go into insert
- type 2 spaces
- ESC
That's it 2 spaces are added. However to remove the spaces, I't does not work, for example doing:
- Enter visual mode ( ctrl + v)
- jj to select the lines
- shift + i to go into insert
- Delete 2 spaces ( with backspace or delete)
- ESC
This just does not work, other lines spaces are not deleted. How then can I do this ?
Here is an example code:
.module_1
.pricing_details
%h2
Save
The idea is moving everything so it matches 2 space in respecto .module_1 as:
.module_1
.pricing_details
%h2
Save
The propose sol开发者_StackOverflow社区ution using < > works only for indenting now I'd like to for example:
.module_1
.pricing_details
%h2
Save
move the above to:
.module_1
.pricing_details
%h2
Save
Try < and > commands. You will need :set shiftwidth=2
for them to work in this way.
UPDATE
Considering your last example, changing
.module_1
.pricing_details
%h2
Save
to ⇓
.module_1
.pricing_details
%h2
Save
can be accomplished with moving to .pricing_details
line and hitting Vjj<
.
Highlight your text and do:
<
Use:
.
To repeat the action multiple times. Note that this will shift the text whatever your shift width is. If it is not 2, you can set it to 2 by doing:
:set sw=2
You can indent text the same way by using ">".
All of this is in the documentation: http://vimdoc.sourceforge.net/htmldoc/usr_25.html#25.3
in the vimrc:
" pressing F5 adds two spaces at beginning of line and goes to next line
inoremap <F5> <ESC>:s/\(.*\)/ \1/e<CR>:set nohlsearch<CR>ji
" also works when not in edit mode
map <F5> i<F5><ESC>
" F6 removes two spaces from the end of whitespace at the beginning of line
inoremap <F6> <ESC>:s/\(^\s*\)/\1/e<CR>:set nohlsearch<CR>ji
map <F6> i<F6><ESC>
To remove 2 spaces from the beginning of every line of a paragraph just press F5 through all its lines.
This is modeled after my keybindings for commenting and uncommenting C code (the difference is in the regex of course)
only drawback is it needs to disable search highlight since the regex matches damn near the entire document all the time.
精彩评论