Editing a .jar with `vim`

However after selecting a file (eg. AbstractComponent.class) and press Enter, within vim I get:

caution: filename not matched

This is probably a known bug in vim's ZIP plugin - the plugin does not properly handle ZIP files that contain ZIP comments. See e.g. this mailing list post

As a side note, I also noticed that if I extract the jar (either with unzip or jar) and open an extracted file with vim, the contents are misformatted

This is because most files inside a JAR are compiled Java class files (file suffix .class). These are binary data, and vim is not really suitable for editing them, because vim is a text editor, not a binary editor.

You can edit them in vim using the xxd command (see "Using xxd" in the vim docs), or you can use a hex editor, such as bvi.

At any rate, directly viewing the contents of a class file is rarely helpful, as you need to understand the binary class file format to read them.

Could you explain why you are trying to open files inside a JAR? Then maybe we can help.

Tags:

Linux

Vim

Jar