Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Vim中使用哪些自定义密钥绑定?_Vim - Fatal编程技术网

在Vim中使用哪些自定义密钥绑定?

在Vim中使用哪些自定义密钥绑定?,vim,Vim,您使用哪些自定义密钥绑定来提高Vim的生产效率 我的两个最爱是: inoremap jj <Esc> " Clear screen clears search highlighting. nnoremap <C-L> :nohl<CR><C-L> inoremap jj “清除屏幕将清除搜索突出显示。 nnoremap:nohl 以下命令将在命令模式下重新映射到;到:,从而避免在键入类似:wq的命令时按住和松开Shift键浪费宝贵的毫

您使用哪些自定义密钥绑定来提高Vim的生产效率

我的两个最爱是:

inoremap jj <Esc>

" Clear screen clears search highlighting.
nnoremap <C-L> :nohl<CR><C-L>
inoremap jj
“清除屏幕将清除搜索突出显示。
nnoremap:nohl

以下命令将在命令模式下重新映射到
,从而避免在键入类似
:wq
的命令时按住和松开Shift键浪费宝贵的毫秒:

" Remap ";" to ":"
map ; :
noremap ;; ;
如果您需要键入实际的
,只需按两次即可。

让mapleader=“,”
let mapleader=","

" omnicompletion : words
inoremap <leader>, <C-x><C-o>

" omnicompletion : filepaths
inoremap <leader>: <C-x><C-f>

" omnicompletion : lines
inoremap <leader>= <C-x><C-l>

" toggle TagList
nnoremap <leader>l :TlistToggle<CR>

" toggle NERDTree
nnoremap <leader>n :NERDTreeToggle<CR>

" I like vertically aligned assignation operators
nnoremap <leader>a :Tabularize<Space>

" with | marking the cursor
" it turns this 
" function foo(){|}
" into this
" function foo(){
"   |
" }
inoremap <C-Return> <CR><CR><C-o>k<Tab>

" push the current ligne up and down
nnoremap <M-D-Up>   ddKp
nnoremap <M-D-Down> ddP  

" swap word under the cursor with previous word on the left
" from the Vim wiki
nnoremap <M-D-Left>  "_yiw?\w\+\_W\+\%#<CR>:s/\(\%#\w\+\)\(\_W\+\)\(\w\+\)/\3\2\1/<CR><C-o><C-l>

" swap word under the cursor with next word on the right
" from the Vim wiki
nnoremap <M-D-Right> "_yiw:s/\(\%#\w\+\)\(\_W\+\)\(\w\+\)/\3\2\1/<CR><C-o>/\w\+\_W\+<CR><C-l>

