从Vim中的用户定义命令切换到** insert **模式(Switch to **insert** mode from a user-defined command in Vim)
我在我的
vimrc
定义了自己的命令:command! Tcs :normal lvf`hc
目的是我继续进行反击,它会将内部内容从此处删除到下一个反引号。 喜欢:
`hi there` -> ``
问题是仍处于正常模式,我想复制
c
命令行为,以便我可以在插入模式下立即开始键入。我试过
command! Tcs :normal lvf`hc :startinsert
command! Tcs :normal lvf`hc :startinsert
但是我在最后一次c
之后输入的内容将直接在编辑器中输入。谢谢
I'm defining my own command in my
vimrc
:command! Tcs :normal lvf`hc
The aim is that I go on a backtick and it will delete the inner content from here to the next backtick. Like:
`hi there` -> ``
Problem is that is remains in normal mode, I would like to replicate the
c
command behaviour so that I can start typing immediately in insert mode.I've tried
command! Tcs :normal lvf`hc :startinsert
but whatever I put after the lastc
will be typed directly in the editor.Thanks
原文:https://stackoverflow.com/questions/41805215
最满意答案
我的一个朋友在做类似的事情,并帮助我解决了这个问题。
在第2步和第3步,我试图编写输入并使用进程标准输入和输出读取输出,而且,我试图使用.lnk来运行命令提示符。 所有这些都导致了错误。
解决方案是:
- 创建两个批处理文件,一个用于启动命令提示符,另一个用于编译.c文件(这些文件是在程序代码之外创建的)。
- (运行时)使用编写的代码创建.c文件。 如果文件存在,请将其删除并创建一个新文件。
- 使用cmd.exe启动该过程。
- 运行批处理文件,使用Stream Writer将它们写入cmd.exe。
- 使用Stream Reader检索输出。
幸运的是,这有效! 代码结束如下:
string CompileC (string code) { string path = @"C:\sample.c"; string results = ""; try { if (File.Exists(path)) File.Delete(path); using (FileStream fs = File.Create(path)) { byte[] codeText = new UTF8Encoding(true).GetBytes(code); fs.Write(codeText, 0, codeText.Length); } Process process = new Process(); process.StartInfo.FileName = @"C:\Windows\system32\cmd.exe"; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.Start(); using (StreamWriter sw = process.StandardInput) { if (sw.BaseStream.CanWrite) { //This batch starts up the Visual Studio Command Prompt. sw.WriteLine(@"C:\Startup.bat"); //This batch does the compilation, once the Command Prompt //is running, using the 'cl' command. sw.WriteLine(@"C:\Compile.bat"); } } using (StreamReader sr = process.StandardOutput) { if (sr.BaseStream.CanRead) results = sr.ReadToEnd(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } return results; }
A friend of mine worked on something similar, and helped me to solve this problem.
On steps 2 and 3, I was trying to write the input and read the output using simply the process standard input and output, and also, I was trying to use an .lnk to run the Command Prompt. All those things caused the error.
The solution was:
- Create two batch files, one to start up the Command Prompt and the other to compile the .c file (those were created outside the program's code).
- (On runtime) Create the .c file, using the code written. If file exists, delete it and create a new one.
- Start the process with cmd.exe.
- Run the batch files, using a Stream Writer to write them in the cmd.exe.
- Retrieve the output using a Stream Reader.
Fortunately, this worked! Code ended like this:
string CompileC (string code) { string path = @"C:\sample.c"; string results = ""; try { if (File.Exists(path)) File.Delete(path); using (FileStream fs = File.Create(path)) { byte[] codeText = new UTF8Encoding(true).GetBytes(code); fs.Write(codeText, 0, codeText.Length); } Process process = new Process(); process.StartInfo.FileName = @"C:\Windows\system32\cmd.exe"; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.Start(); using (StreamWriter sw = process.StandardInput) { if (sw.BaseStream.CanWrite) { //This batch starts up the Visual Studio Command Prompt. sw.WriteLine(@"C:\Startup.bat"); //This batch does the compilation, once the Command Prompt //is running, using the 'cl' command. sw.WriteLine(@"C:\Compile.bat"); } } using (StreamReader sr = process.StandardOutput) { if (sr.BaseStream.CanRead) results = sr.ReadToEnd(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } return results; }
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
你如何实现Windows窗体应用程序C#的样式?(How do you implement a Styling for Windows forms Application C#?)[2023-09-01]
在控件周围拖出一个矩形,以便它们全部被选中。 按住Ctrl +左键单击调整选择。 更改属性。 或者通过使用类继承来创建自己的“样式”按钮控件。 从Button类派生自己的类,更改构造函数中的属性: using System; using System.Windows.Forms; internal class MyButton : Button { public MyButton() { this.FlatStyle = FlatStyle.Flat; // etc ... -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
我的一个朋友在做类似的事情,并帮助我解决了这个问题。 在第2步和第3步,我试图编写输入并使用进程标准输入和输出读取输出,而且,我试图使用.lnk来运行命令提示符。 所有这些都导致了错误。 解决方案是: 创建两个批处理文件,一个用于启动命令提示符,另一个用于编译.c文件(这些文件是在程序代码之外创建的)。 (运行时)使用编写的代码创建.c文件。 如果文件存在,请将其删除并创建一个新文件。 使用cmd.exe启动该过程。 运行批处理文件,使用Stream Writer将它们写入cmd.exe。 使用Stream ...
-
而不是实例化每个应用程序的控件,将其全部隐藏起来,只显示所选“应用程序”中的控件,考虑这一点:将主选择器面板设计为占位符。 当用户选择一个应用程序时,分配应用程序面板实例来代替选择器面板实例,并允许应用程序执行完成。 退出后,还原占位符实例。 Rather than instantiate the controls for each application, hide them all, and just show the ones from the selected "application", cons ...
-
启动时,我已经能够在应用程序上生成NamedPipeServer。 命名管道服务器名称本身标记有应用程序的名称+它生成的进程ID。 进程号记录在users appdata文件夹中的ini文件中。 可以使用可选的命令行参数启动该进程,以实现“callingApplication”的值,即“INI标头”。 这样,我们可以从不同的调用者创建应用程序的多个实例,而不会干扰并确保连接到正确的命名管道。 static void Main(string[] args) { string callingApplic ...
-
您可能想要查找MFC或Qt框架 。 两者都有一个很好的GUI编辑器和视觉工作室集成(MFC实际上与视觉工作室一起) Winforms是一个严格的.NET事物,所以无论你做什么,它都不会是Winforms。 You might want to look up MFC or the Qt framework. both have a nice GUI editor and integrate with visual studio (MFC actually comes with visual studio) W ...
-
C# - 获取Windows窗体应用程序中SelectedItem的值(C# - getting value of SelectedItem in Windows Forms application)[2022-02-18]
我知道我有点晚了,但是这很有效: int? nStoreNumber = cmbABSM.SelectedValue as int?; if (nStoreNumber==null) return; I know I am a little late, but this works well: int? nStoreNumber = cmbABSM.SelectedValue as int?; if (nStoreNumber==null) return; -
您创建了第一个表单的另一个实例并将其隐藏,因此您当前打开的第一个表单将不会隐藏。 您应该隐藏打开的实例。 为此,您可以使用Application.OpenForms找到它: var first = Application.OpenForms.OfType
().FirstOrDefault(); if (first != null) first.Hide(); 您还可以在Program类中保留对第一个表单的引用,并使用该引用Hide它或再次Show它。 请注意, Applica ... -
如何在Windows窗体应用程序vc ++中导入C静态库(How to import the C static Libraries in windows forms application vc++)[2022-05-15]
链接器错误消息强烈暗示它出错了什么。 注意未定义符号的__clrcall调用约定,它告诉您编译器认为这些是“CLR”函数。 托管代码,当然不是,它们是__cdecl。 还有更多,名字也被破坏了。 请注意名称中的“@@ $$ FYM?AW4STATUS @@ E @ Z”诅咒。 这告诉你编译器认为它们是用C ++而不是C语言编写的。 你必须明确告诉编译器这个,.h文件不够兼容。 你在C ++ / CLI源代码文件中这样做: #pragma managed(push, off) extern "C" { #in ...