簡體   English   中英

在vim中執行命令后,在兩個標簽之間進入插入模式

[英]Enter insert mode between two tags after command in vim

我希望更改以下vim命令,以便在輸入:%s / temp123 // g部分后,它將使我進入\\ begin和\\ end標記之間的插入模式。

 inoremap \\beg \begin{temp123}<enter><enter>\end{temp123}<enter><esc>:%s/temp123//g<left><left>

輸入搜索/替換命令后,我已經可以使用:startinsert進入插入模式,但是我無法將光標置於\\ begin和\\ end標記之間。

任何幫助/解決方案/改進將不勝感激。

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然后返回到第一個函數,然后完成粘貼:

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>

但這也不起作用。 我還嘗試了不帶nnoremap <MiddleMouse> :set paste<cr>"+p:set nopaste<cr>不帶:startinsert"+p"*p寄存器,但這又只是直接粘貼,就像我在鍵入它一樣,它不進入insert第一個模式。我願意相信這將與+剪貼板編譯版本的Vim的工作,但不是我的版本。 鏈接到我原來的問題及答案

是的,您正在尋找一種交互式替換,但是:s / new / old / g c不允許您編輯每個匹配項。 對於這種工作,請切換至gn命令+ 食譜:

對於第一個搜索{} temp123(或任何你要替換)與/
然后按cgn更改視覺選擇的下一個匹配項
完成后,返回普通模式以提交您的編輯。
如果下一個編輯與上一個相同,則僅按 否則cgn
上升並重復。

有關更多的想法,請參見此vimcast: gn命令。

這是我現在使用的解決方案。

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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM