简体   繁体   English

Notepad++ 中 Python 的自动缩进

[英]Automatic indentation for Python in Notepad++

I've been googling lots and this is getting really frustrating.我一直在谷歌搜索,这真的很令人沮丧。 It doesn't act like idle.它不像空闲。

Example:例子:

else:  
    name = 'World'
    print 'Howdy', name
    print 'yay'

but in Notepad++但在记事本++

else: # i press enter and this is what it does
lands me here

But I want to be able to do like in idle: after the : I can just press enter and keep on going.但我希望能够在 idle: 之后做类似的事情:我可以按 Enter 并继续前进。 My English isn't that great.我的英语不是那么好。

I have my filetype set to Python etc. and my format to unix.我的文件类型设置为 Python 等,我的格式设置为 unix。

This is what you want:这就是你想要的:

Settings > Preferences > MISC.设置 > 首选项 > MISC。 > Auto-Indent (checkbox) > 自动缩进(复选框)

-- ——

Sometimes people ask, "How can I do x in program y?"有时人们会问,“我怎样才能在程序 y 中做 x?”

I have a dream that one day "Use program z instead" will not be the most popular response.我梦想有一天“改用程序 z”不会成为最受欢迎的回应。

I played a bit with python in Notepad++ and I had a problem with the tab.我在 Notepad++ 中玩了一些 python,但我的选项卡有问题。 Since in python your indentation is really important but notepad ++ put space instead of a tab.由于在 python 中,您的缩进非常重要,但记事本 ++ 放置了空格而不是制表符。

So to change to tab you need to go in notepad ++ Menu Settings > Preferences... then select Tab Settings Then select python in the Tab Settings box and uncheck Use default value and check Replace by space .所以要更改为选项卡,您需要进入记事本++菜单设置>首选项...然后选择选项卡设置然后在选项卡设置框中选择python并取消选中使用默认值并选中替换为空格

Like the other answer, you might want to consider another ide.像另一个答案一样,您可能需要考虑另一个想法。 I personally use eclipse with the pydev plugin and django plungin.我个人使用带有 pydev 插件和 django 插件的 eclipse。 Erik is nice too.埃里克也不错。

I found the Python Indent plugin on the official plugin page, and it worked fine!我在官方插件页面上找到了 Python Indent 插件,效果很好!

http://docs.notepad-plus-plus.org/index.php/Plugin_Central#Phttp://docs.notepad-plus-plus.org/index.php/Plugin_Central#P

Well, here is a updated answer:好吧,这是一个更新的答案:

Notepad++ >> Plugins >> plugin manager >> show plugin manager >> find (python indent) click install >> should be downloaded you need to reach to enable again from Plugins>>python indent>>enable Notepad++ >> 插件 >> 插件管理器 >> 显示插件管理器 >> 查找(python 缩进)单击安装 >> 应该下载您需要从插件>>python 缩进>>启用再次启用

Go to Settings > Preferences > Language转到设置 > 首选项 > 语言

Then on the "Tab Settings" box select "python" and tick the "Use default value" checkbox.然后在“选项卡设置”框中选择“python”并勾选“使用默认值”复选框。

You're welcome.别客气。

PS Yeah, I know this a little old. PS 是的,我知道这有点老了。 I really just couldn't help it.我实在是忍不住了。 Anyway, this is for version v7.3.2.无论如何,这是针对 v7.3.2 版本的。

-- For Newer Versions , Goto Settings>>Preferences>>Auto-Completion>>Auto-Indent(checkbox) -- 对于较新版本,转到设置>>首选项>>自动完成>>自动缩进(复选框)

-- For Older Versions , Goto Settings > Preferences > MISC. -- 对于旧版本,转到设置 > 首选项 > MISC。 > Auto-Indent (checkbox) > 自动缩进(复选框)

By the time of this post, The newest Version of Notepad++ is v7.8.7.(tested)到本文发布时,Notepad++ 的最新版本是 v7.8.7。(已测试)

  1. Click on Settings点击设置
  2. Click Preferences...单击首选项...
  3. Browse drop-down menu to find MISC.浏览下拉菜单以查找MISC。
  4. Tick the box which says Auto-indent勾选自动缩进的框

