터미널에서 빔에 Cmd
키를 사용하는 방법이 있습니까? MacVim이하는 일.콘솔 Vim에서 CMD 매핑을 사용하십시오
iTerm2에서 Cmd+S
을 다시 매핑하여 Esc:w!<CR>
을 보내서 Vim에 파일을 저장했지만 조금 약한 것으로 들립니다.
iTerm 및 Vim의 모든 기능을 사용하여이 작업을 수행 할 수있는 방법이 있습니까?
터미널에서 빔에 Cmd
키를 사용하는 방법이 있습니까? MacVim이하는 일.콘솔 Vim에서 CMD 매핑을 사용하십시오
iTerm2에서 Cmd+S
을 다시 매핑하여 Esc:w!<CR>
을 보내서 Vim에 파일을 저장했지만 조금 약한 것으로 들립니다.
iTerm 및 Vim의 모든 기능을 사용하여이 작업을 수행 할 수있는 방법이 있습니까?
가능하지만 약간의 작업이 필요하며 몇 가지 단점이 있습니다.
문제의 첫 번째 세트는 점이다
나머지 문제는 Vim이 Mac과 같은 키 바인딩으로 상자 밖으로 구성되어 있지 않다는 것입니다. 다행히 MacVim은 인터페이스 빌더 또는 Objective-C 소스에서 코딩하지 않고 /Applications/MacVim.app/Contents/Resources/vim/runtime/macmap.vim에 대부분의 Mac 스타일 GUI 바인딩을 포함합니다. 그래서 나는 그것들을 복사해서 터미널에 적용 할 수있었습니다. 여기 MacVim (다른 맥 애플 리케이션)에 매우 밀접하게 작동하는 설정입니다 :
" Keybindings for terminal vim; mostly to emulate MacVim (somewhat)
" See /Applications/MacVim.app/Contents/Resources/vim/runtime/macmap.vim (from
" which many of the following are taken); and menu.vim in the same directory.
" Since these all have native (Cmd-modified) versions in MacVim, don't bother
" defining them there.
" A utility function to help cover our bases when mapping.
"
" Example of use:
" call NvicoMapMeta('n', ':new<CR>', 1)
" is equivalent to:
" exec "set <M-n>=\<Esc>n"
" nnoremap <special> <Esc>n :new<CR>
" vnoremap <special> <Esc>n <Esc><Esc>ngv
" inoremap <special> <Esc>n <C-o><Esc>n
" cnoremap <special> <Esc>n <C-c><Esc>n
" onoremap <special> <Esc>n <Esc><Esc>n
function! NvicoMapMeta(key, cmd, add_gv)
" TODO: Make this detect whether key is something that has a Meta
" equivalent.
let l:keycode = "<M-" . a:key . ">"
let l:set_line = "set " . l:keycode . "=\<Esc>" . a:key
let l:nmap_line = 'nmap <silent> <special> ' . l:keycode . ' ' . a:cmd
let l:vnoremap_line = 'vnoremap <silent> <special> ' . l:keycode . ' <Esc>' . l:keycode
if(a:add_gv)
let l:vnoremap_line.='gv'
endif
let l:inoremap_line = 'inoremap <silent> <special> ' . l:keycode . ' <C-o>' . l:keycode
let l:cnoremap_line = 'cnoremap <special> ' . l:keycode . ' <C-c>' . l:keycode
let l:onoremap_line = 'onoremap <silent> <special> ' . l:keycode . ' <Esc>' . l:keycode
exec l:set_line
exec l:nmap_line
exec l:vnoremap_line
exec l:inoremap_line
exec l:cnoremap_line
exec l:onoremap_line
endfunction
" I can't think of a good function to assign to Meta+n, since in MacVim Cmd+N
" opens a whole new editing session.
" Meta+Shift+N
" No equivalent to this in standard MacVim. Here " it just opens a window on a
" new buffer.
call NvicoMapMeta('N', ':new<CR>', 1)
" Meta+o
" Open netrw file browser
call NvicoMapMeta('o', ':split %:p:h<CR>', 1)
" Meta+w
" Close window
call NvicoMapMeta('w', ':confirm close<CR>', 1)
" Meta+s
" Save buffer
call NvicoMapMeta('s', ':confirm w<CR>', 1)
" Meta+Shift+S
" Save as
" TODO: This is silent, so you can't tell it's waiting for input. If anyone can
" fix this, please do!
call NvicoMapMeta('S', ':confirm saveas ', 1)
" Meta+z
" Undo
call NvicoMapMeta('z', 'u', 1)
" Meta+Shift+Z
" Redo
call NvicoMapMeta('Z', '<C-r>', 1)
" Meta+x
" Cut to system clipboard (requires register +")
exec "set <M-x>=\<Esc>x"
vnoremap <special> <M-x> "+x
" Meta+c
" Copy to system clipboard (requires register +")
exec "set <M-c>=\<Esc>c"
vnoremap <special> <M-c> "+y
" Meta+v
" Paste from system clipboard (requires register +")
exec "set <M-v>=\<Esc>v"
nnoremap <silent> <special> <M-v> "+gP
cnoremap <special> <M-v> <C-r>+
execute 'vnoremap <silent> <script> <special> <M-v>' paste#paste_cmd['v']
execute 'inoremap <silent> <script> <special> <M-v>' paste#paste_cmd['i']
" Meta+a
" Select all
call NvicoMapMeta('a', ':if &slm != ""<Bar>exe ":norm gggH<C-o>G"<Bar> else<Bar>exe ":norm ggVG"<Bar>endif<CR>', 0)
" Meta+f
" Find regexp. NOTE: MacVim's Cmd+f does a non-regexp search.
call NvicoMapMeta('f', '/', 0)
" Meta+g
" Find again
call NvicoMapMeta('g', 'n', 0)
" Meta+Shift+G
" Find again, reverse direction
call NvicoMapMeta('G', 'N', 0)
" Meta+q
" Quit Vim
" Not quite identical to MacVim default (which is actually coded in the app
" itself rather than in macmap.vim)
call NvicoMapMeta('q', ':confirm qa<CR>', 0)
" Meta+Shift+{
" Switch tab left
call NvicoMapMeta('{', ':tabN<CR>', 0)
" Meta+Shift+}
" Switch tab right
call NvicoMapMeta('}', ':tabn<CR>', 0)
" Meta+t
" Create new tab
call NvicoMapMeta('t', ':tabnew<CR>', 0)
" Meta+Shift+T
" Open netrw file browser in new tab
call NvicoMapMeta('T', ':tab split %:p:h<CR>', 0)
" Meta+b
" Call :make
call NvicoMapMeta('b', ':make<CR>', 1)
" Meta+l
" Open error list
call NvicoMapMeta('l', ':cl<CR>', 1)
" TODO: We need to configure iTerm2 to be able to send Cmd+Ctrl+arrow keys, so
" we can duplicate the :cnext/:cprevious/:colder/:cnewer bindings to those keys
" in MacVim.
" There may be a few others I've missed, too.
NvicoMakeMeta
함수는 지정된 행동에에 전달 된 키의 메타 키 수정 된 버전을지도; 여기에서 "메타 키"는 명령에 대한 일반적인 용어이거나 옵션- 수정 된 것입니다. 이름에있는 "Nvico"는 일반, 시각적, 삽입, 명령 및 운영자 보류 모드에서 매핑한다는 사실을 나타냅니다.
ESC
문자 (모든 메타 키 시퀀스와 화살표 키 등의 시작 부분)를 해석 할 때 Vim이 작동하는 방식 때문에 ESC
의 시퀀스와 다른 문자를 매핑하면 간단히 끝납니다. Esc 키 누르기 (예 : 정상 모드로 돌아가고 싶다는 신호를 보내기)를받은 후 Vim으로 상당한 시간을 기다려야합니다.내 기능이이를 피하는 방법은 :set
을 사용하여 키 코드를 설정하는 것입니다 (:help :set-termcap
참조).
여기에 당신이해야 할 무엇, 요약합니다.
iTerm
메뉴>Preferences…
)로 이동하십시오. Keys
탭으로 이동하십시오. 수정 자로 사용할 키를 다시 매핑하여 왼쪽 옵션 또는 오른쪽 옵션을 전송합니다. iTerm2가 컴퓨터를 제어 할 수 있도록 조언을 따르십시오. 그것은 당신이 할 수있는 올바른 환경 설정 창을 열어야합니다. 자물쇠를 클릭하고 암호를 입력해야 iTerm 옆에있는 상자를 선택할 수 있습니다.Profiles
탭에서 응용 프로그램 전체 Preferences
대화 상자를 열어 예) 사용 +Esc
이 Right option key acts as
을 Left option key acts as
옆에 확인 (및/또는되었는지 확인하고 싶습니다 메타 키를 만들 었는지 여부 오른쪽 옵션)을 보내십시오.나는 단지 macmap.vim 파일이 실제로 MacVim뿐만 아니라 기본 Vim 배포본의 일부라는 점을 추가 할 것이라고 생각했다. 그러나 이것은 cmd-key 매핑을 위해 '
아니요, Command 키는 MacVim의 GUI에서만 볼 수 있습니다. 매핑을 위해 사용하는 것을 절대적으로 주장한다면 (그렇게해서는 안됨) iTerm을 통해 맵핑하는 것이 유일한 해결책입니다. – romainl
그리고'macmeta'는 Command 키와 아무 관련이 없습니다. – romainl
죄송합니다. GUI Vim을 사용하지 않고 관련이 있다고 생각합니다. 어쨌든 설명해 주셔서 감사합니다. – firedev