我希望更改以下vim命令,以便在输入:%s / temp123 // g部分后,它将使我进入\ begin和\ end标记之间的插入模式。
inoremap \\beg \begin{temp123}<enter><enter>\end{temp123}<enter><esc>:%s/temp123//g<left><left>
输入搜索/替换命令后,我已经可以使用:startinsert进入插入模式,但是我无法将光标置于\ begin和\ end标记之间。
任何帮助/解决方案/改进将不胜感激。
答案 0 :(得分:0)
TL; DR:不能。
:star[tinsert][!] Start Insert mode just after executing this command. Works like typing "i" in Normal mode. When the ! is included it works like "A", append to the line. Otherwise insertion starts at the cursor position. Note that when using this command in a function or script, the insertion only starts after the function or script is finished. This command does not work from :normal.
我正在尝试使以下行工作:
nnoremap <MiddleMouse> :set paste<cr>:startinsert<MiddleMouse><esc>
这意味着我在:startinsert
之后放置的所有命令都改为在:startinsert
之前紧接着运行,然后:startinsert
运行并更改插入模式(注意:对于使用i
而不是:startinsert
也是如此)。
下一步是尝试创建一个嵌套函数,其中有一个函数调用另一个函数,第二个函数运行:startinsert
然后返回第一个函数,然后完成粘贴:< / p>
function! Paste()
call InsertMode()<cr>
:set paste<cr>
<S-Insert>
:set nopaste<cr>
<esc>
endfunction
function! InsertMode()
:startinsert<cr>
endfunction
nnoremap <MiddleMouse> call Paste()<cr>
但这也不起作用。我还尝试了将"+p
和"*p
寄存器与:startinsert
一起使用而没有nnoremap <MiddleMouse> :set paste<cr>"+p:set nopaste<cr>
的情况,但这只是直接粘贴,就像我在输入时一样,它不会输入{{ 1}}模式。我愿意相信这可以在使用+ clipboard编译的Vim版本上使用,但是那不是我的版本。 Link to my original question and answer
答案 1 :(得分:0)
是的,您正在寻找一种交互式替换,但:s / new / old / g c 不允许您编辑每个匹配项。对于这种工作,请切换到 gn 命令+ 。配方:
首先用 /
搜索{temp123}(或您要替换的任何东西)
然后按 cgn 更改视觉选择的下一个匹配项
完成后,返回普通模式以提交您的编辑。
如果下一个编辑与上一个相同,则仅按。,否则按 cgn
上升并重复。
有关更多想法,请参见以下视频广播:gn command
答案 2 :(得分:0)
这是我现在正在使用的解决方案。
function TexBegin()
let currline = line(".")
call inputsave()
let tagname = input("enter tag name: ")
call inputrestore()
call setline(currline, "\\begin{" . tagname . " }")
normal o
normal o
call setline(currline + 2, "\\end{" . tagname . "}")
normal l
startinsert
normal o<Esc>
endfunction
inoremap \\beg <Esc>:call TexBegin()<CR>