Vim使Python代码缩进错误(使用python-mode插件)

时间:2017-07-03 23:31:13

标签: python vim python-mode

如下面的屏幕播放所示,我在向Python代码添加注释时演示了Vim的奇怪行为。在演示1和演示2之间,我只是在不同的缩进级别(在类定义中)开始注释行。

演示1

enter image description here

演示2

enter image description here

问题:

正如在屏幕播放结束时所示,只有在插入模式下键入:才能使缩进正确。

理想的解决方案将实现:

在开始评论时,请正确留下缩进级别;

2 个答案:

答案 0 :(得分:1)

这听起来像是一个vim设置问题。从vanilla vim开始,当我创建一个新行时,每行都没有缩进。如果我在.vimrc目录中创建名为home的文件。即~/.vimrc并放

filetype indent plugin on

在文件中,我得到了似乎预期的缩进行为。那对你有用吗。

答案 1 :(得分:1)

我案例中的解决方案

我评论了以下一行,一切都很顺利。对评论没有进一步的奇怪修正。 set smartindent

我的Vim的其他信息:

为了缩进,这里是设置:

filetype plugin on
filetype indent on
set autoindent

此外,已经证实python-mode没有错。使用python-mode或不set smartindentset smartindent一直让我遇到问题。

暂定结论:

C:/vim/vimfiles/ftplugin/python.vim可能不正常,我的折叠方法指定如下。此类设置位于setlocal formatoptions=crnqj

c

这里是使用的字符的对应关系,但似乎没有一个麻烦。

  • r:使用textwidth自动换行评论,自动插入当前评论标题。

  • <Enter>:在插入模式下点击n后自动插入当前评论标题。

  • 1. the first item wraps 2. the second item :格式化文本时,识别编号列表。这实际上是用的 &#39; formatlistpat&#39;选项,因此可以使用任何类型的列表。该 数字用于下一行后的文本缩进。该 默认是查找号码,可选地后跟&#39;。&#39;,&#39;:&#39;,&#39;)&#39;, &#39;]&#39;或者&#39;}&#39;。请注意&#39; autoindent&#39;也必须设置。不行 与&#34; 2&#34;一起使用。 例如:

    q
  • j:允许使用&#34; gq&#34;格式化评论。 请注意,格式化不会更改空白行或包含的行 只有评论的领导者。在这样一条线之后开始一个新的段落, 或者当评论领导者改变时。

  • #:合理的地方,在加入行时删除评论主管。

参考更好的框架+答案解决方案

