git rebase 파일에서 단어를 대체하는 방법

git rebase 파일에서 단어를 대체하는 방법

대화형 리베이스(예: )를 수행할 때 Git에서 생성된 리베이스 목록을 빠르게 편집하기 위해 시각적 모드 매핑을 설정하려고 합니다 git rebase --interactive upstream/master. 그러면 다음과 같은 텍스트 파일이 제공됩니다.

pick 12345678 commit message 1
pick 23456789 commit message 2
pick 34567890 commit message 3

내가 하고 싶은 일은 <c-v>다른 리베이스 방법으로 전환하고 싶은 줄을 선택하고 수행하는 것입니다. 예를 들어 줄의 첫 번째 단어에서 를 <localleader>f로 변경하는 데 사용합니다. 나는 이것을 약간의 내결함성을 갖도록 만들고 싶습니다. 그래서 주석이나 빈 줄과 같은 다른 줄에 대해서는 이 작업을 수행하지 않습니다.pickfixup

내가 시도한 것은 :substitute정규 표현식 그룹을 사용하여 유효한 단어만 선택하는 것입니다: (pick|reword|edit|squash|fixup|exec|drop). 현재 내가 가지고 있는 것은 다음과 같습니다 .vimrc.

autocmd FileType gitrebase vnoremap <buffer> <localleader>p :s/^\(pick\|reword\|edit\|squash\|fixup\|exec\|drop\)/pick/<cr>
autocmd FileType gitrebase vnoremap <buffer> <localleader>r :s/^\(pick\|reword\|edit\|squash\|fixup\|exec\|drop\)/reword/<cr>
autocmd FileType gitrebase vnoremap <buffer> <localleader>e :s/^\(pick\|reword\|edit\|squash\|fixup\|exec\|drop\)/edit/<cr>
autocmd FileType gitrebase vnoremap <buffer> <localleader>s :s/^\(pick\|reword\|edit\|squash\|fixup\|exec\|drop\)/squash/<cr>
autocmd FileType gitrebase vnoremap <buffer> <localleader>f :s/^\(pick\|reword\|edit\|squash\|fixup\|exec\|drop\)/fixup/<cr>
autocmd FileType gitrebase vnoremap <buffer> <localleader>x :s/^\(pick\|reword\|edit\|squash\|fixup\|exec\|drop\)/exec/<cr>
autocmd FileType gitrebase vnoremap <buffer> <localleader>d :s/^\(pick\|reword\|edit\|squash\|fixup\|exec\|drop\)/drop/<cr>

불행히도 정규식은 아무것도 일치하지 않습니다. \=그룹의 모든 단어 중 0 또는 1과 일치하도록 패턴 끝에 a를 추가하려고 시도했으며 대체할 단어 앞에 대체 항목을 추가합니다.

내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변1

탈출하는 일입니다. 항상 \\|대신 사용하거나 \|시도해 보십시오.

autocmd FileType gitrebase vnoremap <buffer> <localleader>p :s/\v^(pick\|reword\|edit\|squash\|fixup\|exec\|drop)/pick/<cr>

관련 정보