Vim简介给使用Visual Studio Code的人

Hot tips to bring the awesomeness of Visual Studio Code to Vim.

将Visual Studio Code的精妙之处带给Vim的热门技巧。

前题 (Front-Matter)

I want to start by saying, this is not an editor-shame article. You can use whatever text editor you want. It really doesn’t matter. I’m only writing this because I found a level of productivity in Vim that I haven’t had in any of the editors I used before (Sublime Text, Atom or VSCode).

我首先要说的是,这不是一篇关于编辑的耻辱文章。 您可以使用所需的任何文本编辑器。 真的没关系。 我之所以写这篇文章是因为我发现Vim的生产力水平是我以前使用的任何编辑器(Sublime Text,Atom或VSCode)中都没有的。

If you’ve heard about Vim, and want to try it out, I hope this article can provide a bit of familiarity you’d find from VSCode.

如果您听说过Vim,并且想尝试一下,希望本文对VSCode有所帮助。

为什么选择Vim? (Why Vim?)

There are lots of reasons to use Vim, so here’s a few of mine.

有很多使用Vim的理由,所以这里有一些。

双手保持在10和2 (Keep your hands at 10 and 2)

When you are solely using the keyboard, there is going to be an inherent speed boost just from not having to physically move your hands. And hey, maybe you’re a black belt in mouse movement, and you can move back in forth with a speed invisible to the naked eye. For the rest of us simple humans, it takes time.

当您仅使用键盘时,由于不必物理移动手,这将带来固有的速度提升。 嘿,也许您是鼠标移动中的黑带,并且您可以以肉眼看不见的速度向前移动。 对于我们其余的简单人来说,这需要时间。

Let’s do some quick math.

让我们做一些快速数学运算。

It takes 600ms to move my hand from the “home keys” to the mouse. On average, for sake of argument, I do that once a minute while I’m writing code. Whether that be to scroll, navigate to a new file, or something similar.

将我的手从“主页键”移动到鼠标需要600毫秒。 平均而言,为了争辩,我在编写代码时每分钟执行一次。 无论是滚动,导航到新文件还是类似文件。

600 (wasted time in ms) x 60 (times per hour) x 5 (hours I am actually coding) = 180,000ms wasted =

600(以毫秒为单位的浪费时间)x 60(每小时的时间)x 5(我实际编码的小时数)= 180,000ms浪费=

3. Minutes. Every. Day.
3分钟。 每一个 天。

Yeah, okay, maybe that doesn’t sound so bad, but, those 3 minutes could be spent writing a function, or refactoring code, not flailing your hand about like you're Harry Potter!

是的,也许听起来还不错,但是那三分钟可能是花在编写函数或重构代码上 ,而不是像哈利·波特那样挥霍双手!

速度 (Speed)

My favorite quote that describes what it’s like to code in VIM:

我最喜欢的报价描述了在VIM中编写代码的感觉:

“Code at the speed of thought”
“以思想的速度编码”

Vim is built around the idea that you are directly communicating with your computer. You tell it what you want, and it does it for you. The biggest eye-opener for me was this little tidbit:

Vim是基于您与计算机直接通信的想法构建的。 您告诉它您想要什么,它就会为您完成。 对我来说最大的大开眼界是这个小窍门:

To delete everything in between two objects (parentheses, quotes, etc), it's as simple as:

要删除两个对象(括号,引号等)之间的所有内容,方法很简单:

di'

di'

That’s just the surface of amazing shorthand things you can do with Vim.

这只是您可以使用Vim进行的惊人速记功能的表面。

我是一个真正的程序员! (I’m a real programmer!)

Part of the journey of learning VIM is exposing yourself to how UNIX works. I’m under the impression that the more you expose yourself to things like bash, the better programmer you are going to be.

学习VIM的一部分旅程就是让自己了解UNIX的工作原理。 我的印象是,您接触bash之类的东西越多,您将成为更好的程序员

Chances are, you have a pretty sweet command line setup. Wouldn’t it be nice if your code editor and your command line worked in concert?

您可能有一个非常漂亮的命令行设置。 如果您的代码编辑器和命令行协同工作,会不会很好?

您如何退出Vim? (How do you exit Vim?)

Probability is high that you’ve ever edited a file on a Linux server, and couldn’t figure out how to exit the file. Let’s say, for example, changing an SSH key on Digital Ocean. If you know VIM…you don’t have to worry about that!

您曾经在Linux服务器上编辑过文件,却想不出如何退出文件的可能性很高。 比方说,例如,在Digital Ocean上更改SSH密钥。 如果您了解VIM,则不必担心!

我改用Vim的真正原因 (The real reason I switched to Vim)

Honesty time. The real catalyst for wanting to switch to Vim was watching Kyle Mathews (creator of Gatsby.js) using it during a demo.