" and I have lusty-explorers "modes" mapped to:
" "files"   <leader>f
" "buffers" <leader>b
" "grep"    <leader>g
“全面完成:文字 重新映射, “omnicompletion:文件路径 inoremap: “全方位完成:线条 inoremap= “切换标记列表 nnoremap l:TlistToggle “切换NERDTree nnoremap n:nerdtreethoggle “我喜欢垂直对齐的赋值运算符 nnoremap a:制表 “用|标记光标 “它把这个 “函数foo(){124;}” “到这里来 “函数foo(){ " | " } 伊诺雷马克 “向上和向下推动当前线路 nnoremap-ddKp nnoremap ddP “将光标下的单词与左边的上一个单词交换 “从Vim wiki nnoremap“\u yiw?\w\\\\\\\\\\\\\\%\\\\:s/\(\%\\\\\w\\\\\)(\\\\\\\\\\\\\(\w\\+\)/\3\2\1/ “将光标下的单词与右侧的下一个单词交换 “从Vim wiki nnoremap“\u-yiw:s/\(\%\w\+\)\(\u-w\+\)\(\w\+\)/\3\2\1/\w\+\u-w\+ “我将lusty探险家的“模式”映射到: “文件”f “缓冲区”b 格雷普
将光标下的单词标记为Grep

使用以下grepprg选项,它将递归搜索到当前目录中,不包括某些特定文件

" Quick Grep
noremap <Leader>g :grep<space><C-r><C-w><CR>:copen<CR><CR><C-W>b

set grepprg=grep\ -nH
\\--include='*.c'
\\--include='*.cpp'
\\--include='*.h'
\\--exclude-dir='.svn'
\\--exclude='*.svn-base'
\\--exclude-dir='OBJ'
\\--exclude='symTbl.c'
\\ $*
\\ -R\ .
“快速Grep
noremap g:grep:copenb
设置grepprg=grep \-nH
\\--include='*.c'
\\--include='*.cpp'
\\--include='*.h'
\\--排除目录='.svn'
\\--排除='*.svn base'
\\--排除dir='OBJ'
\\--排除class='symTbl.c'
\\ $*
\\-R\。
它将光标下的单词变灰,然后打开Quickfix窗口并将光标移动到bottow窗口(这应该是grep结果列表)

这可能是我最常用的快捷方式之一,而且它节省了大量的打字

在窗口之间快速移动

noremap <C-j> <C-W>j
noremap <C-k> <C-W>k
noremap <C-h> <C-W>h
noremap <C-l> <C-W>l
noremap j
诺雷马克
诺雷马克h
诺雷马克

当屏幕水平和垂直分割时,移动起来非常直观和方便。

用于在屏幕上向上/向下导航环绕到多行的长行:Alt+↑ 或↓ 箭头键在屏幕行而不是文件行中移动

map <A-Down> gj
map <A-Up> gk
imap <A-Up> <ESC>gki
imap <A-Down> <ESC>gji
map-gj
地图gk
imap gki
imap gji
窗口管理
“窗口拆分”
nmap sh:左上方的vnew
nmap sl:在vnew的正下方
nmap sk:leftovernew
nmap sj:新的右下方
nmap swh:左上角vnew
nmap swl:botright vnew
nmap swk:左上角新建
nmap swj:botright新建
“滚动当前窗口旁边的窗口
“(特别适用于两个窗口拆分)
nmap j wW
nmap k wW
文本编辑
“切换搜索突出显示
nmap/:设置hlsearch!
“切换粘贴模式
“(与“粘贴切换”相比,更喜欢此选项,以响应当前状态)
nmap:设置本地粘贴!粘贴
“选择上次编辑(或粘贴)的文本
nmap gv`[v`]
“保留包含(或不包含)最后一个搜索词的行
nmap v//:v///dgg
nmap g//:g///dgg
“电子邮件(de-)报价
nmap q vip:s/^/>/
vmap q:s/^/>/
nmap Q vip:s/^>//
vmap Q:s/^>//
文件打开和保存
“保存和恢复会话
nmap ss:wa:mksession$HOME/.vim/sessions/
nmap-rs:wa:source$HOME/.vim/sessions/
“通过sudo写入缓冲区
cnoreabrevw!!w!sudo tee%>/dev/null
“将当前目录更改为缓冲区中文件的目录
nmap cd:cd%:p:h:pwd
“打开与当前文件位于同一目录中的文件
nmap e:e=展开('%:p:h')。/'

插入模式

" <esc> in normal mode clears highlight
nnoremap <silent> <esc> :noh<cr><esc>
“在正常模式下清除突出显示
nnoremap:noh
命令行编辑

" copy an entire word from the line above instead of just one
inoremap <expr> <c-y> matchstr(getline(line('.')-1), '\%' . 
\ virtcol('.') . 'v\%(\k\+\\|.\)')

" Insert Directory of current buffer and open completion
cnoremap <expr> <c-k> getcmdline()[getcmdpos()-2] == " " ? 
\ expand("%:h") .  "/\<c-d>" : "\<c-d>"
“从上一行复制整个单词,而不是仅复制一个
inoremap matchstr(getline(line('.')-1),“\%”。
\virtcol('.').“v\%(\k\+\\\\\\\\\\.\)”
“插入当前缓冲区的目录并打开完成
cnoremap getcmdline()[getcmdpos()-2]==“”?
\展开(“%:h”)。"/\" : "\"

Duplicate of:至少这需要是一个社区wiki。此wiki与
f
/
f
searchI将分号映射到冒号,将冒号映射到分号。您使用命令的方式比f/f功能多,尽管您仍然可以像我使用它的方式访问它。看起来quick grep缺少了一些东西。你不是在搜索文件
:grep%:copenb
@pydave:你完全正确,我没有包括该文件的原因是它是在我的
grepprg
选项中定义的。我会相应地更新我的信息。
" Save and restore session
nmap <leader>ss :wa<cr>:mksession! $HOME/.vim/sessions/
nmap <leader>rs :wa<cr>:source $HOME/.vim/sessions/

" Write buffer through sudo
cnoreabbrev w!! w !sudo tee % >/dev/null

" Change the current directory to the directory of the file in buffer
nmap <silent> <leader>cd :cd %:p:h<cr>:pwd<cr>

" Open file located in the same directory as the current one
nmap <leader>e :e <c-r>=expand('%:p:h').'/'<cr>
" <esc> in normal mode clears highlight
nnoremap <silent> <esc> :noh<cr><esc>
" copy an entire word from the line above instead of just one
inoremap <expr> <c-y> matchstr(getline(line('.')-1), '\%' . 
\ virtcol('.') . 'v\%(\k\+\\|.\)')

" Insert Directory of current buffer and open completion
cnoremap <expr> <c-k> getcmdline()[getcmdpos()-2] == " " ? 
\ expand("%:h") .  "/\<c-d>" : "\<c-d>"