[VIM] Insert 모드에서 paste하기

잡설

vim 을 주력으로 쓰는 상황에서 마우스를 버리기 힘든 이유가 Insert모드에서 copy paste를 해야하는 경우가 많기 때문입니다.
특히나 Insert 모드에서 paste하기 위해선 esc 눌러서 Normal 모드로 간 다음 위치 조정해서 paste 하고 다시 i 로 Insert 모드로 재진입하는 번거러움은.. 정말 귀찮음 그 자체죠.
물론 vim 개발자 형님들이 만들었을거라는 생각은 했지만 그냥 마우스를 쓰는 방법이 있으니 그걸 찾기까지 생각이 미치지 못했죠.
그러다 우연한 계기(나중에 설명)로 방법을 찾게 되었고 reddit 댓글을 인용하자면 "this is sorcery!" 를 외치게 되었습니다.

CTRL+R

Normal 모드에서는 그냥 Redo입니다. vim 사용자는 다들 아시는 단축키죠.

:help ^R
CTRL-R                  Redo [count] changes which were undone.  {Vi: redraw
                        screen}

하지만 Insert 모드에서는 다릅니다.

:help i^R
CTRL-R {0-9a-z"%#*+:.-=}                                        i_CTRL-R
                Insert the contents of a register.  Between typing CTRL-R and
                the second character, '"' will be displayed to indicate that
                you are expected to enter the name of a register.
                The text is inserted as if you typed it, but mappings and
                abbreviations are not used.  If you have options like
                'textwidth', 'formatoptions', or 'autoindent' set, this will
                influence what will be inserted.  This is different from what
                happens with the "p" command and pasting with the mouse.
                Special registers:
                        '"'     the unnamed register, containing the text of
                                the last delete or yank
                        '%'     the current file name
                        '#'     the alternate file name
                        '*'     the clipboard contents (X11: primary selection)
                        '+'     the clipboard contents
                        '/'     the last search pattern
                        ':'     the last command-line
                        '.'     the last inserted text
                        '-'     the last small (less than a line) delete
                                                        i_CTRL-R_=
                        '='     the expression register: you are prompted to
                                enter an expression (see expression)
                                Note that 0x80 (128 decimal) is used for
                                special keys.  E.g., you can use this to move
                                the cursor up:
                                        CTRL-R ="\<Up>"
                                Use CTRL-R CTRL-R to insert text literally.
                                When the result is a List the items are used
                                as lines.  They can have line breaks inside
                                too.
                                When the result is a Float it's automatically
                                converted to a String.
                See registers about registers.  {not in Vi}

뭐가 많군요! 어차피 다 쓸건 아니니 스킵하고 아래 활용법만 익히세요.

활용법1

Insert Mode에서 Paste
CTRL+R+"

마지막 "를 입력하기 복잡하니 다음과 같이 합니다.
CTRL+R+0

아마도 0이 기본 버퍼인것 같은데 잘 모르므로 그냥 이렇게 씁니다.

활용법2

Insert Mode에서 방금 전 찾기한 텍스트 입력
CTRL+R+/

/는 Normal Mode에서 검색할때 쓰는 명령이니 익숙하실겁니다.
저는 정말 많이 쓰는 기능입니다.

활용법3

Command Mode에서 Paste
예를 들어 copy한 파일명을 열때 다음과 같이 하면 되는거죠!
:e CTRL+R+0


활용법3을 연구하다 발견한 기능입니다.
이것들만 잘 활용해도 마우스 쓸 일이 확 줄어들어서 좋습니다!

댓글

이 블로그의 인기 게시물

WSL2 Ubuntu 20.04 및 네트워크 설정

리눅스 멀티코어를 사용하는 tar 압축/해제

git pull 을 했더니 branch가 갈라지는 경우