诚实的时间。 想要切换到Vim的真正催化剂是在演示过程中观看了使用它的Kyle Mathews(Gatsby.js的创建者)。

VS代码功能及其等效功能 (VS Code Features and their equivalents)

Convinced? Cool, here’s some tools!

说服了吗 太酷了,这里有一些工具!

插件系统 (Plugin System)

Vim by itself is pretty barebones. In order to add plugins, we have to have a mechanism to manage them. Enter Plug:

Vim本身就是一个准系统。 为了添加插件,我们必须有一种管理它们的机制。 输入插头:

junegunn/vim-plug

junegunn / vim-plug

Note: There are a few plugin managers out there. I landed on Plug for no particular reason. I like it, and I’ve had no issues with it. FYI, Vundle is deprecated.
注意:那里有一些插件管理器。 我没有特殊原因就落在了Plug上。 我喜欢它,但没有任何问题。 仅供参考,Vundle已弃用。

There has been a bunch of solutions for file searching over the years, as indicated by the multitude of answers in forums. I tried a couple of different ones, but landed on this combination:

多年来,有许多文件搜索解决方案,如论坛中的大量答案所示。 我尝试了几种不同的方法,但是采用了这种组合:

Fuzzy Finder(fzf) + Ripgrep

模糊查找器(fzf) + Ripgre p

Fzf is a really well built/maintained fuzzy search that works in both the command line and vim.

Fzf是一个构建良好/维护良好的模糊搜索,可同时在命令行和vim中使用。

Note: You may see Ag(Silver searcher) in a lot of articles, however the Ag related vim plugin is no longer maintained, so it's suggested to use RipGrep.
注意:您可能会在很多文章中看到Ag(Silver searcher),但是不再维护与Ag相关的vim插件,因此建议使用RipGrep。
智能感知 (Intellisense)

The auto-completion system (Intellisense) in VSCode is arguably its best feature. Lucky for us, it’s been ported over to Vim!

VSCode中的自动完成系统(Intellisense)可以说是其最佳功能。 对我们来说幸运的是,它已被移植到Vim!

neoclide/coc.nvim

neoclide / coc.nvim

CoC has its own extension system, that mirrors that of VSCodes. It's easy to use and well-documented (the most important part).

CoC拥有自己的扩展系统,该系统与VSCodes的系统相同。 它易于使用且有据可查(最重要的部分)。

Note: You may see some old articles talking about YouCompleteMe, but as far as I can tell, that isn’t maintained anymore.
注意:您可能会看到一些有关YouCompleteMe的老文章,但是据我所知,已经不再维护了。
文件系统资源管理器 (File System Explorer)

VSCode, like most modern text editors, comes with a file explorer. Vim’s native netrw is alright, and I’ve seen quite a few articles saying you don’t need anything else, like here. However, I find NERDTree is too useful to not use.

像大多数现代文本编辑器一样,VSCode带有文件浏览器。 Vim的本地netrw很好,我已经看了很多文章说您不需要其他东西,例如这里 。 但是,我发现NERDTree太有用了,无法使用。

scrooloose/nerdtree

阴囊/书呆子

Git集成 (Git integration)

I gotta be honest here, I do most of my git stuff straight in Iterm. However, VSCode has an incredibly nice Git Diff split screen. To get that level of git integration, check out this plugin:

我要老实说,我在Iterm中直接做大多数git的事情。 但是,VSCode的Git Diff分屏非常好。 要获得该级别的git集成,请查看以下插件:

tpope/vim-fugitive

tpope / vim逃犯

您可能需要的其他插件 (Additional plugins that you may want)

This is some of the stuff I used in Visual Studio Code, that I wanted to bring into Vim.

这是我想带入Vim的Visual Studio Code中使用的一些东西。

自动完成括号 (Autocomplete Brackets)

This nice little package will auto close those pesky brackets.

这个不错的小包装将自动关闭那些讨厌的括号。

jiangmiao/auto-pairs

江庙/汽车对

文件图标 (File Icons)

This will add icons to stuff like NERDTree.

这会将图标添加到NERDTree之类的东西。

ryanoasis/vim-devicons

ryanoasis / vim-devicons

更漂亮 (Prettier)

Wouldn’t you know it, but the official prettier team has a vim plugin. How nice! Also, incredibly simple to set up.

您不知道吗,但是官方的漂亮团队有一个vim插件。 多好! 而且,设置非常简单。

prettier/vim-prettier

更漂亮/ vim更漂亮

Get it to work on autosave, check out this article.

使它可以自动保存,请查阅本文

片段 (Snippets)

Wouldn’t you know it, using the Conquer of Completion, you can import VSCode snippets!

您不知道吗,使用“完成征服”就可以导入VSCode片段!

Check this out to show you how to do that:

检查一下,向您展示如何做到这一点:

neoclide/coc.nvim

neoclide / coc.nvim

Here is the React snippets package I’m using.

这是我正在使用的React代码段包。

xabikos/vscode-react

xabikos / vscode-react

额外的东西 (Additional Stuff)

THE home for Vim plugins is Vim Awesome.

Vim插件的存放地是Vim Awesome。

Vim Awesome

Vim很棒

Great place to watch people use Vim:

观看人们使用Vim的好地方:

Vimcasts - Free screencasts about the text editor Vim

Vimcasts-关于文本编辑器Vim的免费屏幕录像

点文件 (Dotfiles)

I have a few remapped keys to make things easier. Check out my dotfiles for all those.

我有一些重新映射的键可以使事情变得简单。 查看我所有的dotfile。

DarthOstrich/dotfiles

DarthOstrich / dotfiles

最后的想法 (Final Thoughts)

我的旅途 (My Journey)

I solely use Vim now, after spending about a year to learn it. Initially, I was using it just for my personal projects, because my productivity level was low. I had to keep stopping to look up how to do something. However, I dropped VSCode completely about 4 months ago, and I don’t plan on going back.

经过大约一年的学习,我现在仅使用Vim。 最初,我只是将其用于个人项目,因为我的生产力水平很低。 我不得不停下来寻找如何做某事。 但是,大约4个月前,我完全放弃了VSCode,并且我不打算回头。

需要纪律 (It takes discipline)

Learning Vim can seem daunting, and frankly, it is. It requires self-imposed discipline. However, doesn’t everything in development? There is no tool/language/framework I’ve ever learned that didn’t require some level of deliberate practice.

学习Vim似乎令人生畏,坦率地说,确实如此。 它要求自我约束。 但是,不是所有内容都在开发中吗? 我所学过的工具/语言/框架并不需要一定程度的深思熟虑

Vim is a lifestyle choice. It will take a while to get used to it, and it WILL be frustrating at times. However, if you stick to it, I guarantee it’ll improve your workflow. If you have any additional tips or questions, please drop them below. As always, happy coding!

Vim是一种生活方式的选择。 要花一些时间才能习惯它,有时它会令人沮丧。 但是,如果您坚持下去,我保证它将改善您的工作流程。 如果您还有其他提示或问题,请将其放在下面。 一如既往,编码愉快!

其他学习资源 (Additional Resources for learning)

Mastering Vim Quickly — Jovica Ilic

快速掌握Vim — Jovica Ilic

8 Vim Tricks That Will Take You From Beginner to Expert

8种Vim技巧,将带您从初学者到专家

参考文献 (References)

Switching to Vim

切换到Vim

10 simple Linux tips which save 50% of my time in the command line

10个简单的Linux技巧,可在命令行中节省50%的时间

翻译自: https://www.freecodecamp.org/news/vim-for-people-who-use-visual-studio-code/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Visual Studio Code (VSCode) 是一个轻量级且功能强大的代码编辑器,支持多种编程语言,包括Java。要安装Java并在VSCode使用它,你可以按照以下步骤操作: 1. **下载和安装Java**: - 访问Oracle的官方网站 <https://www.oracle.com/java/technologies/javase-jdk-downloads.html> ,下载适合你操作系统的Java Development Kit (JDK)。 - 安装JDK,确保在安装过程中选择将JDK添加到系统环境变量。 2. **验证Java安装**: - 打开终端或命令提示符(Windows),输入 `java -version` 或 `javac -version`,如果安装成功,会显示Java版本信息。 3. **安装Java开发插件**: - 在VSCode中打开设置(`Ctrl + ,` 或 `Cmd + ,`)。 - 在搜索框中输入 "Java",找到并安装 "Java Extension Pack" 或官方推荐的 "Pivotal.vscode-java" 插件。这将提供对Java语言的完整支持,包括代码补全、调试等。 4. **配置Java设置**: - 右键点击VSCode的左侧面板,选择 "首选项" -> "设置"。 - 输入 `.vscode/settings.json` 或在搜索框里搜寻 "java",然后添加以下内容: ```json { "java.home": "<你的JDK安装路径>/jdk版本号", "java.path": [ "<你的JDK安装路径>/bin" ] } ``` - 将 `<你的JDK安装路径>` 替换为实际的JDK安装位置,`jdk版本号` 例如 `1.8` 或 `17`。 5. **启动Java项目**: - 创建一个新的Java项目,可以在VSCode内创建,或者从本地导入项目。 - 使用VSCode的构建工具(如Maven或Gradle),或者直接通过终端运行Java程序。 相关问题: 1. Java Extension Pack提供了哪些功能? 2. 如何在VSCode中调试Java代码? 3. 如果遇到VSCode找不到Java SDK的问题,应该检查哪些设置?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值