键入代码时如何最小化箭头键的使用?

时间:2021-10-24 03:40:06

When typing code, I would normally close brackets, go back inside, go outside, type semicolon, etc:

键入代码时,我通常会关闭括号,返回内部,外出,键入分号等:

I might start with (| is the caret):

我可以从(|是插入符号)开始:

System.out.println()|

Then go left:

然后左转:

System.out.println(|)

Then this:

System.out.println(foo()|)

Again backtracking a space:

再次回溯空间:

System.out.println(foo(|))

Typing quotes are similar:

输入引号类似:

System.out.println(foo(""|))

...etc.

My right hand is constantly moving between the home row and the arrow keys. I've tried vim and although I know the basics, it still feels very awkward to me.

我的右手在主行和箭头键之间不断移动。我尝试过vim,虽然我知道基础知识,但对我来说仍然感觉很尴尬。

How should I do this? Should I just type from left to right (opening bracket, then contents, then closing brackets, then semicolon)?

我该怎么做?我应该从左到右键入(打开括号,然后是内容,然后关闭括号,然后是分号)?

Thanks.

11 个解决方案

#1


First and foremost, there is much speed to be gained in Vim by using h, j, k and l instead of the arrow keys. See Learning Vim the Pragmatic Way for a overview of the keys.

首先,通过使用h,j,k和l而不是箭头键,可以在Vim中获得很快的速度。有关键的概述,请参阅学习Vim的实用方法。

However, what you probably want in this case is the AutoClose plugin. It automatically inserts the closing parenthesis (or quote) along with the opening, and places the caret between them. Thus you go from

但是,在这种情况下您可能需要的是AutoClose插件。它会自动插入右括号(或引号)和开口,并将插入符号放在它们之间。因此,你去

System.out.println(|)

to

System.out.println(foo(|))

to

System.out.println(foo("|"))

If you then type ")), the caret will "move over" the closing characters instead of inserting new ones. Although, a faster way to get to the end of line is probably <Esc>A.

如果你输入“)),插入符将”移动“结束字符而不是插入新字符。虽然,更快到达行尾的方法可能是 A.

System.out.println(foo(""));

