简体   繁体   English

使用VIM查看同一文件时,Emacs缩进不起作用

[英]Emacs indentation doesn't work when looking at the same file with VIM

I'm having a problem with indentation in Emacs. 我在Emacs中出现缩进问题。

Whenever I'm indenting code in Emacs it looks fine, but when I look at the same code in VIM/Github/Eclipse, there's parts of code that isn't indented. 每当我在Emacs中缩进代码时,它看起来都很好,但是当我在VIM / Github / Eclipse中查看相同的代码时,有部分代码没有缩进。

Examples: 例子:

This is what I see in Emacs: 这是我在Emacs中看到的:

public class Test {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

This is what I see in the other editors: 这是我在其他编辑器中看到的:

public class Test {
    public static void main(String[] args) {
    System.out.println("Hello, World!");
    }
}

The languages I'm seeing this in is: - C - Java - JavaScript 我看到的语言是:-C-Java-JavaScript

I haven't tried to simulate the behaviour in other languages atm... 我没有尝试模拟其他语言atm的行为...

I'm also seeing these symptoms in some of the code I receive from some of my teachers that I know use Emacs to generate pre-code that I'll be looking at in Eclipse/VIM/Github. 我从一些老师那里收到的一些代码中也看到了这些症状,我知道他们使用Emacs生成了我将在Eclipse / VIM / Github中查看的预代码。

One extra thing: using 'cat' on linux displays indentation, made by Emacs, correct! 还有一件事:在Linux上使用'cat'可以显示由Emacs制作的缩进,正确! It's the only thing besides Emacs that can do that.... 这是除Emacs之外唯一可以做到的事情。

Is there any way to prevent this? 有什么办法可以防止这种情况? It isn't a big problem, but VERY irritating atm and I haven't been able to come up with a solution. 这不是一个大问题,但是非常令人烦恼的atm,我一直无法提出解决方案。

This is very likely a tabs vs. spaces issue. 这很可能是制表符与空格的问题。 Emacs is probably displaying the tabs as eight spaces as this is the standard that cat would use. Emacs可能会将选项卡显示为八个空格,因为这是cat使用的标准。

Run :set list in vim to see what characters are making up the whitespace. 在vim中运行:set list来查看由哪些字符组成的空格。 If you want the indentation show up the same you either need to configure all the editors to use the same indentation (preferable) or configure them to at least show tabs as the same number of spaces. 如果希望缩进显示相同,则需要将所有编辑器配置为使用相同的缩进(首选),或者将它们配置为至少将选项卡显示为相同数量的空格。

Relevant vim settings: expandtab , tabstop . 相关的vim设置: expandtabtabstop
Relevant emacs settings: tab-width , indent-tabs-mode . 相关emacs设置: tab-widthindent-tabs-mode

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

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