
less
표시된 모든 페이지에서 프로그램이 첫 번째 행(또는 처음 두 행)을 반복하도록 하는 방법이 있습니까 ?
이 작업을 수행할 수 있는 다른 호출기가 있습니까?
이것은 데이터베이스 테이블 탐색을 위한 킬러 앱이 될 것 mysql
입니다 psql
.gqlplus
하단 스크린샷 참조이 페이지. 머리글 행 + 가로 ASCII 열을 반복하고 싶습니다.
답변1
Vim을 사용하는 솔루션이 있습니다.
먼저 대부분의 작업을 수행하는 Vim 매크로가 필요합니다. 다음 위치에 저장하세요 ~/.vim/plugin/less.vim
.
" :Less
" turn vim into a pager for psql aligned results
fun! Less()
set nocompatible
set nowrap
set scrollopt=hor
set scrollbind
set number
execute 'above split'
" resize upper window to one line; two lines are not needed because vim adds separating line
execute 'resize 1'
" switch to lower window and scroll 2 lines down
wincmd j
execute 'norm! 2^E'
" hide statusline in lower window
set laststatus=0
" hide contents of upper statusline. editor note: do not remove trailing spaces in next line!
set statusline=\
" arrows do scrolling instead of moving
nmap ^[OC zL
nmap ^[OB ^E
nmap ^[OD zH
nmap ^[OA ^Y
nmap <Space> <PageDown>
" faster quit (I tend to forget about the upper panel)
nmap q :qa^M
nmap Q :qa^M
endfun
command! -nargs=0 Less call Less()
둘째, 호출기를 시뮬레이션하려면 vim을 호출하여 다음을 수행해야 합니다.
- 표준 입력 읽기
- 그러나 명령줄에 인수가 제공되면 거기에서 무엇이든 읽으십시오.
- 읽기 전용 모드로 작업
- 모든 초기화 스크립트를 건너뛰고 대신 위에 정의된 Less 매크로를 실행하세요.
나는 이것을 도우미 스크립트로 정리했습니다 ~/bin/vimpager
.
#!/bin/bash
what=-
test "$@" && what="$@"
exec vim -u NONE -R -S ~/.vim/plugin/less.vim -c Less $what
스크립트를 실행 가능하게 만드는 데 사용됩니다 chmod +x ~/bin/vimpager
.
셋째, psql의 호출기를 다시 작성해야 합니다. PAGER
psql뿐만 아니라 다른 프로그램에도 영향을 미치므로 전역적으로 변수를 설정 하지 마십시오 . 대신 다음을 파일에 추가하세요 ~/.psqlrc
.
\setenv PAGER ~/bin/vimpager
바라보다! 프로필을 다시 로드하면 아래와 같이 예상대로 작동하는 결과를 즐길 수 있습니다(세로 및 가로 탐색용 화살표 키).. 게다가 필요할 경우 Vim의 모든 기능을 사용할 수 있습니다.
답변2
시도해 봤어?SQL 모드Emacs/XEmacs에서?
more
or만큼 사용하기가 쉽지 는 않지만 less
결과를 수직 및 수평으로 스크롤할 때 머리글 행을 남겨두어야 한다는 요구 사항을 충족합니다.
답변3
이것은 다음에서 크게 빌린 것입니다.수락된 답변,그런데 추가된...
- 더 빠르게 스크롤
- 실수로 제목을 스크롤하는 일이 없습니다.
- 구문 강조(일부 크레딧여기에 속해)
- 양수/음수, 날짜, 시간,
NULL
참/거짓(그리고 T/F, Y/N, 예/아니요) - 줄 번호(파이프 문자 앞에 줄 번호가 있는 경우)
- 양수/음수, 날짜, 시간,
- 도움말 텍스트
- 포함된 Vim 지원윈도우용 힘내
- 표준 입력 버퍼가 변경되면 뷰를 업데이트하겠다고 위협하지 마세요.
를 사용하지 않기 때문에 특정 출력에 맞게 일부 부분을 조정해야 할 수도 있습니다 psql
. 내 목적에 따라 도우미 기능도 약간 다르지만 다음과 같습니다.답변이 수락되었습니다.
입력 샘플
| ID | First | Last | Member | Balance |
--+----+-----------+--------------+--------+---------+
1| 4 | Tom | Hanks | False | 0.00 |
2| 12 | Susan | Patterson | True | 10.00 |
3| 23 | Harriet | Langford-Wat | False | 0.00 |
4| 8 | Jerry | NULL | True | -382.94 |
[… More rows …]
10| 87 | Horace | Weaver | False | 47.52 |
암호
" :HeadPager
" Turn vim into a pager with a header row
" Adapted from https://unix.stackexchange.com/a/27840/143088
fun! HeadPager()
" If you didn't get three lines, shortcut out
if line('$') < 3
set nocompatible
nmap <silent> q :qa!<c-M>
nmap <silent> Q :qa!<c-M>
return
endif
set noswapfile
set nocompatible
set nowrap
set scrollopt=hor
set scrollbind
" Hide statusline in lower window
set laststatus=0
" Explain mapped chars in status line.
set statusline=\ \ \ Q\ to\ quit\.\ Arrows\ or\ mousewheel\ to\ scroll\.\ \(Vim\ commands\ work\,\ too\.\)
" Delete/copy header lines
silent execute '1,2d'
" Split screen with new buffer (opens at top)
execute 'new'
" Switch to upper split
wincmd k
" Paste the header over the blank line
execute 'norm! Vp'
" Header highlighting
syn match Pipe "|"
hi def Pipe ctermfg=blue
syn match Any /[^|]\+/
hi def Any ctermfg=yellow
" Switch back to lower split for scrolling
wincmd j
" Set lower split height to maximum
execute "norm! \<c-W>_"
" Syntax highlighting
syn cluster CellContents contains=None
syn match Pipe "|" contained nextgroup=@CellContents skipwhite
hi def Pipe ctermfg=blue
" Start with newline or |. End right before next | or EOL
syn region Cell start=/\v(^|\|)\s*/ end=/\v(\||$)\@=/ contains=LineNumber,Pipe
syn match NumPos /\v\+?\d+(,?\d{3})*\.?\d*\ze *(\||$)\@=/ contained
syn match NumNeg /\v-\d+(,?\d{3})*\.?\d*\ze *(\||$)\@=/ contained
syn match NumZero /\v[+-]?0+\.?0*\ze *(\||$)\@=/ contained
hi def NumPos ctermfg=cyan
hi def NumNeg ctermfg=red
hi def NumZero ctermfg=NONE
syn cluster CellContents add=NumPos,NumNeg,NumZero
syn match DateVal /\v\d{4}-\d{2}-\d{2}/ contained nextgroup=TimeVal skipwhite
syn match TimeVal /\v\d{1,2}:\d{2}(:\d{2})?(\.\d+)?(Z| ?\c[AP]M)?\ze *(\||$)\@=/ contained
hi def DateVal ctermfg=magenta
hi def TimeVal ctermfg=magenta
syn cluster CellContents add=DateVal,TimeVal
syn match TrueVal /\v\c(t(rue)?|y(es)?)\ze *(\||$)\@=/ contained
syn match FalseVal /\v\c(f(alse)?|no?)\ze *(\||$)\@=/ contained
hi def TrueVal ctermfg=green
hi def FalseVal ctermfg=red
syn match NullVal /\v\cnull?\ze *(\||$)\@=/ contained
hi def NullVal ctermbg=gray ctermfg=black
syn cluster CellContents add=TrueVal,FalseVal,NullVal
syn match LineNumber /^ *\d\+/ contained
hi def LineNumber ctermfg=yellow
" Arrows do scrolling instead of moving
nmap <silent> <Up> 3<c-Y>
nmap <silent> <Down> 3<c-E>
nmap <silent> <Left> zH
nmap <silent> <Right> zL
nmap <Space> <PageDown>
" Faster quit (I tend to forget about the upper panel)
nmap <silent> q :qa!<c-M>
nmap <silent> Q :qa!<c-M>
" Ignore external updates to the buffer
autocmd! FileChangedShell */fd/*
autocmd! FileChangedRO */fd/*
endfun
command! -nargs=0 HeadPager call HeadPager()
답변4
"앞으로" 앞에 숫자를 추가하면 전체 길이 대신 N 줄이 스크롤됩니다. 따라서 터미널 창에 40줄이 있는 경우 38f
start를 입력하면 마지막 "페이지"의 마지막 2줄만 남기고 38줄만 스크롤됩니다. 맨페이지에서:
SPACE or ^V or f or ^F
Scroll forward N lines, default one window (see option -z
below). If N is more than the screen size, only the final
screenful is displayed. Warning: some systems use ^V as a spe‐
cial literalization character.
z Like SPACE, but if N is specified, it becomes the new window
size.
b or ^B or ESC-v
Scroll backward N lines, default one window (see option -z
below). If N is more than the screen size, only the final
screenful is displayed.