Should be trivial, and it might even be in the help, but I can't figure out how to navigate it. How do I indent multiple lines quickly in vi?
相关问题
- Emacs shell: save commit message
- How to change the first two uppercase characters o
- Insert text into current buffer from function
- Hot reload on save
- Substituting zero-width match in vim script
As well as the offered solutions, I like to do things a paragraph at a time with
>}
do this
and add this line
this is only for cpp file you can do this for another file type also just by modifying the filetype...
There is one more way that hasn’t been mentioned yet - you can use
norm i
command to insert given text at the beginning of the line. To insert 10 spaces before lines 2-10:Remember that there has to be space character at the end of the command - this will be the character we want to have inserted. We can also indent line with any other text, for example to indent every line in file with 5 underscore characters:
Or something even more fancy:
More practical example is commenting Bash/Python/etc code with # character:
To re-indent use x instead of i. For example to remove first 5 characters from every line:
I dont know why its so difficult to find a simple answer like this one...
I myself had to struggle a lot to know this its its very simple
edit your
.vimrc
file under home directory add this linein you file where you want to indent properly
in normal/command mode type
I like to mark text for indentation:
PS: you can use :'a,'z technique to mark a range for any operation (d,y,s///, etc) where you might use lines, numbers, or %
For block of code {}: = + %
For selected line: Shift + v select using up/down arrow key then press =.
For entire file: gg + = + G
Note: 'gg' means go to line 1, '=' is the indent command, and 'G' moves the cursor to the end of file.