I pasted a large section of python code under vim, but starting from a certain line, all the code was moved back by one more tab. There were more than 100 lines. I manually adjusted them one by one, and I was exhausted.
Is there any way to make it easier?
漂亮男人2017-05-16 16:43:40
In vim, it is best to enter paste mode before pasting code, so that automatic indentation will be turned off
set paste
Paste the code and then turn off the paste mode
set nopaste
The indentation of a single line of code is two greater than signs '>>'
Retraction is two less than signs '<<'
If you want to indent many lines of code, do the following
1 //在这里按下'v'进入选择模式
1
1
1
1
1
1//光标移动到这里,再按一次大于号'>'缩进一次,按'6>'缩进六次,按'<'回缩。以下同理
function helo{//将光标移动到'{',在按下'%',光标将会移动到匹配的括号
//这里省略1000行
}//光标会移动到这里,再按一次大于号'>'就可以缩进
phpcn_u15822017-05-16 16:43:40
:10,100>
Indent line 10 to line 100:20,80<
Line 20 to line 80 are anti-indented
滿天的星座2017-05-16 16:43:40
In normal mode, the cursor is on the starting line that needs to be processed, then: 100>>
世界只因有你2017-05-16 16:43:40
1 Press Esc to enter command line mode
2 Move the cursor to the starting line that needs to be processed
3 Press v to go to view mode and select all the lines that need to be processed
4 Press Ctrl+<That’s it
PHP中文网2017-05-16 16:43:40
Be careful when pasting in Vim, if Vim cannot know that you are pasting (non-GUI version, mouse support is not turned on in the terminal or the terminal itself does not support the mouse, because Vim does not have X clipboard support and bypasses Vim, use the The Shift key allows the terminal to paste directly (for example, when pasting into Vim in ssh, usually Vim cannot access the local clipboard, so it can only let the terminal "type")), then you need to set the 'paste' option before pasting . This option disables automatic indentation, mapping, etc. in insert mode. See :h 'paste'
ringa_lee2017-05-16 16:43:40
You can play like this:
If you need to delete a tab from line 10 to line 100, you can write like this:10,100s/^t//
That’s ok!
天蓬老师2017-05-16 16:43:40
Define various tabs of python in vimrc, for example:
autocmd FileType python set ts=4 | set sw=4 | set expandtab
Then in normal mode, enter directly =nj
n is the number of lines required to be automatically aligned. No matter how messy the indentation is, it will be automatically aligned
给我你的怀抱2017-05-16 16:43:40
The commands provided by vim below are very flexible, but they are too low-level. At present, all the answers given by the respondents are hard-keyed, which is difficult to remember and inefficient. It is recommended to set them as shortcut keys.
For example, I am used to using tab, selecting the target area and pressing the shortcut key.
viml
vnoremap <tab> >gv vnoremap <s-tab> <gv
Take the subject’s question as an example.
End~
漂亮男人2017-05-16 16:43:40
Provide another method without entering V mode.
Move to the first line that needs to be processed, ma
Move to the last line that needs to be processed, <'a