vim-tw / ama

Helping vimmer in Taiwan with any questions.
https://github.com/vim-tw/ama/issues
16 stars 1 forks source link

貼上時排版會亂掉 #7

Closed wildskyf closed 8 years ago

wildskyf commented 8 years ago

在貼程式碼的時候縮排會亂掉,比如說下面這段 code:

#include <iostream>

int main() {
    std ::cout << "yo";
    std ::cout << "2";
    return 0;
}

會變成 2016-01-22 03-29-05

目前已知可以下 :set paste 來避免縮排毀掉,但還要再下 :set nopaste 變回來,這太麻煩了! 於是就找了網路上的文章,發現可以把下面這行加到 .vimrc 中:

:set pastetoggle=<F9>

這樣未來貼上前按一下 <F9>,貼上後再按一次 <F9> 就好。

我的問題來了!

雖然這樣已經比一開始方便許多,但有沒有方法在我貼上時,自動幫我把那兩下 <F9> 按下去? 換句話說,我連按那兩下 <F9> 都懶,有沒有人能救救我這個懶惰鬼呢? XD

科技始終來自於人性

goldie-lin commented 8 years ago

@wi1d5ky:

但有沒有方法在我貼上時,自動幫我把那兩下 按下去?

https://github.com/wincent/terminus 此 vim plugin 含此功能, 但目前尚未看到更單純的 vim plugins。 關鍵字: "bracketed paste".

wildskyf commented 8 years ago

感謝 @goldie-lin 提供的外掛!! 還有 @othree 的 https://github.com/othree/rc/blob/master/home/.vimrc#L669-L681 :

if &term =~ "xterm.*"
  let &t_ti = &t_ti . "\e[?2004h"
  let &t_te = "\e[?2004l" . &t_te
  function XTermPasteBegin(ret)
    set pastetoggle=<Esc>[201~
    set paste
    return a:ret
  endfunction
  map <expr> <Esc>[200~ XTermPasteBegin("i")
  imap <expr> <Esc>[200~ XTermPasteBegin("")
  cmap <Esc>[200~ <nop>
  cmap <Esc>[201~ <nop>
endif
chusiang commented 8 years ago

這想法挺酷的!等哪天有需要用到再來試試,不過在下早早就有設過了 @othree 的這段哩。

Reference