사용자 도구

사이트 도구


vim:tips

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
마지막 판 양쪽 다음 판
vim:tips [2021/04/10 13:06]
kwon37xi
vim:tips [2021/05/13 08:38]
kwon37xi
줄 172: 줄 172:
 <code sh> <code sh>
 :set nrformats+=alpha :set nrformats+=alpha
 +</code>
 +
 +===== 커서 중앙 유지 =====
 +  * 화면상에서 커서 위치가 항상 화면 중앙에 오게 하는 방법
 +  * [[https://vim.fandom.com/wiki/Keep_your_cursor_centered_vertically_on_the_screen|Keep your cursor centered vertically on the screen | Vim Tips Wiki | Fandom]]
 +  * ''set scroloff=5'', ''set so=5 : 커서의 위 아래로 5줄씩 보이라는 의미. 기본값 0.
 +  * ''set so=999'' : 되도록 중앙에 위치하게 함.
 +  * ''<Leader>zz'' 누르면 커서 중앙 위치 toggle
 +<code vim>
 +nnoremap <Leader>zz :let &scrolloff=999-&scrolloff<CR>
 +</code>
 +  * 최종
 +
 +<code>
 +set scrolloff=<any startup value you like>
 +if !exists('*VCenterCursor')
 +  augroup VCenterCursor
 +  au!
 +  au OptionSet *,*.*
 +    \ if and( expand("<amatch>")=='scrolloff' ,
 +    \         exists('#VCenterCursor#WinEnter,WinNew,VimResized') )|
 +    \   au! VCenterCursor WinEnter,WinNew,VimResized|
 +    \ endif
 +  augroup END
 +  function VCenterCursor()
 +    if !exists('#VCenterCursor#WinEnter,WinNew,VimResized')
 +      let s:default_scrolloff=&scrolloff
 +      let &scrolloff=winheight(win_getid())/2
 +      au VCenterCursor WinEnter,WinNew,VimResized *,*.*
 +        \ let &scrolloff=winheight(win_getid())/2
 +    else
 +      au! VCenterCursor WinEnter,WinNew,VimResized
 +      let &scrolloff=s:default_scrolloff
 +    endif
 +  endfunction
 +endif
 +
 +nnoremap <leader>zz :call VCenterCursor()<CR>
 </code> </code>
  
vim/tips.txt · 마지막으로 수정됨: 2021/05/13 08:39 저자 kwon37xi