简而言之,我在编辑Python脚本时观察到的并不是&#34; Python文件类型&#34;单独。它与符号import xlrd workbook = xlrd.open_workbook('GAT_US_PartReview_2017-06-23.xlsx') worksheet = workbook.get_sheet(0, update_pos=True) header = [] report_card = [] # Count Stmnts for Required Data valid_count = 0 app_req_count = 0 intr_req_count = 0 oe_intr_req_count = 0 part_img_req_count = 0 upc_req_count = 0 unspsc_req_count = 0 msds_req_count = 0 # Count Stmts for Missing Data missing_app_count = 0 missing_intr_count = 0 missing_oe_intr_count = 0 missing_mpcc_count = 0 missing_attr_values_count = 0 missing_part_img_count = 0 missing_upc_count = 0 missing_warr_text_count = 0 missing_warr_pdf_count = 0 missing_unspsc_count = 0 missing_msds_count = 0 for row_num, row in enumerate(worksheet): if row_num <= 4: # print(row) # Print out the header header.append([row[0], row[2]]) else: hq_line, part_no, part_class, appl_req, appl_count, intr_req, intr_count, oe_intr_req, has_oe_intr, has_attr_editor, has_attr_values, part_img_req, has_part_img, has_mpcc, warr_req, has_warr_txt, has_warr_pdf, msds_req, has_msds, upc_req, has_upc, has_unspsc, attr_count, attrval_count, valid_part = row if valid_part == 'YES': valid_count += 1 # Required Parts Count if appl_req == 'YES': app_req_count += 1 if intr_req == 'YES': intr_req_count += 1 if oe_intr_req == 'YES': oe_intr_req_count += 1 if part_img_req == 'YES': part_img_req_count += 1 if upc_req == 'YES': upc_req_count += 1 if msds_req == 'YES': msds_req_count += 1 # Missing Data Counts if appl_req == 'YES' and appl_count == '0': missing_app_count += 1 if intr_req == 'YES' and intr_count == '0': missing_intr_count += 1 if oe_intr_req == 'YES' and has_oe_intr == '0': missing_oe_intr_count += 1 if has_mpcc == 'NO': missing_mpcc_count += 1 if has_attr_values == 'NO': missing_attr_values_count += 1 if has_part_img == 'NO': missing_part_img_count += 1 if upc_req == 'YES' and has_upc == '0': missing_upc_count += 1 if warr_req == 'YES' and has_warr_txt == 'NO': missing_warr_text_count += 1 if warr_req == 'YES' and has_warr_pdf == 'NO': missing_warr_pdf_count += 1 if has_unspsc == 'NO': missing_unspsc_count += 1 if msds_req == 'YES' and has_msds == 'NO': missing_msds_count += 1 # Statements for Required Counts valid_parts = ('Number of Valid Parts: ', '{:,}'.format(valid_count)) application_required = ('Application Records Required: ', '{:,}'.format(app_req_count)) interchange_required = ('Interchange Records Required: ', '{:,}'.format(intr_req_count)) oe_interchange_required = ('OE Interchange Records Required: ', '{:,}'.format(oe_intr_req_count)) mpcc = ('MPCC Required: ', '{:,}'.format(valid_count)) # Every valid part requires a MPCC attributes = ('Attributes Required: ', '{:,}'.format(valid_count)) # Every valid part requires attributes image_required = ('Image Required: ', '{:,}'.format(part_img_req_count)) upc = ('UPC Requited: ', '{:,}'.format(upc_req_count)) warranties = ('Warranty Text/PDF Required: ', '{:,}'.format(valid_count)) # Require warranty text/pdf on all parts unspsc = ('UNSPSC Code Required: ', '{:,}'.format(valid_count)) # Require UNSPSC Codes for all parts msds = ('MSDS Required: ', '{:,}'.format(msds_req_count)) # Statements for Missing Counts missing_applications = ('Missing Applications: ', '{:,}'.format(missing_app_count)) missing_interchange = ('Missing Interchange: ', '{:,}'.format(missing_intr_count)) missing_oe_interchange = ('Missing OE Interchange: ', '{:,}'.format(missing_oe_intr_count)) missing_mpcc = ('Missing MPCC: ', '{:,}'.format(missing_mpcc_count)) missing_attributes = ('Missing Attributes: ', '{:,}'.format(missing_attr_values_count)) missing_image = ('Missing Image: ', '{:,}'.format(missing_part_img_count)) missing_UPC = ('Missing UPC: ', '{:,}'.format(missing_upc_count)) missing_warranty_text = ('Missing Warranty Text: ', '{:,}'.format(missing_warr_text_count)) missing_warranty_pdf = ('Missing Warranty PDF: ', '{:,}'.format(missing_warr_pdf_count)) missing_unspsc = ('Missing UNSPSC Code: ', '{:,}'.format(missing_unspsc_count)) missing_msds = ('Missing MSDS: ', '{:,}'.format(missing_msds_count)) # CSV Output report_card.append(valid_parts) report_card.append(application_required) report_card.append(interchange_required) report_card.append(oe_interchange_required) report_card.append(mpcc) report_card.append(attributes) report_card.append(image_required) report_card.append(upc) report_card.append(warranties) report_card.append(unspsc) report_card.append(msds) report_card.append(missing_applications) report_card.append(missing_interchange) report_card.append(missing_oe_interchange) report_card.append(missing_mpcc) report_card.append(missing_attributes) report_card.append(missing_image) report_card.append(missing_UPC) report_card.append(missing_warranty_text) report_card.append(missing_warranty_pdf) report_card.append(missing_unspsc) report_card.append(missing_msds) for row in header: print(row) for x in report_card: print(x) with open('Report_Card.csv', 'w', newline='') as f: writer = csv.writer(f) writer.writerows(header) writer.writerows(report_card) ,又名&#34;哈希&#34;有关。