So, to sum up, the above can be produced by typing System.out.println(foo("<Esc>A;.

因此,总而言之,可以通过键入System.out.println(foo(“ A;。

For editing paired characters, as opposed to inserting them, see surround.vim.

要编辑成对字符,而不是插入它们,请参阅surround.vim。

#2


Well, that's Java, If you use a more or less good IDE you should be able to autocomplete, that way when you type "System.out.println" and hit enter to accept autocomplete, the brackets will show up and the caret will be in the middle (oh, and there will be the quotes too!)

好吧,那就是Java,如果你使用一个或多或少好的IDE,你应该能够自动完成,当你输入“System.out.println”并按Enter键接受自动完成时,括号将显示,插入符号将是在中间(哦,也会有引号!)

#3


If you're already in vim, try playing around with the h,j,k, and l keys. They do the same thing as the arrow keys but are much more convenient. Trying to get in the habit of typing in order would probably also help, but that's something that takes some effort.

如果您已经在vim中,请尝试使用h,j,k和l键。它们与箭头键做同样的事情,但更方便。试图养成按顺序打字的习惯可能也会有所帮助,但这需要付出一些努力。

#4


You can save keystrokes by holding the Ctrl key and using the arrow keys. Instead of moving one character, it moves one word at a time. This also works when backspacing. So Ctrl-Backspace will delete the entire word instead of just the last character.

您可以通过按住Ctrl键并使用箭头键来保存击键。它不是移动一个字符,而是一次移动一个字。这也适用于退格时。因此,Ctrl-Backspace将删除整个单词而不是最后一个单词。

#5


Don't.

Your habit of ending something that you started - whether it be the closing parenthesis, bracket, brace, or the .Close() call to match .Open(), or delete/free call to match your new/malloc - is an excellent one. Even if you intend to "close" your object in a different scope (like a terminate function), your habit forces you to think about properly releasing resources.

你习惯于结束你开始的东西 - 无论是关闭括号,括号,大括号还是.Close()调用匹配.Open(),或删除/免费调用以匹配你的新/ malloc - 是一个很好的一个。即使您打算在不同的范围内“关闭”您的对象(如终止函数),您的习惯也会迫使您考虑正确释放资源。

Yes, there are helpful editors out that allow you to code faster, which you should definitely use, but don't let them become a crutch that allow you to forget to close objects/release resources.

是的,有一些有用的编辑器允许你更快地编写代码,你应该使用它,但不要让它们成为一个让你忘记关闭对象/释放资源的拐杖。

The direct answer to your question: Most good programmer editors can be customized/configured, so you'll just have to do some reading about advanced configuration of the editor of your choice - vim, emacs, the Visual Studio editor.

直接回答你的问题:大多数优秀的程序员编辑器都可以自定义/配置,所以你只需要阅读一些关于你选择的编辑器的高级配置--vim,emacs,Visual Studio编辑器。

#6


Try AutoHotKey and my script:

试试AutoHotKey和我的脚本:

*!I::SendInput, % (GetKeyState("Shift", "P") ? "+" : "") (GetKeyState("Ctrl", "P") ? "^" : "") "{Up}"
*!K::SendInput, % (GetKeyState("Shift", "P") ? "+" : "") (GetKeyState("Ctrl", "P") ? "^" : "") "{Down}"
*!J::SendInput, % (GetKeyState("Shift", "P") ? "+" : "") (GetKeyState("Ctrl", "P") ? "^" : "") "{Left}"
*!L::SendInput, % (GetKeyState("Shift", "P") ? "+" : "") (GetKeyState("Ctrl", "P") ? "^" : "") "{Right}"
*!U::SendInput, % (GetKeyState("Shift", "P") ? "+" : "") (GetKeyState("Ctrl", "P") ? "^" : "") "{Home}"
*!O::SendInput, % (GetKeyState("Shift", "P") ? "+" : "") (GetKeyState("Ctrl", "P") ? "^" : "") "{End}"
*!h::SendInput, % (GetKeyState("Shift", "P") ? "+" : "") (GetKeyState("Ctrl", "P") ? "^" : "") "{Del}"

LAlt & Shift:: ('optional line')

LAlt&Shift ::('可选线')

It's about holding LAlt + pressing something from: i, k,j, l (arrow keys), u, o (home, end) or h (delete). Last line is optional if you don't want to change keyboard lang. layout by LAlt +Shift

这是关于持有LAlt +按下的东西:i,k,j,l(箭头键),u,o(主页,结束)或h(删除)。如果您不想更改键盘朗,则最后一行是可选的。由LAlt + Shift布局

You can use it even in combination with modificators like shift and ctrl.

即使与shift和ctrl等修饰符结合使用,您也可以使用它。

enjoy ;)

#7


I would totally recommend vim... as it will help a lot of this! Also, look into something that will auto-close your parenthesis, square brackets, and curly brackets for you... I have something in vim that does this and it helps with this type of problem because I'm already inside the parenthesis.

我完全会推荐vim ...因为它会帮助很多这个!另外,看看会自动关闭括号,方括号和大括号的东西......我在vim中有一些东西可以做到这一点,它有助于解决这类问题,因为我已经在括号内了。

#8


Another vote for Vim. Also, there are some great plugins for more standard IDEs that use Vi keybindings. I use jVI in Netbeans from time to time.

对Vim的另一次投票。此外,还有一些很棒的插件可供使用Vi键绑定的更多标准IDE。我不时在Netbeans中使用jVI。

You'll find that the more you use Vim, the easier it is on your wrists. You'll also find that a sufficiently clever find/replace can save you quite a few keystrokes, as can a global action regex-y thing.

你会发现你使用Vim的次数越多,你的手腕就越容易。您还会发现,一个足够聪明的查找/替换可以为您节省大量的键击,就像全局动作正则表达式一样。

Bind :tabn and :tabp to something accessible like and and force yourself to get stuff done without giving up and using a proper GUI editor.

绑定:tabn和:tabp到可访问的东西,并强制自己完成工作而不放弃和使用正确的GUI编辑器。

#9


I used to type completely linearly (yes, in vim), never could get the hang of the dashing back and forth that writing closing elements immediately created.

我曾经完全线性地键入(是的,在vim中),永远不会得到立即创建的写入关闭元素的来回潇洒。

However, I now use Eclipse - it creates them for me as I go, so at the end of something with a )")) mess I just hit end and type a ;, no need to deal with it manually at all. Which sometimes confuses me, but that's ok.

但是,我现在使用Eclipse - 它在我创建时为我创建它们,所以在a)的某些结尾处“))混乱我只是点击结束并键入a;,根本不需要手动处理它。困惑我,但没关系。

#10


I find the number pad makes navigation very easy because the home and pgup keys are so close. For actually typing numbers you just use the top row of the keyboard (which is difficult to learn I agree but sufficiently fast after a while).

我发现数字键盘使导航非常容易,因为home和pgup键非常接近。对于实际输入数字,你只需使用键盘的顶行(这很难学习我同意但一段时间后足够快)。

The only downsides of this for me are using laptop keyboards and using other people's machines where I have to turn off num lock every time.

这对我来说唯一的缺点是使用笔记本电脑键盘和使用其他人的机器,我必须每次都关闭num lock。

#11


