如何使用C-X e调用VIM来处理长而复杂的棘手命令? [英] How can I invoke VIM with C-X e for long, complex, tricky commands?

查看:109
本文介绍了如何使用C-X e调用VIM来处理长而复杂的棘手命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此处找到了一个很棒的提示。您可以 [r]巧妙地调用编辑器来编写冗长,复杂或棘手的命令。但是,当我按下上面的组合键时,我打开了Emacs。我想将其切换到Vim。如何使用C-X e调用Vim?

I found an awesome tip here. You can "[r]apidly invoke an editor to write a long, complex, or tricky command". However, when I press the key combination above, I get Emacs open. I would like to switch it to Vim. How can I invoke Vim with C-X e?

[1。 Brian Cambell解决的问题]


export EDITOR = vim

export EDITOR=vim

添加到您的.bashrc或适当的Shell rc文件中

Add to your .bashrc or appropriate shell rc file

[2。通过Pax解决了问题]

我无法将棘手的命令返回给Bash。错误为:

I was unable to get the tricky command back to Bash. The errors were:

 > Error detected while processing BufRead Auto commands for "*":
 > E117: Unknown function: JumpToLastPosition

.vimrc中的行情解决了第二个问题。我仍然不确定我的.vimrc中的部分:

Quotes in .vimrc solved the second problem. I am still unsure about the part in my .vimrc:

  "  augroup misc
  "      autocmd!
  "      autocmd BufReadPost * call JumpToLastPosition()
  "      autocmd FileChangedShell * call WarningMsg("File changed outside of vim")
  "  augroup end

[3。问题]

以上内容在做什么.vimrc可以吗?

What do the above part in .vimrc do?

推荐答案

在大多数Linux安装(我测试过的所有安装)中,bash都能识别Emacs和Vi命令历史记录键(或者您可以使用 set -o vi 强制输入)。

On most Linux installs (all the ones I tested), bash recognizes both the Emacs and Vi command history keys (or you can use "set -o vi" to force it).

因此,您可以使用vi模式< ESC> v 进入可视模式,这将在Vim会话中开始编辑。

So, you can just use the vi-mode "<ESC>v" to to enter visual mode, this will start editing in a Vim session.

要运行该命令,只需保存并退出Vim( ZZ :wq )。要取消该命令,需要删除内容,然后保存并退出( 1GdGZZ )。

To run the command, you just save and exit from Vim ("ZZ" or ":wq"). To cancel the command, you need to delete the contents, save and exit ("1GdGZZ").

除了通过退出运行它之外,还可以在编辑器中将其保存到其他位置(:w / tmp / myscript )。

In addition to running it by exiting, you can also save it while in the editor to another location (":w /tmp/myscript").

请记住,可视模式将与当前选定的行一起使用,因此您不必以空白命令开头( < ESC> v )。您可以使用常规的vi模式工具从历史记录中先选择一行,然后然后进入可视模式(< ESC> kv 对于最后一个命令,< ESC> / grep< ENTER> nnv 对于最后一个grep命令,依此类推)。

Keep in mind that visual mode will work with the currently selected line so you don't have to start with a blank command ("<ESC>v"). You can use the normal vi-mode tools to select a line from the history first and then enter visual mode ("<ESC>kv" for last command, "<ESC>/grep<ENTER>nnv" for third-last grep command and so on).

使用此方法的优点是不更改可能用于其他用途的 EDITOR 变量(除非您希望Vim用于一切,这是采取IMNSHO的非常明智的立场。)

Using this method has the advantage of not changing the "EDITOR" variable which may be used for other things (unless you want Vim for everything, which is a very sensible position to take IMNSHO).

更新:

关于您的错误,在问题后发布:

Regarding your error, posted after the question:

JumpToLastPosition()是Vim调用的函数所有文件都将光标置于上次编辑文件时的位置。我假设您实际上是在编辑开始时(而不是退出时)收到此错误,因为这是读取缓冲区后的自动功能。

JumpToLastPosition() is the function called by Vim for all files to put the cursor where it was when you last edited the file. I'm going to assume you're actually getting this error when the editing starts, not when you exit, since this is the auto function following a buffer read.

Can您启动了一个普通 vim会话( vim xx.txt 然后是 vim xx )发生错误?您可能会发现遇到相同的问题(并且可能仅在最后一个问题上遇到)。

Can you start a "normal" vim session ("vim xx.txt" and then "vim xx") without this error occurring? You may find you get the same problem (and possibly only on the last one).

如果确实存在相同的问题,则需要查看启动文件。 BufRead的autocmd可能会以某种方式损坏。看一下vimrc和filetype.vim文件,以了解在何处调用和/或定义了该函数(我怀疑它已被调用但未定义,这可能是两个文件之间不匹配或其中一个已损坏)。

If you do have the same problem, you need to look at your startup files. It's possible the autocmd for BufRead is broken somehow. Have a look inside your vimrc and you filetype.vim files to see where that function is called and/or defined (I suspect it's called but not defined and that may be a mismatch between the two files or one of them has been damaged).

这篇关于如何使用C-X e调用VIM来处理长而复杂的棘手命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