javaee2020-教程直播-17eclipse个性化设置的建议

1 设置自己的eclipse编码自动补全

自动补全用起来更“自动”。
好不好用取决于自己的习惯。
在主菜单的:Window -> Preferences -> Java/Editor/Content Assist
把"Autocomplete Trigger for Java"配置为:

.(@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

(默认值是一个“.”)并且把Auto activation delay降低(例如说降低到0或者100ms)。

  • 打点提示,面向对象的需要
  • 左括号提示,写入参时需要
  • @提示,写注解时需要

2 习惯去用eclipse的各种快捷操作

写多代码,自然学会。

  • Ctrl+1 快速修复(最经典的快捷键,就不用多说了)

  • Ctrl+D: 删除当前行

  • Ctrl+Alt+↓ 复制当前行到下一行(复制增加)

  • Ctrl+Alt+↑ 复制当前行到上一行(复制增加)

  • Alt+↓ 当前行和下面一行交互位置(特别实用,可以省去先剪切,再粘贴了)

  • Alt+↑ 当前行和上面一行交互位置(同上)

  • Alt+← 前一个编辑的页面

  • Alt+→ 下一个编辑的页面(当然是针对上面那条来说了)

  • Alt+Enter 显示当前选择资源(工程,or 文件 or文件)的属性

  • Shift+Enter 在当前行的下一行插入空行(这时鼠标可以在当前行的任一位置,不一定是最后)

  • Shift+Ctrl+Enter 在当前行插入空行(原理同上条)

  • Ctrl+Q 定位到最后编辑的地方

  • Ctrl+L 定位在某行 (对于程序超过100的人就有福音了)

  • Ctrl+M 最大化当前的Edit或View (再按则反之)

  • Ctrl+/ 注释当前行,再按则取消注释

  • Ctrl+O 快速显示 OutLine

  • Ctrl+T 快速显示当前类的继承结构

  • Ctrl+W 关闭当前Editer

  • Ctrl+K 参照选中的Word快速定位到下一个

  • Ctrl+E 快速显示当前Editer的下拉列表(如果当前页面没有显示的用黑体表示)

  • Ctrl+/(小键盘) 折叠当前类中的所有代码

  • Ctrl+×(小键盘) 展开当前类中的所有代码

  • Ctrl+Space 代码助手完成一些代码的插入(但一般和输入法有冲突,可以修改输入法的热键,也可以暂用Alt+/来代替)

  • Ctrl+Shift+E 显示管理当前打开的所有的View的管理器(可以选择关闭,激活等操作)

  • Ctrl+J 正向增量查找(按下Ctrl+J后,你所输入的每个字母编辑器都提供快速匹配定位到某个单词,如果没有,则在stutes line中显示没有找到了,查一个单词时,特别实用,这个功能Idea两年前就有了)

  • Ctrl+Shift+J 反向增量查找(和上条相同,只不过是从后往前查)

  • Ctrl+Shift+F4 关闭所有打开的Editer

  • Ctrl+Shift+X 把当前选中的文本全部变味小写

  • Ctrl+Shift+Y 把当前选中的文本全部变为小写

  • Ctrl+Shift+F 格式化当前代码

  • Ctrl+Shift+P 定位到对于的匹配符(譬如{}) (从前面定位后面时,光标要在匹配符里面,后面到前面,则反之)下面的快捷键是重构里面常用的,本人就自己喜欢且常用的整理一下(注:一般重构的快捷键都是Alt+Shift开头的了)

  • Alt+Shift+R 重命名 (是我自己最爱用的一个了,尤其是变量和类的Rename,比手工方法能节省很多劳动力)

  • Alt+Shift+M 抽取方法 (这是重构里面最常用的方法之一了,尤其是对一大堆泥团代码有用)

  • Alt+Shift+C 修改函数结构(比较实用,有N个函数调用了这个方法,修改一次搞定)

  • Alt+Shift+L 抽取本地变量( 可以直接把一些魔法数字和字符串抽取成一个变量,尤其是多处调用的时候)

  • Alt+Shift+F 把Class中的local变量变为field变量 (比较实用的功能)

  • Alt+Shift+I 合并变量(可能这样说有点不妥Inline)

  • Alt+Shift+V 移动函数和变量(不怎么常用)

  • Alt+Shift+Z 重构的后悔药(Undo)

编辑作用域 功能 快捷键

  • 全局 查找并替换 Ctrl+F
  • 文本编辑器 查找上一个 Ctrl+Shift+K
  • 文本编辑器 查找下一个 Ctrl+K
  • 全局 撤销 Ctrl+Z
  • 全局 复制 Ctrl+C
  • 全局 恢复上一个选择 Alt+Shift+↓
  • 全局 剪切 Ctrl+X
  • 全局 快速修正 Ctrl1+1
  • 全局 内容辅助 Alt+/
  • 全局 全部选中 Ctrl+A
  • 全局 删除 Delete
  • 全局 上下文信息 Alt+?
  • Alt+Shift+?
  • Ctrl+Shift+Space
  • Java编辑器 显示工具提示描述 F2
  • Java编辑器 选择封装元素 Alt+Shift+↑
  • Java编辑器 选择上一个元素 Alt+Shift+←
  • Java编辑器 选择下一个元素 Alt+Shift+→
  • 文本编辑器 增量查找 Ctrl+J
  • 文本编辑器 增量逆向查找 Ctrl+Shift+J
  • 全局 粘贴 Ctrl+V 全局
  • 重做 Ctrl+Y

查看

作用域 功能 快捷键
全局 放大 Ctrl+=
全局 缩小 Ctrl±

窗口

作用域 功能 快捷键
全局 激活编辑器 F12
全局 切换编辑器 Ctrl+Shift+W
全局 上一个编辑器 Ctrl+Shift+F6
全局 上一个视图 Ctrl+Shift+F7
全局 上一个透视图 Ctrl+Shift+F8
全局 下一个编辑器 Ctrl+F6
全局 下一个视图 Ctrl+F7
全局 下一个透视图 Ctrl+F8
文本编辑器 显示标尺上下文菜单 Ctrl+W
全局 显示视图菜单 Ctrl+F10
全局 显示系统菜单 Alt±

说几个常用的:

1,把光标放在方法名或变量名上,按ctrl+alt+h ,会把所有使用了该方法或变量的地方找出来。
2,ctrl+q 跳到最后一次编辑的位置
3,crtl+t 打开接口的实现类
4,Ctrl+Shift+F 格式化自己的代码,会去除多余空格换行和连接号+等左右漏掉的空格等。 最好把宽度设置到120,默认80,120不窄不宽,看代码很舒服。
5,Ctrl+O 快速查看代码的大纲。 这样下来即使一个类中有好多方法也不害怕了。

3 Eclipse提速优化方法

3.1关闭不常用的工程

打开的项目太多,会严重影响Eclipse的启动,将其关闭或者直接从工程视图中删除不是物理删除.即可。

3.2取消启动时自动加载的插件

选择Preferrnces -> General -> Startup and Shutdown,将Plug-ins activited on startup的插件全部取消,保存即可。

3.3maven的设置

选择Preferrnces -> Maven,将Download respository index updates on startup 选项取消,保存即可。

3.4取消validation

选择Preferrnces -> validation,选择Disable All,保存即可。

3.5修改eclipse.ini参数

可以参考如下文章进行设置:
优化JVM参数提高eclipse运行速度

设置启动VM,省去启动时查找的时间,使用最新的jdk来运行eclipse
-vm
D:/Program Files/Java/jdk1.8.0_91/jre/bin

3.6.取消spell checking

选择Preferrnces -> General -> Editors -> Text Editors -> spelling,取消Enable spell checking选项,保存即可。

3.7取消自动更新

Install/Update > Automatic Updates > 取消勾选“Automatically find new updates and notify me”。

3.8禁用动画,使用classic主题,或者不使用主题

Window -> Preferences -> General -> Appearance -> Uncheck ‘Enable animations’

Window > Customize Perspective > 移除所有用不到或不想用的内容尽量使用快捷键.,菜单栏也是如此你用过几次菜单栏的打印按钮

3.9不要在Eclipse中运行SVN和GIT

3.10使用JVM性能监视工具

首先启动JDK自带的JVM性能监视工具,在java\bin的目录下,有一个jvisualvm,它是绑定在JDK中的visualvm.双击启动 visualvm. 然后启动eclipse, 在eclipse启动完成以后,使用visualvm的查看eclipse的Visual GC情况:
-server是让JVM以server模式运行,加重JIT的优化作用,由于eclipse是经常开着不关,在server模式下,JIT会随着运行的时间,把字节码更深刻的变成成机器代码.加快运行速度.
-Xverify:none, 跳过对字节码的验证。

4 eclipse初次安装一些设置

  1. 修改字体大小 fonts -》 basic -》 text -》 14号
  2. 修改jdk java -》 installed jre -》 删除现有的jre -》 加入jdk1.8(注意是jdk)
  3. 修改编码 gernal -》 workspace -》 utf-8
  4. 修改提示 java -》 editor -》 content assistent -》.(@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
  5. 加入tomcat server -》 runtime eviroment -》 tomcat
  6. 修改maven配置,特别是它的settings.xml文件
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.conf}/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->

  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
	<mirror>
		<id>alimaven</id>
		<mirrorOf>central</mirrorOf>
		<name>aliyun maven</name>
		<url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
	<mirror> 
		<id>CN</id> 
		<name>OSChina Central</name> 
		<url>http://maven.oschina.net/content/groups/public/</url> 
		<mirrorOf>central</mirrorOf> 
	</mirror>
	<mirror>
		<id>repo2</id>
		<name>Mirror from Maven Repo2</name>
		<url>http://repo2.maven.org/maven2/</url>
		<mirrorOf>central</mirrorOf>
	</mirror>	
  </mirrors>

  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |
   |-->
  <profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <profile>
      <id>jdk-1.4</id>

      <activation>
        <jdk>1.4</jdk>
      </activation>

      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    -->

    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
      <id>env-dev</id>

      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>

      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
  </profiles>

  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>

  1. validation -> validation -> disable all确定

5 学生们常踩的坑

你找不到某个窗口时,就这么干,总比重装强多了。

  1. Window -> Reset Perspective(有时候不一定行)
  2. File -> Switch workspace ->Other(然后删除原来的工作空间目录,再重启eclipse)
  3. 删除eclipse工作空间下的.metadata目录,重启eclipse(这个文件记录着你所有关于eclipse的配置)(推荐★★★)
  4. Window->Close Perspective
  5. File->Restart

6 eclipse恢复初始设置的方法(无敌重启大法)

删除eclipse工作空间下的.metadata目录,重启eclipse(这个文件记录着你所有关于eclipse的配置)
专治各种杂症

7 专治eclipse下的中文乱码

对于这个eclipse,据我现在所知(以后可能会更新),一共有四个地方可以更改编码格式。我们先给这四个地方取一个土一些的名字,方便我后面文章的介绍。
1、整个项目空间的编码格式的设置
(window->Proferences->在搜索框输入"enc"->选择Workpalce)
在这里插入图片描述
2.单个项目的编码格式设置
(右击那个项目,选择Porperties->Resource)
在这里插入图片描述
3.所有文件的编码格式设置(你可以理解为,我设置了这里的编码格式后,比如你设为GBK,那么那些你选择的所有的文件的编码格式会全为GBK),咱们就对所有的java文件设置编码格式就好,你也可以对别的类型文件,自己选择。
(window->preference->在搜索框输入“con”->选择右边的"Text->"选择Conten Types->JavaResource)
在这里插入图片描述
在这里插入图片描述
4.对单个文件进行编码的设置
(打开那个文件->按住“Alt+回车”->Resource)
在这里插入图片描述

修改单个项目的编码格式,或者修改工作空间的编码格式是无法作用到项目里面的java文件的编码格式。

简单就是一句话,你看到你打开的文件是乱码的,别慌,Alt+回车,修改一下编码格式,准行的。

7.1乱码示例

问题:拷贝了一部分源码到自己的工程,打开后发现中文乱码,在Eclipse中无论是把属性设置为GBK还是utf-8,其中的中文都还是乱码
改成GBK后中文乱码:锟斤拷锟矫筹拷锟斤拷锟斤拷斐
产生:自己的工程默认编码是UTF-8,拷贝过来的源代码编码是GBK的。
解决:先将自己的工程编码改成GBK,再将要拷贝的文件拷贝到工程中,之后在Eclipse中设置编码为GBK就不会产生乱码了。

7.2eclipse中文乱码修改新方法,在修改了所有的utf-8都没有用就这样修改

方法背景:想看别人的JAVA项目,导入eclipse后出现中文乱码,在设置了所有的工作空间都为UTF-8以后都没有用,并且项目Resource选项没有GBK选项,或统一选择GBK后会使其他项目出现中文乱码,可以用此方法。
方法原理:逐个修改导入项目的编码文件:org.eclipse.core.resources.prefs 文件

问题:统一修改整个工作空间的编码为GBK又会导致原有项目中文乱码,而且一般不建议修改为GBK,UTF8是国际编码,它的通用性比较好

解决步骤:
第一步:切换为Navigator导航器,打开org.eclipse.core.resources.prefs文件,或者在项目根目录文件夹用记事本打开
在这里插入图片描述
第二步:修改src文件编码并保存
在这里插入图片描述
我这里统一修改为GBK就正常了,自己可以根据需求单独或全部修改
在这里插入图片描述
中文恢复正常显示
在这里插入图片描述

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值