A good IDE (galileo is almost here) will auto close brackets, parentheses, etc, and will intelligently insert a semicolon at the end of the statement too. No need to use arrows at all!

一个好的IDE(伽利略几乎就在这里)会自动关闭括号,括号等,并且会在语句的末尾智能地插入分号。根本不需要使用箭头!

Of course for a println in Eclipse you can just type sysout but that's probably a bad habit to get into.

当然对于Eclipse中的println,您只需输入sysout即可,但这可能是一个不好的习惯。

But be careful! If you get too quick your colleagues will always make you drive :P

不过要小心!如果你太快,你的同事总会让你开车:P

#1


First and foremost, there is much speed to be gained in Vim by using h, j, k and l instead of the arrow keys. See Learning Vim the Pragmatic Way for a overview of the keys.

首先,通过使用h,j,k和l而不是箭头键,可以在Vim中获得很快的速度。有关键的概述,请参阅学习Vim的实用方法。

However, what you probably want in this case is the AutoClose plugin. It automatically inserts the closing parenthesis (or quote) along with the opening, and places the caret between them. Thus you go from

但是,在这种情况下您可能需要的是AutoClose插件。它会自动插入右括号(或引号)和开口,并将插入符号放在它们之间。因此,你去

System.out.println(|)

to

System.out.println(foo(|))

to

System.out.println(foo("|"))

If you then type ")), the caret will "move over" the closing characters instead of inserting new ones. Although, a faster way to get to the end of line is probably <Esc>A.

如果你输入“)),插入符将”移动“结束字符而不是插入新字符。虽然,更快到达行尾的方法可能是 A.

System.out.println(foo(""));

