LoginSignup
177
151

More than 5 years have passed since last update.

vimでペーストする際に、自動でpaste modeにする方法のメモ

Posted at

vimでpasteを行うと、自動的にインデントがかかり、盛大に崩れてしまってしまう事がある。

そんな時は、都度autoindentを無効にしたり

:set noautoindent

都度paste mode にしたり

:set paste

:a! を使う方法があるらしいです。

":a!"
ペースト
エスケープキー

とはいえ、都度キーを打つのは面倒なので、自動化したいです。

自動化の方法

.vimrcに直接書くパターン

if &term =~ "xterm"
    let &t_ti .= "\e[?2004h"
    let &t_te .= "\e[?2004l"
    let &pastetoggle = "\e[201~"

    function XTermPasteBegin(ret)
        set paste
        return a:ret
    endfunction

    noremap <special> <expr> <Esc>[200~ XTermPasteBegin("0i")
    inoremap <special> <expr> <Esc>[200~ XTermPasteBegin("")
    cnoremap <special> <Esc>[200~ <nop>
    cnoremap <special> <Esc>[201~ <nop>
endif

pluginのパターン

cd ~/.vim/bundle
git clone https://github.com/ConradIrwin/vim-bracketed-paste

or

NeoBundle 'ConradIrwin/vim-bracketed-paste'

どちらの場合も、bracketed paste modeに対応しているターミナルである必要があるみたいです。

You need to be using a modern xterm-compatible terminal emulator that supports bracketed paste mode. xterm, urxvt, iTerm2, gnome-terminal (and other terminals using libvte) are known to work.

参考

177
151
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
177
151