Configure Vim to develop Android [the artifact is an artifact after all]

Source: Internet
Author: User

Android programmers should say that eclipse or netbean is the most widely used. Considering that Google has launched a complete set of development plug-ins that allow users to write code from the project to compile and run the link simulator in one go, it is understandable to use ide like Eclipse. However, there are always some users who do not like IDE and do not want to develop it in a way similar to eclipse. Their ideas include:

  • No editor can match Vim/Emacs
  • My computer is too slow to run ide
  • I like it in the form of command lines. I like it when I call 10000 commands every day.

Pai_^

This article is for this part of users. In fact, for a company like Google with a strong Linux atmosphere, the command line tool provided by Google is enough for you to leave the IDE, that is, there are not many excellent functions of eclipse in editing. However, with eclim introduced in this article, you will find that you have embedded eclipse into vim! Now, after creating a project, from editing the source code to editing and translating to managing the project, to installing the program to the simulator,All tasks can be completed in vim.We really use Vim as the IDE!

Note: I am not a blind fan of CMD. In my opinion, if I really want to develop Android apps, rather than being a bit tricky, IDE is still a little useful:

  • When your project is large and there are many things to manage. Scalable problems may occur when you use Vim to develop programs in any language.
  • When you try to find a bug. Using ddms with eclipse is indeed much more convenient than other methods.

So I use it with cmd and IDE.

The key to implementing the content described in this article is the Open Source Software eclim. You can {
Pagetracker. _ trackpageview ('A/eclim.sourceforge.net ');
} "Href =" http://eclim.sourceforge.net/eclimd.html "> eclim official site learn and download. Next, we will explain the specific installation and use steps for eclim.

Install

Before installation, make sure that your system has

  1. Jdk1.5 or higher
  2. Eclipse 3.5.x
  3. Vim 7.1.x, and set nocompatible in vimrc and open filetype plugin on

First download, we can see from the download page that there are three packages, exeis windows, tar.gz is the source code, SH is the installation script under Linux/MAC. Because the source code package requires ant for configuration and installation, you have to worry about the version, right? So we can directly download the sh file for installation.

After downloading the sh file, execute the command. A graphical interface for installation will pop up, one way to next. Note: Please back up your ~ in advance ~ /. All the original plug-ins under the vim directory, because eclim overwrites the installed plug-ins to this directory by default. You can copy back the original backup plug-in after installation.

Okay. Now that the installation is complete, how can we use eclimd? Eclimd has two modes: Vim in eclipse and eclipse in Vim. Here we mainly talk about the configuration of the vim/gvim environment.

First, like many other programs, eclim has a daemon. Therefore, you must open this daemon every time you want to use it. Open this program by using the eclimd script, which is usually in your ~ Under the/. Eclipse/xxxxxx directory, the specific location depends on the eclipse configuration file directory you specified during installation. If you forget it, use

Find/home-name eclimd 2>/dev/null

Find. Once found, it is recommended to add the path to the path, and then set this command to boot, if you will often use it.

Okay. Now the daemon program is running. Open vim and run the command.

: Pingeclim

If everything works normally, the eclim and eclipse versions will appear. Otherwise, the daemon operation may be abnormal.

Use

Well, if everything is normal here, we will start to use eclim for Android engineering. The following content is the core part of today's speech.

Eclim itself supports the creation of five projects, C/C ++, Java, PHP, Python, Ruby, and engineering creation methods. For details, refer to the instructions on the official website. However, here we do not use eclim itself to create a project. Because the android SDK itself provides this function, and the project created by the SDK has that set of file directories. Remember, we use eclim to provide convenience for Android development, so the overall flow path is still the Android one. Therefore, we should first create a project

Android Create Project-n test-activity demo-package CN. forwind. myproject-Target 3-path./myproject

In this way, the project directory myproject is created under the local directory. After you run the La command, you will find that this is essentially not an eclipse Java project, because there are no. Project and. classpath files. Eclim essentially follows the eclipse specifications. What should I do? It doesn't matter. We can do this. Go to the upper directory of the myproject directory, open vim, and enter

: Projectcreate./myproject-N Java

What does it mean? That is to say, we need to create a Java Eclipse project under the./myproject directory. The./myproject directory already contains all the files created by Android. Therefore, all the files required by both parties are available. Use LA to check if there is another. Project and another. classpath? And the src directory is automatically added to the classpath!

Note: It seems that there is another bug in eclim, that is, the path should not be too deep when a project is created, and an error occurs when there are more than five layers. The solution I used is to put the directory containing the project under the Home Directory to ensure that the path is not very deep. You can also read this android project through eclipse, and it will automatically help you create. Project and. classpath. It is not troublesome, because you only need to do it once for a project.

Okay. Now we have created a new project. Next we will create an AVD.

Android create AVD-N forwind.cn

In this way, the preparation is complete. Now go to the myproject directory and open vim.

First, use

: Projectlist

Command to confirm that the project myproject is recognized. Okay, now we try to run

: Projecttree myproject

Check whether the hierarchical architecture of the entire project is displayed on the left? I believe that all vimer operations should be performed. You can also define this command as a shortcut. You do not need to add a project name later, because the tree chart of the current project is opened by default.

You can also use

: Projectstree

To open the tree map of all projects. If you want to open a file, you will automatically open the tree map of the corresponding project, and add this sentence to your vimrc file.

Let G: eclimprojecttreeautoopen = 1

A friend may have a problem. If I want to open another file in the tree, isn't it overwriting the current file? Of course, friends who are used to buffer operations will think it doesn't matter, but many of them operate on tabs. At this time, you can move the cursor to the file you want to open and press t, in uppercase, the file is automatically opened in another tab. Well, let's take a look at what eclim gave us in addition to Vim's own advantages during the editing process. First, you don't have to worry about the code style, such as braces. You can write your own style and finish a command.
: % Javaformat
You can automatically describe the file layout as the Java code style you set in eclipse. In this way, you only need to set a unified team style in eclipse, so you don't have to worry about writing. This function is equivalent to the <C-S-F> in eclipse. Second, eclim has a relatively elementary code check function, which is equivalent to the quick fix of Eclipse. First, after writing a source code
: Validate
You can let eclim help you check the rows that may be wrong, and mark them with the double left arrow. Then you move the cursor to the row and use the command
: Javacorrect
You can have eclim modify your suggestion. Of course, you can also directly modify it yourself.

Finally, I will introduce the Code Completion that everyone will be very concerned about. The Code Completion of eclim is equivalent to the standard Vim completion method. The shortcut key is "Ctrl x ctrl u ". We all know that the utable shows user define. What is the effect? Take a look at the following :)

{
Pagetracker. _ trackpageview ('A/2.bp.blogspot.com ');
} "Rel =" lightbox "href =" http://2.bp.blogspot.com/_W6UcJjyXr24/Sh_JM6CRU5I/AAAAAAAAC28/oMAEGqUZpKA/s1600-h/eclim-demo.png "onblur =" function onblur ()
{
Try {parent. deselectbloggerimagegracefully ();} catch (e ){}
} ">

I have used a lot of VIM code to complete plug-ins, including language-specific and generic. It should be that eclim is the best I have ever used to support the Java language. Of course, as mentioned earlier, eclim also has good support for other languages. If you are interested, visit the official website.

Okay. Here is the code Editing Section. It should be said that there are too many functions of eclim, and you can find them in most eclipse. I will not continue to introduce it here. If you like this, you can check this {
Pagetracker. _ trackpageview ('A/eclim.sourceforge.net ');
} "Href =" http://eclim.sourceforge.net/vim/cheatsheet.html "target =" _ blank "> cheatsheet, common functions are basically complete.

So after editing the code, what should I do next? Test it on emulator. First, open the created AVD.

Emulator-AVN avd_name

Then compile and install. In the android SDK, you can use ant debug to compile the debug version program, install ADB install name.apk, or install it with ant install. Eclim is awesome because it has built-in support for ant! That is to say, you have written the code in Vim, and you don't need to launch it. You can simply use ant install to view the effect in the simulator. In addition, you can directly edit the build. xml corresponding to ant. eclim also provides the function of completing the code and checking the basic syntax!

How can I see the above introduction? Once again, eclim is really a powerful tool. We recommend that all people interested in it go to the official website to read the document on their own, so that you will find that, you no longer need eclipse. (Except debugging: P ).

Finally, eclim also supports separate configuration files. You can create ~ /. Eclimrc is of the same nature as. gvimrc.

Finally, I didn't introduce how to use eclim to edit the interface XML, because I used droiddraw to draw the interface. However, if you are used to text editing, the truth is the same.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.