So, to sum up, the above can be produced by typing System.out.println(foo("<Esc>A;.

因此,总而言之,可以通过键入System.out.println(foo(“ A;。

For editing paired characters, as opposed to inserting them, see surround.vim.

要编辑成对字符,而不是插入它们,请参阅surround.vim。

#2


Well, that's Java, If you use a more or less good IDE you should be able to autocomplete, that way when you type "System.out.println" and hit enter to accept autocomplete, the brackets will show up and the caret will be in the middle (oh, and there will be the quotes too!)

好吧,那就是Java,如果你使用一个或多或少好的IDE,你应该能够自动完成,当你输入“System.out.println”并按Enter键接受自动完成时,括号将显示,插入符号将是在中间(哦,也会有引号!)

#3


If you're already in vim, try playing around with the h,j,k, and l keys. They do the same thing as the arrow keys but are much more convenient. Trying to get in the habit of typing in order would probably also help, but that's something that takes some effort.

如果您已经在vim中,请尝试使用h,j,k和l键。它们与箭头键做同样的事情,但更方便。试图养成按顺序打字的习惯可能也会有所帮助,但这需要付出一些努力。

#4


You can save keystrokes by holding the Ctrl key and using the arrow keys. Instead of moving one character, it moves one word at a time. This also works when backspacing. So Ctrl-Backspace will delete the entire word instead of just the last character.

您可以通过按住Ctrl键并使用箭头键来保存击键。它不是移动一个字符,而是一次移动一个字。这也适用于退格时。因此,Ctrl-Backspace将删除整个单词而不是最后一个单词。

#5


Don't.

Your habit of ending something that you started - whether it be the closing parenthesis, bracket, brace, or the .Close() call to match .Open(), or delete/free call to match your new/malloc - is an excellent one. Even if you intend to "close" your object in a different scope (like a terminate function), your habit forces you to think about properly releasing resources.

你习惯于结束你开始的东西 - 无论是关闭括号,括号,大括号还是.Close()调用匹配.Open(),或删除/免费调用以匹配你的新/ malloc - 是一个很好的一个。即使您打算在不同的范围内“关闭”您的对象(如终止函数),您的习惯也会迫使您考虑正确释放资源。

Yes, there are helpful editors out that allow you to code faster, which you should definitely use, but don't let them become a crutch that allow you to forget to close objects/release resources.

是的,有一些有用的编辑器允许你更快地编写代码,你应该使用它,但不要让它们成为一个让你忘记关闭对象/释放资源的拐杖。

The direct answer to your question: Most good programmer editors can be customized/configured, so you'll just have to do some reading about advanced configuration of the editor of your choice - vim, emacs, the Visual Studio editor.

直接回答你的问题:大多数优秀的程序员编辑器都可以自定义/配置,所以你只需要阅读一些关于你选择的编辑器的高级配置--vim,emacs,Visual Studio编辑器。

#6


Try AutoHotKey and my script:

试试AutoHotKey和我的脚本:

*!I::SendInput, % (GetKeyState("Shift", "P") ? "+" : "") (GetKeyState("Ctrl", "P") ? "^" : "") "{Up}"
*!K::SendInput, % (GetKeyState("Shift", "P") ? "+" : "") (GetKeyState("Ctrl", "P") ? "^" : "") "{Down}"
*!J::SendInput, % (GetKeyState("Shift", "P") ? "+" : "") (GetKeyState("Ctrl", "P") ? "^" : "") "{Left}"
*!L::SendInput, % (GetKeyState("Shift", "P") ? "+" : "") (GetKeyState("Ctrl", "P") ? "^" : "") "{Right}"
*!U::SendInput, % (GetKeyState("Shift", "P") ? "+" : "") (GetKeyState("Ctrl", "P") ? "^" : "") "{Home}"
*!O::SendInput, % (GetKeyState("Shift", "P") ? "+" : "") (GetKeyState("Ctrl", "P") ? "^" : "") "{End}"
*!h::SendInput, % (GetKeyState("Shift", "P") ? "+" : "") (GetKeyState("Ctrl", "P") ? "^" : "") "{Del}"

LAlt & Shift:: ('optional line')

LAlt&Shift ::('可选线')

It's about holding LAlt + pressing something from: i, k,j, l (arrow keys), u, o (home, end) or h (delete). Last line is optional if you don't want to change keyboard lang. layout by LAlt +Shift

这是关于持有LAlt +按下的东西:i,k,j,l(箭头键),u,o(主页,结束)或h(删除)。如果您不想更改键盘朗,则最后一行是可选的。由LAlt + Shift布局

You can use it even in combination with modificators like shift and ctrl.

即使与shift和ctrl等修饰符结合使用,您也可以使用它。

enjoy ;)

#7


I would totally recommend vim... as it will help a lot of this! Also, look into something that will auto-close your parenthesis, square brackets, and curly brackets for you... I have something in vim that does this and it helps with this type of problem because I'm already inside the parenthesis.

我完全会推荐vim ...因为它会帮助很多这个!另外,看看会自动关闭括号,方括号和大括号的东西......我在vim中有一些东西可以做到这一点,它有助于解决这类问题,因为我已经在括号内了。

#8


Another vote for Vim. Also, there are some great plugins for more standard IDEs that use Vi keybindings. I use jVI in Netbeans from time to time.

对Vim的另一次投票。此外,还有一些很棒的插件可供使用Vi键绑定的更多标准IDE。我不时在Netbeans中使用jVI。

You'll find that the more you use Vim, the easier it is on your wrists. You'll also find that a sufficiently clever find/replace can save you quite a few keystrokes, as can a global action regex-y thing.

你会发现你使用Vim的次数越多,你的手腕就越容易。您还会发现,一个足够聪明的查找/替换可以为您节省大量的键击,就像全局动作正则表达式一样。

Bind :tabn and :tabp to something accessible like and and force yourself to get stuff done without giving up and using a proper GUI editor.

绑定:tabn和:tabp到可访问的东西,并强制自己完成工作而不放弃和使用正确的GUI编辑器。

#9


I used to type completely linearly (yes, in vim), never could get the hang of the dashing back and forth that writing closing elements immediately created.

我曾经完全线性地键入(是的,在vim中),永远不会得到立即创建的写入关闭元素的来回潇洒。

However, I now use Eclipse - it creates them for me as I go, so at the end of something with a )")) mess I just hit end and type a ;, no need to deal with it manually at all. Which sometimes confuses me, but that's ok.

但是,我现在使用Eclipse - 它在我创建时为我创建它们,所以在a)的某些结尾处“))混乱我只是点击结束并键入a;,根本不需要手动处理它。困惑我,但没关系。

#10


I find the number pad makes navigation very easy because the home and pgup keys are so close. For actually typing numbers you just use the top row of the keyboard (which is difficult to learn I agree but sufficiently fast after a while).

我发现数字键盘使导航非常容易,因为home和pgup键非常接近。对于实际输入数字,你只需使用键盘的顶行(这很难学习我同意但一段时间后足够快)。

The only downsides of this for me are using laptop keyboards and using other people's machines where I have to turn off num lock every time.

这对我来说唯一的缺点是使用笔记本电脑键盘和使用其他人的机器,我必须每次都关闭num lock。

#11


A good IDE (galileo is almost here) will auto close brackets, parentheses, etc, and will intelligently insert a semicolon at the end of the statement too. No need to use arrows at all!

一个好的IDE(伽利略几乎就在这里)会自动关闭括号,括号等,并且会在语句的末尾智能地插入分号。根本不需要使用箭头!

Of course for a println in Eclipse you can just type sysout but that's probably a bad habit to get into.

当然对于Eclipse中的println,您只需输入sysout即可,但这可能是一个不好的习惯。

But be careful! If you get too quick your colleagues will always make you drive :P

不过要小心!如果你太快,你的同事总会让你开车:P