在插入模式下按CTRL-U后Vim冻结。有什么建议?

时间:2015-11-07 11:41:13

标签: vim

最近我发现在插入模式下按CTRL-U会锁定/冻结vim。唯一的CTRL-C有助于恢复它。终端版本和gvim具有相同的行为。仅在虚拟控制台模式(CTRL-ALT-F1)中,C-U才能正常工作。这是我的.vimrc

" This must be first, because it changes other options as a side effect.
set nocompatible

" Don't use Ex mode, use Q for formatting
map Q gq

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
imap <C-U> <C-G>u<C-U>

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
  set mouse=a
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

  augroup END

else
  set autoindent        " always set autoindenting on
endif

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
            \ | wincmd p | diffthis
endif

" Options
" =========================================================
colorscheme gruvbox
let g:gruvbox_contrast_dark = 'normal'
set background=dark
set t_Co=256
" spelling
set spell spelllang=ru_yo,en_us
set spellsuggest=10
set keymap=russian-jcukenwin
set iminsert=0
set imsearch=0
" backup
set writebackup " backup on write
set nobackup        " keep a backup file
set undofile        " keep an undo file
set swapfile        " keep a swap file
" directories
" set autochdir
set backupdir=~/.vim/tmp/backup//
set undodir=~/.vim/tmp/undo//
set directory=~/.vim/tmp/swp//
" active editor
set nowrap
set nu
set backspace=indent,eol,start " backspacing over everything in im
set ruler                   " show the cursor position all the time
" cmd
set history=50      " keep 50 lines of command line history
set showcmd             " display incomplete commands
" search
set ignorecase      " ignore case using a search pattern.
set smartcase           " override 'ignorecase' when pattern has upper case.
set incsearch           " do incremental searching
" tab
" set tabstop=2 shiftwidth=2 noexpandtab " n-column tab
set tabstop=2 shiftwidth=2 expandtab " n-space character tab
" window
set splitbelow
set splitright
set winminheight=0
" folding settings
set foldmethod=indent   " fold based on indent
set foldnestmax=10      " deepest fold is 10 levels
set nofoldenable        " dont fold by default
set foldlevel=1         " this is just what i use
" invisible chars
set list                            " don't show invisible characters.
set listchars=tab:.\ ,trail:~,extends:>,precedes:<,eol:\ "¬
set nohidden                            " unload buffer when no longer shown in window.
set laststatus=2                " Display vim-lightline
" indent, cursor, width
set cursorline                  " Highlight the screen line of the cursor.
set colorcolumn=72          " Columan to highlight.
set autoindent                  " Automatically set the indent of a new line.
set textwidth=80
set completeopt=menuone,longest ",preview  prevents immediate complete
" tab
set switchbuf=usetab        " use window or tabs to find selected buff
" windows
set noea " fix window size after closing others
" sessions (^blank,help)
set sessionoptions=buffers,curdir,folds,help,options,tabpages,winsize

" Autocmd
" =========================================================
au BufReadPost *.tmpl set syntax=html

" Mappings
" =========================================================
" source and update file
nmap <F5> :so ~/.vimrc<CR>
nmap <leader>e :e<CR>
" copy filepath
nmap <silent> <F4> :let @+=expand("%:p")<CR>
" buffers
nmap <F2> :ls<CR>:b
nmap <c-w><c-t> :tabnew<CR>
nmap <c-w><c-e> :tab sp<CR>
nmap <c-w><c-b>n :tabnew %<Bar>:bNext<Bar><CR>
nmap <c-w><c-b><c-b> :bw %<CR>
nmap <c-w><c-b>w :bw! %<CR>
nmap <c-w><c-b>a :tab ball<CR>
" sessions
nmap <silent> <leader>ss :wa<Bar>exe "mksession! " . v:this_session<CR>
nmap <leader>sr :so .session.vim<CR>
nmap <leader>sc :msk .session.vim<CR>
" quit
nmap <leader>qd :qa!<CR>  " quit & discard changes
nmap <leader>qq :xa<CR>   " quit & write if changed
nmap <leader>qs <leader>s<leader>qd
" new vertical window
nmap <c-w><c-n> :vnew<CR>
" tab movement and switching
nmap <c-l> :tabnext<CR>
nmap <c-h> :tabprevious<CR>
nmap <c-j> :tabmove -1<CR>
nmap <c-k> :tabmove +1<CR>
" search and replace
nmap <leader>c :let @/=""<CR>
" trailing spaces
nmap <silent> <leader>dt mq:%s/\s\+$//e<Bar>:let @/=""<CR>`q:delm q<CR>
" update, write
nmap <leader>u <leader>dt:update<CR>
nmap <leader>w <leader>dt:write<CR>
cmap w!! w !sudo tee > /dev/null %
" window manipulation
nmap <c-w>== :set ead=ver ea noea<CR>
nmap <c-w>=- :set ead=hor ea noea<CR>
" shell
nmap <space> :sh<CR>

