기본적으로 들어가는 기능들과
마우스 기능
일하면서 느낀 파일에서 찾기 기능의 중요성 등을 통해
시프트 에프와
컨트롤 에프로 찾기기능 사용할 수 있다.
마우스를 통해 커서 이동을 가능하게 했고
마우스 휠 스크롤로 줄이 이동이 안되서 f1 f2 로 이동시켰다.
줄번호는 커서 위치별 전체줄 퍼센테이지에 따라 색상을 다르게 해 가독성을 높였다.
" VIM 옵션
syntax on " 구문강조 사용
set autoindent " 자동 들여쓰기
set smartindent " 스마트한 들여쓰기
set cindent " C 프로그래밍용 자동 들여쓰기
set shiftwidth=4 " 자동 들여쓰기 4칸
set tabstop=4 " 탭을 4칸으로
set nowrapscan " 검색할 때 문서의 끝에서 처음으로 안돌아감
set ignorecase " 검색시 대소문자 무시, set ic 도 가능
set hlsearch " 검색어 강조, set hls 도 가능
set number " 행번호 표시, set nu 도 가능
set nocompatible " 오리지날 VI와 호환하지 않음
set backspace=eol,start,indent " 줄의 끝, 시작, 들여쓰기에서 백스페이스시 이전줄로
set ruler " 화면 우측 하단에 현재 커서의 위치(줄,칸) 표시
"set cursorline " 편집 위치에 커서 라인 설정
set laststatus=2 " 상태바 표시를 항상한다
set incsearch " 키워드 입력시 점진적 검색
set fencs=ucs-bom,utf-8,euc-kr.latin1 " 한글 파일은 euc-kr로, 유니코드는 유니코드로
"set fileencoding=utf-8 " 파일저장인코딩
"set tenc=utf-8 " 터미널 인코딩
set background=dark " 하이라이팅 lihgt / dark
set history=1000 " vi 편집기록 기억갯수 .viminfo에 기록
set wrap
set noswapfile
set lbr
set visualbell " 키를 잘못눌렀을 때 화면 프레시
set mouse=a " vim에서 마우스 사용
set viminfo='20,<1000
set nuw=4 " 줄번호 표시 너비
set wmnu " tab completion
"괄호 매치
set showmatch
"검색 결과
set shortmess-=S
au Bufenter *\(c\|cpp\|h\|sc\|cc\|hpp\) set expandtab
augroup filetypedetect
au! BufRead,BufNewFile *.sc setfiletype c
augroup END
set laststatus=2
set statusline= " 상태 표시줄 초기화
set statusline+=%#DiffAdd#%{(mode()=='n')?'\ \ NORMAL\ ':''}
" 상태 표시줄에 현재 모드가 'NORMAL'인 경우 'NORMAL' 표시, 색상 그룹 DiffAdd 사용
set statusline+=%#DiffChange#%{(mode()=='i')?'\ \ INSERT\ ':''}
" 상태 표시줄에 현재 모드가 'INSERT'인 경우 'INSERT' 표시, 색상 그룹 DiffChange 사용
set statusline+=%#DiffDelete#%{(mode()=='r')?'\ \ REPLACE\ ':''}
" 상태 표시줄에 현재 모드가 'REPLACE'인 경우 'REPLACE' 표시, 색상 그룹 DiffDelete 사용
set statusline+=%#Cursor#%{(mode()=='v')?'\ \ VISUAL\ ':''}
" 상태 표시줄에 현재 모드가 'VISUAL'인 경우 'VISUAL' 표시, 색상 그룹 Cursor 사용
set statusline+=\ %n\ " 현재 버퍼 번호를 표시
set statusline+=%#Visual# " 상태 표시줄에 Visual 모드 색상 그룹 추가
set statusline+=%{&paste?'\ PASTE\ ':''} " PASTE 모드 활성화 시 'PASTE' 표시
set statusline+=%{&spell?'\ SPELL\ ':''} " SPELL 모드 활성화 시 'SPELL' 표시
set statusline+=%#CursorIM# " CursorIM 색상 그룹 추가
set statusline+=%R " 파일이 읽기 전용일 경우 '[RO]' 표시
set statusline+=%M " 파일이 수정된 경우 '[+] 표시
set statusline+=%#Cursor# " 상태 표시줄에 Cursor 색상 그룹 추가
set statusline+=%#CursorLine# " 상태 표시줄에 CursorLine 색상 그룹 추가
set statusline+=\ %t\ " 파일 이름 표시 (현재 버퍼의 이름)
set statusline+=%= " 상태 표시줄의 왼쪽과 오른쪽 섹션 분리
set statusline+=%#CursorLine# " 오른쪽 섹션에 CursorLine 색상 그룹 추가
set statusline+=[%{strlen(&ft)?&ft:'none'},
" 파일 형식(filetype)이 설정된 경우 해당 값 표시, 없으면 'none' 표시
set statusline+=%{strlen(&fenc)?&fenc:&enc},
" 파일 인코딩(file encoding) 정보 표시, 없으면 기본 인코딩 표시
set statusline+=%{&fileformat}] " 파일 포맷 (예: unix, dos, mac) 표시
set statusline+=%#CursorIM# " 상태 표시줄에 CursorIM 색상 그룹 추가
set statusline+=\ %3l:%-2c\ " 현재 행(:l)과 열(:c)을 표시 (3칸 폭, -2칸 폭)
set statusline+=%#Cursor# " 상태 표시줄에 Cursor 색상 그룹 추가
set statusline+=\ %3p%%\ " 파일에서 현재 위치를 퍼센트(%)로 표시
set statusline+=\ %L\ " 파일의 총 줄 수를 표시
" set statusline=%f\ %h%m%r\ %=search:\ %{exists('g:search_total')?g:search_current.'/'.g:search_total:'No search'}\ line:%l/%L
set statusline+= " 상태 표시줄 끝
function! ResetSearch()
" 하이라이팅 및 전역 검색 패턴 초기화
"set nohlsearch " 하이라이팅 비활성화
let @/ = "" " 검색 패턴 초기화
" Shift+F 검색 상태 초기화
if exists('g:sf_search_matches')
unlet g:sf_search_matches
endif
if exists('g:sf_search_total')
unlet g:sf_search_total
endif
if exists('g:sf_search_current')
unlet g:sf_search_current
endif
" Ctrl+F 검색 상태 초기화
if exists('g:search_matches')
unlet g:search_matches
endif
if exists('g:search_total')
unlet g:search_total
endif
if exists('g:search_current')
unlet g:search_current
endif
" 메시지 출력
echohl WarningMsg
echo "Search and highlighting reset"
echohl None
endfunction
" 검색 상태를 업데이트하는 함수
function! UpdateSearchCount(direction)
call ResetSearch() " 초기화 먼저 수행
let @/ = input("Enter search term: ")
if empty(@/)
echohl WarningMsg
echo "No search term entered."
echohl None
return
endif
let matches = []
let current_pos = getpos(".") " 현재 커서 위치 [버퍼 번호, 줄 번호, 열 번호, ...]
" 문서 전체에서 검색 결과 수집
for lnum in range(1, line('$'))
let line = getline(lnum)
let start = 0
while start >= 0
let match_pos = match(line, @/, start)
if match_pos == -1
break
endif
call add(matches, [lnum, match_pos + 1]) " [줄 번호, 열 번호]로 저장
let start = match_pos + 1
endwhile
endfor
let g:search_matches = matches
let g:search_total = len(matches)
if g:search_total == 0
echohl ErrorMsg
echo "No matches found."
echohl None
return
endif
" 현재 커서 위치에서 가장 가까운 검색 결과의 인덱스를 찾음
" let g:search_current = 1
" for index in range(0, g:search_total - 1)
" let match = g:search_matches[index]
" if match[0] > current_pos[1] || (match[0] == current_pos[1] && match[1] >= current_pos[2])
" let g:search_current = index + 1
" break
" endif
" endfor
" 현재 커서 위치 이전의 검색 결과로 시작
let g:search_current = g:search_total
for index in range(g:search_total - 1, -1, -1)
let match = g:search_matches[index]
if match[0] < current_pos[1] || (match[0] == current_pos[1] && match[1] < current_pos[2])
let g:search_current = index + 1
break
endif
endfor
set hlsearch
call MoveToSearchResult()
call ShowSearchStatus()
endfunction
" 검색 결과로 이동
function! MoveToSearchResult()
if !exists('g:search_matches') || empty(g:search_matches)
echohl ErrorMsg
echo "(No search results available)"
echohl None
return
endif
let pos = g:search_matches[g:search_current - 1]
call cursor(pos[0], pos[1]) " 줄 번호와 열 번호로 커서 이동
call ShowSearchStatus()
endfunction
" 검색 결과를 이동
function! MoveSearch(direction)
if !exists('g:search_matches') || empty(g:search_matches)
echohl ErrorMsg
echo "(No search results available)"
echohl None
return
endif
let g:search_current += a:direction
if g:search_current < 1
let g:search_current = g:search_total " 순환 이동
elseif g:search_current > g:search_total
let g:search_current = 1 " 순환 이동
endif
" 검색 위치로 커서를 이동
call MoveToSearchResult()
" 항상 상태 메시지 출력
redraw
call ShowSearchStatus()
endfunction
" 검색 상태 출력
function! ShowSearchStatus()
echohl Search
echo "Search: " . g:search_current . " of " . g:search_total
echohl None
redraw
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Shift+F 전용 검색 상태 관리 함수
function! HighlightSearchSF()
call ResetSearch() " 초기화 먼저 수행
let current_word = expand('<cword>') " 현재 커서 아래 단어 가져옴
" 검색 패턴 설정
if empty(current_word)
echohl WarningMsg
echo "No word under cursor to search"
echohl None
return
endif
let matches = []
let current_pos = getpos(".") " 현재 커서 위치 [버퍼 번호, 줄 번호, 열 번호, ...]
" 문서 전체에서 검색 결과 수집
for lnum in range(1, line('$'))
let line = getline(lnum)
let start = 0
while start >= 0
let match_pos = match(line, current_word, start)
if match_pos == -1
break
endif
call add(matches, [lnum, match_pos + 1]) " [줄 번호, 열 번호] 저장
let start = match_pos + 1
endwhile
endfor
" 검색 결과를 전역 변수에 저장
let g:sf_search_matches = matches
let g:sf_search_total = len(matches)
if g:sf_search_total == 0
echohl ErrorMsg
echo "No matches found for: " . current_word
echohl None
return
endif
" 현재 커서 위치에서 가장 가까운 검색 결과의 인덱스를 찾음
" let g:sf_search_current = 1
" for index in range(0, g:sf_search_total - 1)
" let match = g:sf_search_matches[index]
" if match[0] > current_pos[1] || (match[0] == current_pos[1] && match[1] >= current_pos[2])
" let g:sf_search_current = index + 1
" break
" endif
" endfor
" 현재 커서 위치 이전의 검색 결과로 이동
let g:sf_search_current = g:sf_search_total
for index in range(g:sf_search_total - 1, 0, -1)
let match = g:sf_search_matches[index]
if match[0] < current_pos[1] || (match[0] == current_pos[1] && match[1] < current_pos[2])
let g:sf_search_current = index + 1
break
endif
endfor
" 하이라이팅 활성화 및 첫 결과로 이동
let @/ = current_word " 검색 패턴 설정
set hlsearch " 하이라이팅 활성화
call MoveToSFSearchResult()
endfunction
" 검색 결과로 이동
function! MoveToSFSearchResult()
if !exists('g:sf_search_matches') || empty(g:sf_search_matches)
echohl ErrorMsg
echo "(No search results available)"
echohl None
return
endif
let pos = g:sf_search_matches[g:sf_search_current - 1]
call cursor(pos[0], pos[1]) " 줄 번호와 열 번호로 커서 이동
" 화면 갱신 및 상태 메시지 출력
redraw
call ShowSFSearchStatus()
endfunction
" 검색 상태 메시지 출력
function! ShowSFSearchStatus()
echohl Search
echo "Shift+F Search: " . g:sf_search_current . " of " . g:sf_search_total
echohl None
redraw
endfunction
" 검색 결과를 이동
function! MoveSFSearch(direction)
if !exists('g:sf_search_matches') || empty(g:sf_search_matches)
echohl ErrorMsg
echo "(No search results available)"
echohl None
return
endif
let g:sf_search_current += a:direction
if g:sf_search_current < 1
let g:sf_search_current = g:sf_search_total " 순환 이동
elseif g:sf_search_current > g:sf_search_total
let g:sf_search_current = 1
endif
" 검색 위치로 이동
call MoveToSFSearchResult()
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 흰색에서 검은색까지 그라데이션 색상 정의
highlight LineNrWhite ctermfg=White guifg=#FFFFFF
highlight LineNrRed ctermfg=Red guifg=#FF0000
highlight LineNrYellow ctermfg=Yellow guifg=#FFFF00
highlight LineNrGray ctermfg=DarkGray guifg=#808080
highlight LineNrBlack ctermfg=Black guifg=#000000
" 특정 조건에 따라 색상 변경
autocmd CursorMoved,WinEnter,BufEnter * call SetGradientLineNrColor()
function! SetGradientLineNrColor()
let total_lines = line('$') " 전체 줄 수
let segment_size = max([1, float2nr(total_lines / 9)]) " 최소 1줄 이상
" 현재 줄 번호에 따라 색상 설정
let current_line = line('.')
let group_index = min([8, float2nr(current_line / segment_size)]) " 0~8 제한
if group_index == 0
execute "highlight! link LineNr LineNrWhite"
elseif group_index == 1
execute "highlight! link LineNr LineNrWhite"
elseif group_index == 2
execute "highlight! link LineNr LineNrRed"
elseif group_index == 3
execute "highlight! link LineNr LineNrRed"
elseif group_index == 4
execute "highlight! link LineNr LineNrYellow"
elseif group_index == 5
execute "highlight! link LineNr LineNrGray"
elseif group_index == 6
execute "highlight! link LineNr LineNrGray"
elseif group_index == 7
execute "highlight! link LineNr LineNrBlack"
else
execute "highlight! link LineNr LineNrBlack"
endif
endfunction
" 마우스 모드를 전환하는 함수
function ToggleMouse()
if &mouse == 'a'
set mouse=
echohl WarningMsg
echo 'Mouse mode OFF'
echohl None
else
if has('mouse_sgr')
set ttymouse=sgr
endif
set mouse=a
echohl MoreMsg
echo 'Mouse Mode ON'
echohl None
endif
endfunction
"
" 단축키
"
"줄 색상 변경
map <F7> :call SetGradientLineNrColor()<CR>
" Shift+F로 현재 단어 검색 시작
map <S-F> :call HighlightSearchSF()<CR>
" Shift+F 검색 결과 앞/뒤로 이동
map m :call MoveSFSearch(1)<CR>
map M :call MoveSFSearch(-1)<CR>
" 페이지 새로고침
map E :e!<cr>
" 페이지 저장없이 나가기
map Q :q!<cr>
"map <F2> :set number! number?<cr>
"잘못 쓴 입력 되돌리기
map <S-z> :undo<cr>
"map <F3> <C-w><C-v>
"map <F4> <C-w><C-w>
"map <F5> :NERDTreeToggle<cr>
"map <F6> :TlistToggle<cr>
" 마우스 모드 전환
map <F5> :call ToggleMouse()<cr>
" 검색 초기화
map <F8> :call ResetSearch()<CR>
" 검색 시작
map <C-F> :call UpdateSearchCount(1)<CR>
" 검색 결과 앞으로 이동 (n)
map n :call MoveSearch(1)<CR>
" 검색 결과 뒤로 이동 (N)
map N :call MoveSearch(-1)<CR>
function! ScrollSmooth(up)
let l:scroll_count = 5 " 스크롤할 줄 수
while l:scroll_count > 0
if a:up
execute "normal! \<C-y>"
else
execute "normal! \<C-e>"
endif
let l:scroll_count -= 1
endwhile
endfunction
" 위로 5줄 스크롤
map <F1> :call ScrollSmooth(1)<CR>
" 아래로 5줄 스크롤
map <F2> :call ScrollSmooth(0)<CR>
기본적으로 들어가는 기능들과
마우스 기능
일하면서 느낀 파일에서 찾기 기능의 중요성 등을 통해
시프트 에프와
컨트롤 에프로 찾기기능 사용할 수 있다.
마우스를 통해 커서 이동을 가능하게 했고
마우스 휠 스크롤로 줄이 이동이 안되서 f1 f2 로 이동시켰다.
줄번호는 커서 위치별 전체줄 퍼센테이지에 따라 색상을 다르게 해 가독성을 높였다.
" VIM 옵션 syntax on " 구문강조 사용 set autoindent " 자동 들여쓰기 set smartindent " 스마트한 들여쓰기 set cindent " C 프로그래밍용 자동 들여쓰기 set shiftwidth=4 " 자동 들여쓰기 4칸 set tabstop=4 " 탭을 4칸으로 set nowrapscan " 검색할 때 문서의 끝에서 처음으로 안돌아감 set ignorecase " 검색시 대소문자 무시, set ic 도 가능 set hlsearch " 검색어 강조, set hls 도 가능 set number " 행번호 표시, set nu 도 가능 set nocompatible " 오리지날 VI와 호환하지 않음 set backspace=eol,start,indent " 줄의 끝, 시작, 들여쓰기에서 백스페이스시 이전줄로 set ruler " 화면 우측 하단에 현재 커서의 위치(줄,칸) 표시 "set cursorline " 편집 위치에 커서 라인 설정 set laststatus=2 " 상태바 표시를 항상한다 set incsearch " 키워드 입력시 점진적 검색 set fencs=ucs-bom,utf-8,euc-kr.latin1 " 한글 파일은 euc-kr로, 유니코드는 유니코드로 "set fileencoding=utf-8 " 파일저장인코딩 "set tenc=utf-8 " 터미널 인코딩 set background=dark " 하이라이팅 lihgt / dark set history=1000 " vi 편집기록 기억갯수 .viminfo에 기록 set wrap set noswapfile set lbr set visualbell " 키를 잘못눌렀을 때 화면 프레시 set mouse=a " vim에서 마우스 사용 set viminfo='20,<1000 set nuw=4 " 줄번호 표시 너비 set wmnu " tab completion "괄호 매치 set showmatch "검색 결과 set shortmess-=S au Bufenter *\(c\|cpp\|h\|sc\|cc\|hpp\) set expandtab augroup filetypedetect au! BufRead,BufNewFile *.sc setfiletype c augroup END set laststatus=2 set statusline= " 상태 표시줄 초기화 set statusline+=%#DiffAdd#%{(mode()=='n')?'\ \ NORMAL\ ':''} " 상태 표시줄에 현재 모드가 'NORMAL'인 경우 'NORMAL' 표시, 색상 그룹 DiffAdd 사용 set statusline+=%#DiffChange#%{(mode()=='i')?'\ \ INSERT\ ':''} " 상태 표시줄에 현재 모드가 'INSERT'인 경우 'INSERT' 표시, 색상 그룹 DiffChange 사용 set statusline+=%#DiffDelete#%{(mode()=='r')?'\ \ REPLACE\ ':''} " 상태 표시줄에 현재 모드가 'REPLACE'인 경우 'REPLACE' 표시, 색상 그룹 DiffDelete 사용 set statusline+=%#Cursor#%{(mode()=='v')?'\ \ VISUAL\ ':''} " 상태 표시줄에 현재 모드가 'VISUAL'인 경우 'VISUAL' 표시, 색상 그룹 Cursor 사용 set statusline+=\ %n\ " 현재 버퍼 번호를 표시 set statusline+=%#Visual# " 상태 표시줄에 Visual 모드 색상 그룹 추가 set statusline+=%{&paste?'\ PASTE\ ':''} " PASTE 모드 활성화 시 'PASTE' 표시 set statusline+=%{&spell?'\ SPELL\ ':''} " SPELL 모드 활성화 시 'SPELL' 표시 set statusline+=%#CursorIM# " CursorIM 색상 그룹 추가 set statusline+=%R " 파일이 읽기 전용일 경우 '[RO]' 표시 set statusline+=%M " 파일이 수정된 경우 '[+] 표시 set statusline+=%#Cursor# " 상태 표시줄에 Cursor 색상 그룹 추가 set statusline+=%#CursorLine# " 상태 표시줄에 CursorLine 색상 그룹 추가 set statusline+=\ %t\ " 파일 이름 표시 (현재 버퍼의 이름) set statusline+=%= " 상태 표시줄의 왼쪽과 오른쪽 섹션 분리 set statusline+=%#CursorLine# " 오른쪽 섹션에 CursorLine 색상 그룹 추가 set statusline+=[%{strlen(&ft)?&ft:'none'}, " 파일 형식(filetype)이 설정된 경우 해당 값 표시, 없으면 'none' 표시 set statusline+=%{strlen(&fenc)?&fenc:&enc}, " 파일 인코딩(file encoding) 정보 표시, 없으면 기본 인코딩 표시 set statusline+=%{&fileformat}] " 파일 포맷 (예: unix, dos, mac) 표시 set statusline+=%#CursorIM# " 상태 표시줄에 CursorIM 색상 그룹 추가 set statusline+=\ %3l:%-2c\ " 현재 행(:l)과 열(:c)을 표시 (3칸 폭, -2칸 폭) set statusline+=%#Cursor# " 상태 표시줄에 Cursor 색상 그룹 추가 set statusline+=\ %3p%%\ " 파일에서 현재 위치를 퍼센트(%)로 표시 set statusline+=\ %L\ " 파일의 총 줄 수를 표시 " set statusline=%f\ %h%m%r\ %=search:\ %{exists('g:search_total')?g:search_current.'/'.g:search_total:'No search'}\ line:%l/%L set statusline+= " 상태 표시줄 끝 function! ResetSearch() " 하이라이팅 및 전역 검색 패턴 초기화 "set nohlsearch " 하이라이팅 비활성화 let @/ = "" " 검색 패턴 초기화 " Shift+F 검색 상태 초기화 if exists('g:sf_search_matches') unlet g:sf_search_matches endif if exists('g:sf_search_total') unlet g:sf_search_total endif if exists('g:sf_search_current') unlet g:sf_search_current endif " Ctrl+F 검색 상태 초기화 if exists('g:search_matches') unlet g:search_matches endif if exists('g:search_total') unlet g:search_total endif if exists('g:search_current') unlet g:search_current endif " 메시지 출력 echohl WarningMsg echo "Search and highlighting reset" echohl None endfunction " 검색 상태를 업데이트하는 함수 function! UpdateSearchCount(direction) call ResetSearch() " 초기화 먼저 수행 let @/ = input("Enter search term: ") if empty(@/) echohl WarningMsg echo "No search term entered." echohl None return endif let matches = [] let current_pos = getpos(".") " 현재 커서 위치 [버퍼 번호, 줄 번호, 열 번호, ...] " 문서 전체에서 검색 결과 수집 for lnum in range(1, line('$')) let line = getline(lnum) let start = 0 while start >= 0 let match_pos = match(line, @/, start) if match_pos == -1 break endif call add(matches, [lnum, match_pos + 1]) " [줄 번호, 열 번호]로 저장 let start = match_pos + 1 endwhile endfor let g:search_matches = matches let g:search_total = len(matches) if g:search_total == 0 echohl ErrorMsg echo "No matches found." echohl None return endif " 현재 커서 위치에서 가장 가까운 검색 결과의 인덱스를 찾음 " let g:search_current = 1 " for index in range(0, g:search_total - 1) " let match = g:search_matches[index] " if match[0] > current_pos[1] || (match[0] == current_pos[1] && match[1] >= current_pos[2]) " let g:search_current = index + 1 " break " endif " endfor " 현재 커서 위치 이전의 검색 결과로 시작 let g:search_current = g:search_total for index in range(g:search_total - 1, -1, -1) let match = g:search_matches[index] if match[0] < current_pos[1] || (match[0] == current_pos[1] && match[1] < current_pos[2]) let g:search_current = index + 1 break endif endfor set hlsearch call MoveToSearchResult() call ShowSearchStatus() endfunction " 검색 결과로 이동 function! MoveToSearchResult() if !exists('g:search_matches') || empty(g:search_matches) echohl ErrorMsg echo "(No search results available)" echohl None return endif let pos = g:search_matches[g:search_current - 1] call cursor(pos[0], pos[1]) " 줄 번호와 열 번호로 커서 이동 call ShowSearchStatus() endfunction " 검색 결과를 이동 function! MoveSearch(direction) if !exists('g:search_matches') || empty(g:search_matches) echohl ErrorMsg echo "(No search results available)" echohl None return endif let g:search_current += a:direction if g:search_current < 1 let g:search_current = g:search_total " 순환 이동 elseif g:search_current > g:search_total let g:search_current = 1 " 순환 이동 endif " 검색 위치로 커서를 이동 call MoveToSearchResult() " 항상 상태 메시지 출력 redraw call ShowSearchStatus() endfunction " 검색 상태 출력 function! ShowSearchStatus() echohl Search echo "Search: " . g:search_current . " of " . g:search_total echohl None redraw endfunction """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Shift+F 전용 검색 상태 관리 함수 function! HighlightSearchSF() call ResetSearch() " 초기화 먼저 수행 let current_word = expand('<cword>') " 현재 커서 아래 단어 가져옴 " 검색 패턴 설정 if empty(current_word) echohl WarningMsg echo "No word under cursor to search" echohl None return endif let matches = [] let current_pos = getpos(".") " 현재 커서 위치 [버퍼 번호, 줄 번호, 열 번호, ...] " 문서 전체에서 검색 결과 수집 for lnum in range(1, line('$')) let line = getline(lnum) let start = 0 while start >= 0 let match_pos = match(line, current_word, start) if match_pos == -1 break endif call add(matches, [lnum, match_pos + 1]) " [줄 번호, 열 번호] 저장 let start = match_pos + 1 endwhile endfor " 검색 결과를 전역 변수에 저장 let g:sf_search_matches = matches let g:sf_search_total = len(matches) if g:sf_search_total == 0 echohl ErrorMsg echo "No matches found for: " . current_word echohl None return endif " 현재 커서 위치에서 가장 가까운 검색 결과의 인덱스를 찾음 " let g:sf_search_current = 1 " for index in range(0, g:sf_search_total - 1) " let match = g:sf_search_matches[index] " if match[0] > current_pos[1] || (match[0] == current_pos[1] && match[1] >= current_pos[2]) " let g:sf_search_current = index + 1 " break " endif " endfor " 현재 커서 위치 이전의 검색 결과로 이동 let g:sf_search_current = g:sf_search_total for index in range(g:sf_search_total - 1, 0, -1) let match = g:sf_search_matches[index] if match[0] < current_pos[1] || (match[0] == current_pos[1] && match[1] < current_pos[2]) let g:sf_search_current = index + 1 break endif endfor " 하이라이팅 활성화 및 첫 결과로 이동 let @/ = current_word " 검색 패턴 설정 set hlsearch " 하이라이팅 활성화 call MoveToSFSearchResult() endfunction " 검색 결과로 이동 function! MoveToSFSearchResult() if !exists('g:sf_search_matches') || empty(g:sf_search_matches) echohl ErrorMsg echo "(No search results available)" echohl None return endif let pos = g:sf_search_matches[g:sf_search_current - 1] call cursor(pos[0], pos[1]) " 줄 번호와 열 번호로 커서 이동 " 화면 갱신 및 상태 메시지 출력 redraw call ShowSFSearchStatus() endfunction " 검색 상태 메시지 출력 function! ShowSFSearchStatus() echohl Search echo "Shift+F Search: " . g:sf_search_current . " of " . g:sf_search_total echohl None redraw endfunction " 검색 결과를 이동 function! MoveSFSearch(direction) if !exists('g:sf_search_matches') || empty(g:sf_search_matches) echohl ErrorMsg echo "(No search results available)" echohl None return endif let g:sf_search_current += a:direction if g:sf_search_current < 1 let g:sf_search_current = g:sf_search_total " 순환 이동 elseif g:sf_search_current > g:sf_search_total let g:sf_search_current = 1 endif " 검색 위치로 이동 call MoveToSFSearchResult() endfunction """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 흰색에서 검은색까지 그라데이션 색상 정의 highlight LineNrWhite ctermfg=White guifg=#FFFFFF highlight LineNrRed ctermfg=Red guifg=#FF0000 highlight LineNrYellow ctermfg=Yellow guifg=#FFFF00 highlight LineNrGray ctermfg=DarkGray guifg=#808080 highlight LineNrBlack ctermfg=Black guifg=#000000 " 특정 조건에 따라 색상 변경 autocmd CursorMoved,WinEnter,BufEnter * call SetGradientLineNrColor() function! SetGradientLineNrColor() let total_lines = line('$') " 전체 줄 수 let segment_size = max([1, float2nr(total_lines / 9)]) " 최소 1줄 이상 " 현재 줄 번호에 따라 색상 설정 let current_line = line('.') let group_index = min([8, float2nr(current_line / segment_size)]) " 0~8 제한 if group_index == 0 execute "highlight! link LineNr LineNrWhite" elseif group_index == 1 execute "highlight! link LineNr LineNrWhite" elseif group_index == 2 execute "highlight! link LineNr LineNrRed" elseif group_index == 3 execute "highlight! link LineNr LineNrRed" elseif group_index == 4 execute "highlight! link LineNr LineNrYellow" elseif group_index == 5 execute "highlight! link LineNr LineNrGray" elseif group_index == 6 execute "highlight! link LineNr LineNrGray" elseif group_index == 7 execute "highlight! link LineNr LineNrBlack" else execute "highlight! link LineNr LineNrBlack" endif endfunction " 마우스 모드를 전환하는 함수 function ToggleMouse() if &mouse == 'a' set mouse= echohl WarningMsg echo 'Mouse mode OFF' echohl None else if has('mouse_sgr') set ttymouse=sgr endif set mouse=a echohl MoreMsg echo 'Mouse Mode ON' echohl None endif endfunction " " 단축키 " "줄 색상 변경 map <F7> :call SetGradientLineNrColor()<CR> " Shift+F로 현재 단어 검색 시작 map <S-F> :call HighlightSearchSF()<CR> " Shift+F 검색 결과 앞/뒤로 이동 map m :call MoveSFSearch(1)<CR> map M :call MoveSFSearch(-1)<CR> " 페이지 새로고침 map E :e!<cr> " 페이지 저장없이 나가기 map Q :q!<cr> "map <F2> :set number! number?<cr> "잘못 쓴 입력 되돌리기 map <S-z> :undo<cr> "map <F3> <C-w><C-v> "map <F4> <C-w><C-w> "map <F5> :NERDTreeToggle<cr> "map <F6> :TlistToggle<cr> " 마우스 모드 전환 map <F5> :call ToggleMouse()<cr> " 검색 초기화 map <F8> :call ResetSearch()<CR> " 검색 시작 map <C-F> :call UpdateSearchCount(1)<CR> " 검색 결과 앞으로 이동 (n) map n :call MoveSearch(1)<CR> " 검색 결과 뒤로 이동 (N) map N :call MoveSearch(-1)<CR> function! ScrollSmooth(up) let l:scroll_count = 5 " 스크롤할 줄 수 while l:scroll_count > 0 if a:up execute "normal! \<C-y>" else execute "normal! \<C-e>" endif let l:scroll_count -= 1 endwhile endfunction " 위로 5줄 스크롤 map <F1> :call ScrollSmooth(1)<CR> " 아래로 5줄 스크롤 map <F2> :call ScrollSmooth(0)<CR>