After that, you should be fine.在那之后,你应该没事。

之后重新启动 Notepad++,然后它就可以工作了。

This is for Notepad++ version v8.1.9.3 (the latest as of today)这是针对 Notepad++ 版本 v8.1.9.3(截至今天的最新版本)

Before starting this, save your work... but no need to close any open tab在开始之前,保存您的工作...但无需关闭任何打开的选项卡

First;第一的; install the plugin安装插件

Plugins > Plugins Admin > Search: Python Indent > Python Indent ( check box ) > Install > Yes插件 > 插件管理 > 搜索: Python 缩进> Python 缩进(复选框)> 安装 > 是

Notepad++ will restart... it will take 10 seconds or so Notepad++ 将重新启动...将需要 10 秒左右

Second;第二; enable the plugin启用插件

Plugins > Python Indent > Enable插件 > Python 缩进 > 启用

Third;第三; Have fun!玩得开心!

Do a test... and let me know做个测试……让我知道

None of the above solutions worked for me but this worked:上述解决方案都不适合我,但这有效:

  • Install latest version of notepad++ (as of Feb 2022)安装最新版本的记事本++(截至 2022 年 2 月)

  • Goto Settings -> Preferences -> Language -> Tab Settings -> Select Python -> Uncheck (Default Value) and make sure that the 'Replace by space' is selected with 4 as the count转到设置 -> 首选项 -> 语言 -> 选项卡设置 -> Select Python -> 取消选中(默认值)并确保选择“用空格替换”,计数为 4

  • Next, goto Settings -> Preferences -> Auto-Completion -> Enable Auto-Indent (if it's not already enabled)接下来,转到设置 -> 首选项 -> 自动完成 -> 启用自动缩进(如果尚未启用)

This should work as expected as it's working for me.这应该按预期工作,因为它对我有用。

In Notepad++ version v8.4.4 The Auto Indent is located in Settings->Preferences->Auto-Completion and no longer in MISC.在 Notepad++ 版本 v8.4.4 中,自动缩进位于 Settings->Preferences->Auto-Completion 中,不再位于 MISC 中。 However, for Python indentation it didn't work for me.但是,对于 Python 缩进,它对我不起作用。 What worked is to use the Python Indent plugin (set to Enable).有效的是使用 Python 缩进插件(设置为启用)。 自动缩进

Python缩进插件

A better ide might be spyder.更好的ide可能是spyder。 http://code.google.com/p/spyderlib/ its about the best IDE I have found. http://code.google.com/p/spyderlib/它是我找到的最好的 IDE。

Geany is a fast and light-weight cross-platform IDE, it supports auto-completion and auto-identation for python code, execute run your program , integrated console , plus has asymbol list side pannel that lets you visualize and browse you code easily, you can jump directly to function definitions and the likes using the context menu, plus it's open source Geany是一个快速、轻量级的跨平台 IDE,它支持 python 代码的自动完成和自动识别,执行运行你的程序,集成控制台,还有一个符号列表侧面板,让你轻松地可视化和浏览你的代码,您可以使用上下文菜单直接跳转到函数定义等,而且它是开源的

How ever for a full fledged IDE i would recommand Eric4对于一个成熟的 IDE,我会推荐Eric4

I've found Notepad++ to live up to the task of being a better basic text editor than Notepad, but it isn't really designed to be as smart as a proper programming IDE.我发现 Notepad++ 能够胜任成为比 Notepad 更好的基本文本编辑器的任务,但它实际上并没有像适当的编程 IDE 那样智能。

It might be possible to get it to do what you're asking for, but I certainly don't know how to set it up that way.有可能让它做你所要求的,但我当然不知道如何设置它。

Emacs has python-mode which (also) does it. Emacs 有 python-mode 它(也)做到了。 Grab it and prepare for life-time enjoyment.抓住它,准备终生享受。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM