ProgramingTip

Emacs에서 한 번에 여러 줄 편집

bestdevel 2020. 11. 22. 20:21
반응형

Emacs에서 한 번에 여러 줄 편집


textmate에는 입력을 시작하면 선택한 모든 줄에 동일한 내용이 입력되는 모드가 있습니다. emacs와 이와 같은 조직입니까? 방법이 나를 도울 수있는 방법이 생각하지만 어떻게 해야할지 모르겠습니다.


다음과 같이 간단합니다. CX RT

몇 가지 예는 다음과 가변합니다. http://ergoemacs.org/emacs/emacs_string-rectangle_ascii-art.html


반드시 여러 개의 커서를 설치해야합니다.

https://github.com/magnars/multiple-cursors.el

마멀레이드와 멜파에 있습니다.

Mx 패키지 설치 다중 커서

솔루션 중 하나는 CUA 모드를 사용하는 것입니다. 으로 cua 모드를 활성화하고 M-x cua-mode사각형 시작을 선택합니다. 먼저를 C-Enter다음 표준 이동 명령으로 커서를 이동하여 선택합니다. 이제 Enter 키를 통해 커서를 순환 확장의 선택 항목에 텍스트를 추가하거나 추가 할 수 있습니다.


다음 명령 (및 키)을 사용하여이를 수행 할 수 있습니다.

  • 열린 곳에 (Cx, r, o) 공백 추가
  • kill-rectangle (Cx, r, k) 삭제
  • 명확한 내용 (Cx, r, c)은 공백으로 대체
  • 지정된 텍스트로 Mx string-insert-rectangle 채우기

다음은 설치 기능에 대한 자세한 설명입니다. http://www.gnu.org/software/emacs/manual/html_node/emacs/Rectangles.html


좀 더 복잡한 시나리오를 위해이 작업을 수행하고 새 모듈을 설치하지 않고 수행하려는 경우 계속 진행됩니다. (저는 개인적으로 MarkMultiple을 사용하고 좋아하지만 MarkMultiple을 설치하지 Emacs에서 가능합니다)

최근에 SQL 쿼리를 파일에 출력 한 다음 MYSQL INSERT 쿼리로 형식을 지정해야합니다. Emacs가 내 인생을 어떻게 쉽게 만들 었는지 보여줍니다.

파일은 다음과 가변됩니다.

1   I am a random text
2   I am not
3   G, you've gone mad
4   Click on this link
5   Transfer in progress (we've started the transfer process)
6   But transfer happend yesterday
7   No you are
8   Oh please! this is getting too much!
9   I love emacs
10  I cant be bothered with this any more
11  its time to raise the bar
12  show me how to expand my territory

그리고 나는 그것을 다음과 같이 만들고 싶습니다.

(1,   ,'I am a random text'),
(2,   ,'I am not'),
(3,   ,'G, youve gone mad'),
(4,   ,'Click on this link'),
(5,   ,'Transfer in progress (weve started the transfer process)'),
(6,   ,'But transfer happend yesterday'),
(7,   ,'No you are'),
(8,   ,'Oh please! this is getting too much!'),
(9,   ,'I love emacs'),
(10,  ,'I cant be bothered with this any more'),
(11,  ,'its time to raise the bar'),
(12,  ,'show me how to expand my territory'),
  1. 첫 번째 줄에 커서 놓기
  2. C-x (추적 시작 합니다. [이 시점에서 모든 키 입력이 기록되고 있습니다.]
  3. C-a의 시작으로 줄 이동하려면 누르 세요.
  4. "("다음에 M-f단어를 앞으로 이동 앞으로 ","을 입력하십시오.
  5. C-n다음 줄로 이동 C-x )하고 매크로를 종료합니다.
  6. C-u 11 C-x e 매크로 n (이 경우 11)을 반복합니다.

유레카! 지금까지 실패하지 않았다면 다음과 같은 것을 얻을 수 있습니다.

(1,   I am a random text
(2,   I am not
(3,   G, youve gone mad
(4,   Click on this link
(5,   Transfer in progress (weve started the transfer process)
(6,   But transfer happend yesterday
(7,   No you are
(8,   Oh please! this is getting too much!
(9,   I love emacs
(10,  I cant be bothered with this any more
(11,  its time to raise the bar
(12,  show me how to expand my territory

이 시점에서 나는 나머지를 알아 내도록 당신을 떠날 것입니다. 하지만 가기 전에 이런 종류의 일을 달성하는 데는 꽤 많은 방법이 있음을 언급하고 싶습니다. 이것은 그 중 하나에 불과하며 제가 가장 좋아하는 방법입니다.

도움이 되었기를 바랍니다.)


boskom이 제안한 cua 모드를 찾고 있다고 생각합니다. http://www.vimeo.com/1168225?pg=embed&sec=1168225 이 스크린 캐스트는 이것을 사용하는 방법에 대한 아이디어를 제공 할 수 있습니다.


직사각형은 인접한 줄에서 같은 양의 공간을 삭제하는 것과 같은 간단한 작업을위한 것입니다.

그렇지 않으면 키보드 매크로가 갈 길입니다.


위에 표시된 답변은 열에 텍스트를 삽입하기위한 것입니다. TextMate의 "선택에서 각 줄 편집"은 각 줄의 길이에 관계없이 각 줄에 동일한 텍스트를 삽입합니다. 나는 지금 Lisp를 배우고있다. 그래서 나는 이것을하기위한 함수를 썼다.

(defun append-to-lines (text-to-be-inserted)
  ;;Appends text to each line in region
  (interactive "sEnter text to append: ")
  (save-excursion
    (let (point-ln mark-ln initial-ln final-ln count)
      (barf-if-buffer-read-only)
      (setq point-ln (line-number-at-pos))
      (exchange-point-and-mark)
      (setq mark-ln (line-number-at-pos))
      (if (< point-ln mark-ln)
          (progn (setq initial-ln point-ln final-ln mark-ln)
                 (exchange-point-and-mark))
        (setq initial-ln mark-ln final-ln point-ln))
      (setq count initial-ln)
      (while (<= count final-ln)
        (progn (move-end-of-line 1)
               (insert text-to-be-inserted)
               (next-line)
               (setq count (1+ count))))
      (message "From line %d to line %d." initial-ln final-ln ))))

먼저 영향을 미치려는 모든 줄을 포함하는 선택을 한 다음 Mx 줄에 추가를 사용하여 함수를 실행합니다.

참고 URL : https://stackoverflow.com/questions/761706/in-emacs-edit-multiple-lines-at-once

반응형