![]() ![]() Now, just press whenever you want to format your file. To format and return the same line where you were, just add this mapping to your vimrc: ![]() If you often re-indent large areas (like the entire file, or a large text object), it can be useful to map a key to do it for you, using marks to restore your position. = will re-indent just the current line, or the = operator can be combined with text-objects for very powerful results. The power of = is certainly not limited to the entire file. Thus, an equivalent but less efficient command to accomplish the same as gg=G in normal mode, would be ggVG to select the entire buffer in visual mode, followed by = to re-indent the entire selection. In visual mode, typing = will fix indentation of the current section. In this case, gg positions the cursor on the first line, then =G re-indents from the current cursor position to the end of the buffer. Just like d or y, it will act on any text that you move over with a cursor motion command. In normal mode, typing gg=G will reindent the entire file. Vim veterans often find this operator to be one of the most useful in their repertoire, but so common that it becomes second-nature and is rarely mentioned. It's possible to reformat an entire file, or a section of a file, using Vim's built-in = filter.
0 Comments
Leave a Reply. |