" Plugins
" =========================================================
call plug#begin('~/.vim/plugged')
Plug 'fatih/vim-go'
Plug 'mattn/emmet-vim'
Plug 'itchyny/lightline.vim'
Plug 'sheerun/vim-polyglot'
Plug 'scrooloose/syntastic'
call plug#end()

" Lightline.vim
let g:lightline = {
    \ 'colorscheme': 'jellybeans',
    \ 'active': {
    \   'left': [ [ 'mode', 'paste' ],
    \             [ 'fugitive', 'filename', 'readonly', 'modified' ] ] },
    \}
" Syntastic
" let g:syntastic_sass_checkers = ["sassc"]

" Netrw
nmap <leader>tr <Plug>NetrwRefresh
map <leader>tf :Ntree<CR>
map <silent> <leader>f <S-CR>

let g:netrw_liststyle=3
let g:netrw_banner=0
let g:netrw_mousemaps=0
let g:netrw_chgwin=1 " open files in left window by default
" let g:netrw_keepdir=0
" let g:netrw_silent= 1
" fire up the sidebar
nmap <silent> <C-@> :rightbelow 25vs<CR>:e .<CR>

" vim-go
" disable fmt on save
let g:go_fmt_autosave = 0
" format with goimports instead of gofmt
let g:go_fmt_command = "goimports"
" additional highlight
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1

" YouCompleteMe
let g:ycm_confirm_extra_conf=0
let g:ycm_autoclose_preview_window_after_completion=1
let g:ycm_min_num_of_chars_for_completion=1

" Emmet-vim
let g:user_emmet_leader_key='<c-m>'

" Formats the statusline
" set statusline=%f                           " file name
" set statusline+=[%{strlen(&fenc)?&fenc:'none'}, "file encoding
" set statusline+=%{&ff}] "file format
" set statusline+=%y      "filetype
" set statusline+=%h      "help file flag
" set statusline+=%m      "modified flag
" set statusline+=%r      "read only flag
"
" set statusline+=\ %=                        " align left
" set statusline+=Line:%l/%L[%p%%]            " line X of Y [percent of file]
" set statusline+=\ Col:%c                    " current column
" set statusline+=\ Buf:%n                    " Buffer number
" set statusline+=\ [%b][0x%B]\               " ASCII and byte code under cursor

" Miscellaneous
" =========================================================
nmap <leader>t :call <SID>SynStack()<CR>
function! <SID>SynStack()
  if !exists("*synstack")
    return
  endif
  echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc

:set guioptions-=m  "remove menu bar
:set guioptions-=T  "remove toolbar
:set guioptions-=r  "remove right-hand scroll bar
:set guioptions-=L  "remove left-hand scroll bar

它很大,但是唯一一个与C-U相关的映射:imap <C-U> <C-G>u<C-U>。发生了什么事?

2 个答案:

答案 0 :(得分:3)

我已复制你的vimrc并使用它。同样的效果。这就是这条线:

imap <C-U> <C-G>u<C-U>

显然会导致递归。当注释掉时,<C-u>将重新开始回到行首。

答案 1 :(得分:1)

鉴于@Jens发现的问题......你,帖木儿,可能想尝试

inoremap <c-u> <c-g>u<c-u>

这将阻止重新映射(即无限递归)。