Programing

Vim에서 커서를 이동하지 않고 화면을 이동하는 방법은 무엇입니까?

crosscheck 2020. 10. 4. 10:30
반응형

Vim에서 커서를 이동하지 않고 화면을 이동하는 방법은 무엇입니까?


최근 에 Vim의 Ctrl+ ECtrl+ Y단축키를 발견했습니다.이 단축키는 각각 커서를 움직이지 않고 한 줄씩 화면을 위아래로 움직 입니다.

커서가있는 곳에 커서를두고 화면을 이동하여 커서가있는 줄이 첫 번째 줄이되도록하는 명령을 알고 있습니까? (마지막 줄에 대한 명령이 있으면 좋은 보너스가 될 것입니다).

Ctrl+ E(또는 Ctrl+ Y)를 적절한 횟수 만큼 수동으로 눌러이를 달성 할 수 있지만, 어떻게 든 직접 수행하는 명령이 있으면 좋을 것입니다.

어떤 아이디어?


  • zz- 화면의 중앙에 현재 행을 이동
    ( 과주의zz 당신이 일어날 경우, Caps Lock실수로 저장하고 종료합니다 vim!)
  • zt -현재 줄을 화면 상단으로 이동
  • zb -현재 줄을 화면 하단으로 이동

추가적으로 :

  • Ctrl- y화면을 한 줄 위로 이동
  • Ctrl- e화면을 한 줄 아래로 이동
  • Ctrl- u커서와 화면을 ½ 페이지 위로 이동
  • Ctrl- d커서와 화면을 ½ 페이지 아래로 이동
  • Ctrl- b화면을 한 페이지 위로 이동하고 커서를 마지막 줄로 이동
  • Ctrl- f화면을 한 페이지 아래로 이동하고 커서를 첫 번째 줄로 이동

Ctrl- yCtrl- e커서가 화면 밖으로 이동할 경우에만 커서 위치를 변경합니다.

씨의 http://www.lagmonster.org/docs/vi2.html


Vim은 커서가 항상 현재 화면에 있어야하지만 현재 위치 스크롤을 북마크 한 다음 원래 위치로 돌아갈 수 있습니다.

mg  # This book marks the current position as g (this can be any letter)
<scroll around>
`g  # return to g

다음은 vimrc의 솔루션입니다.

"keep cursor in the middle all the time :)
nnoremap k kzz
nnoremap j jzz
nnoremap p pzz
nnoremap P Pzz
nnoremap G Gzz
nnoremap x xzz
inoremap <ESC> <ESC>zz
nnoremap <ENTER> <ENTER>zz
inoremap <ENTER> <ENTER><ESC>zzi
nnoremap o o<ESC>zza
nnoremap O O<ESC>zza
nnoremap a a<ESC>zza

커서가 화면 중앙에 머무르고 화면이 위아래로 이동합니다.


사용할 때 같은 열에 커서를 두려면 Ctrl+ D, Ctrl+ F, Ctrl+ B, Ctrl+ U, G, H, M, L,gg

다음 옵션을 정의해야합니다.

:set nostartofline

커서 이동 명령 앞에 숫자를 붙이면 해당 명령이 여러 번 반복됩니다.

10Ctrl+ E한 번 대신 Ctrl+ E10 번 수행 합니다.


You may find aswers to this question useful: Scrolling Vim relative to cursor, custom mapping: you can use ScrollToPercent(0) from that question to do this.


zEnter does exactly what this question asks for.

It works where strangely zz would not work (vim 7.4.1689 on Ubuntu 2016.04 LTS with no special .vimrc)


Surprised no one is using the Scrolloff option which keeps the cursor in the middle of the page. Try it with:

:set so=999

It's the first recommended method on the vim wiki and works well


Sometimes it is useful to scroll text with K and J keys. So I have this "scroll mode" function in my .vimrc (also binded on zs)

scroll_mode.vim


There is a new plugin which I wrote, it enables you to navigate the hole file without moving the cursor position. It's based on folding the lines between your position and your target position and then jump over the fold. Or abort it and don't move at all.

It's also easy to fast switch between cursor is the firt line, cursor is the last line and cursor is in the middle by just clicking j, k or l (when you are in the mode of the plugin.)

I guess it would be a good fit here: https://github.com/anschnapp/move-less

참고URL : https://stackoverflow.com/questions/3458689/how-to-move-screen-without-moving-cursor-in-vim

반응형