How to move a large section of Python code forward by one tab under vim?
伊谢尔伦
伊谢尔伦 2017-05-16 16:41:40
0
11
1652

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?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(11)
漂亮男人

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_u1582

:10,100>
Indent line 10 to line 100
:20,80<
Line 20 to line 80 are anti-indented

滿天的星座

In normal mode, the cursor is on the starting line that needs to be processed, then: 100>>

曾经蜡笔没有小新

1,^V in front of the line that needs to be indented;
2,I;
3. tab

世界只因有你

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

洪涛

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'

for details
左手右手慢动作

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!

Peter_Zhu

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

给我你的怀抱

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.

vimlvnoremap <tab> >gv
vnoremap <s-tab> <gv

Take the subject’s question as an example.

  1. Move to the first line of the target area
  2. Enter v to enter selection mode
  3. Enter 100j to move down 100 lines. At this time, the target area of ​​100 lines has been selected
  4. Enter the < tab > key.

End~

漂亮男人

Provide another method without entering V mode.

  1. Move to the first line that needs to be processed, ma

  2. Move to the last line that needs to be processed, <'a

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!