Nvim 的 :help
頁面,是使用 tree-sitter-vimdoc 解析器,從 原始碼 產生而來。
/* */
, #if, #else, #endif。[/ 跳到上一個註解的開頭。]/ 跳到下一個註解的結尾。[# 跳回未封閉的 #if, #ifdef 或 #else。]# 跳到未封閉的 #else 或 #endif。[( 跳回未封閉的 '('。]) 跳到未封閉的 ')'。[{ 跳回未封閉的 '{'。]} 跳到未封閉的 '}'[{
到 ]}
的「一個區塊」,包含中括號。v_iB 選取從 [{
到 ]}
的「內部區塊」。map _u :call ID_search()<Bar>execute "/\\<" .. g:word .. "\\>"<CR> map _n :n<Bar>execute "/\\<" .. g:word .. "\\>"<CR> function! ID_search() let g:word = expand("<cword>") let x = system("lid --key=none " .. g:word) let x = substitute(x, "\n", " ", "g") execute "next " .. x endfun若要使用它,請將游標放在一個單字上,輸入 "_u",Vim 將載入包含該單字的檔案。使用 "n" 在同一個檔案中搜尋該單字的下一個出現位置。使用 "_n" 跳到下一個檔案。
:inoremap <C-E> <C-X><C-E> :inoremap <C-Y> <C-X><C-Y>然後您將失去從游標上方/下方複製文字的能力 i_CTRL-E。
:map <C-U> <C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y> :map <C-D> <C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E>
:ab teh the :ab fro for
:%s/./&/gn characters :%s/\i\+/&/gn words :%s/^//n lines :%s/the/&/gn "the" anywhere :%s/\<the\>/&/gn "the" as a word您可能想要重設 'hlsearch' 或執行 ":nohlsearch"。如果沒有匹配項時不希望產生錯誤,請新增 'e' 旗標。
:echo strlen(@")換行符號計為一個位元組。
:map <F2> msHmtgg/Last [cC]hange:\s*/e+1<CR>"_D"=strftime("%Y %b %d")<CR>p'tzt`s分解儲存位置:ms 將游標位置儲存在 's' 標記中 H 跳到視窗中的第一行 mt 將此位置儲存在 't' 標記中
*.c
重新命名為 *.bla
。我會這樣做$ vim :r !ls *.c :%s/\(.*\).c/mv & \1.bla :w !sh :q!
:%s/Jones/Smith/g :%s/Allen/Peter/g :update
vim *.let argdo source subs.vim請參閱 :argdo。
if ($?prompt == 0) then exit 0 endif另一種方法是在 'shell' 選項中包含 "-f" 旗標,例如
:set shell=csh\ -f(需要反斜線才能在選項中包含空格)。這將使 csh 完全跳過使用 .cshrc 檔案。但這可能會導致某些東西停止運作。
:map ' `使單引號的運作方式像反引號。將游標放在標記的欄位上,而不是跳到該行的第一個非空白字元。
" start of line :cnoremap <C-A> <Home> " back one character :cnoremap <C-B> <Left> " delete character under cursor :cnoremap <C-D> <Del> " end of line :cnoremap <C-E> <End> " forward one character :cnoremap <C-F> <Right> " recall newer command-line :cnoremap <C-N> <Down> " recall previous (older) command-line :cnoremap <C-P> <Up> " back one word :cnoremap <Esc><C-B> <S-Left> " forward one word :cnoremap <Esc><C-F> <S-Right>
:let m = ":map _f :set ai<CR>" " need 'autoindent' set :let m ..= "{O<Esc>" " add empty line above item :let m ..= "}{)^W" " move to text after bullet :let m ..= "i <CR> <Esc>" " add space for indent :let m ..= "gq}" " format text after the bullet :let m ..= "{dd" " remove the empty line :let m ..= "5lDJ" " put text after bullet :execute m |" define the mapping(<> 符號 <>。請注意,這都是照字面輸入。^W 是 "^" "W",而不是
|"
開頭,因為 ":execute" 命令不直接接受註解。:set tw=70一個功能大致相同的映射,但會從第一行取得列表的縮排。(注意:此映射是一行很長且有很多空格的單行)
:map _f :set ai<CR>}{a <Esc>WWmmkD`mi<CR><Esc>kkddpJgq}'mJO<Esc>j
:map ;b GoZ<Esc>:g/^$/.,/./-j<CR>Gdd :map ;n GoZ<Esc>:g/^[ <Tab>]*$/.,/[^ <Tab>]/-j<CR>Gdd
:%s=\(\t.*\.txt\)\t=\1.gz\t=(3) 將此行加入您的 vimrc
set helpfile={dirname}/help.txt.gz其中
{dirname}
是說明檔案所在的目錄。 gzip 外掛程式會負責解壓縮檔案。您必須確定 $VIMRUNTIME 設定為其他 Vim 檔案所在的位置,當它們與壓縮的 "doc" 目錄不在相同位置時。請參閱 $VIMRUNTIME。" vim -b : edit binary using xxd-format! augroup Binary autocmd! autocmd BufReadPre *.bin set binary autocmd BufReadPost *.bin \ if &binary \ | execute "silent %!xxd -c 32" \ | set filetype=xxd \ | redraw \ | endif autocmd BufWritePre *.bin \ if &binary \ | let s:view = winsaveview() \ | execute "silent %!xxd -r -c 32" \ | endif autocmd BufWritePost *.bin \ if &binary \ | execute "silent %!xxd -c 32" \ | set nomodified \ | call winrestview(s:view) \ | redraw \ | endif augroup END
" This is for automatically adding the name of the file to the menu list. " It uses a self-destroying mapping! " 1. use a line in the buffer to convert the 'dots' in the file name to \. " 2. store that in register '"' " 3. add that name to the Buffers menu list " WARNING: this does have some side effects, like overwriting the " current register contents and removing any mapping for the "i" command. " autocmd BufNewFile,BufReadPre * nmap i :nunmap i<CR>O<C-R>%<Esc>:.g/\./s/\./\\./g<CR>0"9y$u:menu Buffers.<C-R>9 :buffer <C-R>%<C-V><CR><CR> autocmd BufNewFile,BufReadPre * normal i另一種方法,可能更好,是使用 ":execute" 命令。在字串中,您可以使用 <> 符號,方法是在其前面加上反斜線。別忘了將現有的反斜線數量加倍,並在 '"' 之前加上反斜線。
autocmd BufNewFile,BufReadPre * exe "normal O\<C-R>%\<Esc>:.g/\\./s/\\./\\\\./g\<CR>0\"9y$u:menu Buffers.\<C-R>9 :buffer \<C-R>%\<C-V>\<CR>\<CR>"對於真正的緩衝區選單,應該使用使用者函數(請參閱 :function),但是這樣就不會使用 <> 符號,這就失去了在此處將其作為範例的意義。
let s:paren_hl_on = 0 function s:Highlight_Matching_Paren() if s:paren_hl_on match none let s:paren_hl_on = 0 endif let c_lnum = line('.') let c_col = col('.') let c = getline(c_lnum)[c_col - 1] let plist = split(&matchpairs, ':\|,') let i = index(plist, c) if i < 0 return endif if i % 2 == 0 let s_flags = 'nW' let c2 = plist[i + 1] else let s_flags = 'nbW' let c2 = c let c = plist[i - 1] endif if c == '[' let c = '\[' let c2 = '\]' endif let s_skip ='synIDattr(synID(line("."), col("."), 0), "name") ' .. \ '=~? "string\\|comment"' execute 'if' s_skip '| let s_skip = 0 | endif' let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip) if m_lnum > 0 && m_lnum >= line('w0') && m_lnum <= line('w$') exe 'match Search /\(\%' .. c_lnum .. 'l\%' .. c_col .. \ 'c\)\|\(\%' .. m_lnum .. 'l\%' .. m_col .. 'c\)/' let s:paren_hl_on = 1 endif endfunction autocmd CursorMoved,CursorMovedI * call s:Highlight_Matching_Paren() autocmd InsertEnter * match none
:HelpCurwin
命令command -bar -nargs=? -complete=help HelpCurwin execute s:HelpCurwin(<q-args>) let s:did_open_help = v:false function s:HelpCurwin(subject) abort let mods = 'silent noautocmd keepalt' if !s:did_open_help execute mods .. ' help' execute mods .. ' helpclose' let s:did_open_help = v:true endif if !empty(getcompletion(a:subject, 'help')) execute mods .. ' edit ' .. &helpfile set buftype=help endif return 'help ' .. a:subject endfunction