【问题标题】:Vim freezes after pressing CTRL-U in insert mode. Any suggestions?在插入模式下按 CTRL-U 后 Vim 冻结。有什么建议?
【发布时间】:2016-02-08 12:26:23
【问题描述】:

最近我发现按 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 &lt;C-U&gt; &lt;C-G&gt;u&lt;C-U&gt;。怎么回事?

【问题讨论】:

  • 它是否适用于vim -u NONE -U NONE
  • Hm...C-U 的行为有点奇怪(比如向后退一个词并替换S-R)。但它不会冻结 vim!
  • 嗯。很不寻常。也许您的 TERM 环境变量与您的实际终端不匹配?
  • 在 vim 和终端中执行 :echo $TERM 和只是 echo $TERM 给出相同的 xterm 值。我如何检查该术语使用 vim 的内容?

标签: vim


【解决方案1】:

我已经复制了你的 vimrc 并使用了它。一样的效果。就是这一行:

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

这显然会导致递归。注释掉时,&lt;C-u&gt; 会擦除回行首。

【讨论】:

  • 是的,已经想到了!)太好了!由于麻烦,我知道了一些新的有趣的插入命令)),如i_CTRL-Ai_CTRL-G+(J,K,A,u) 等。谢谢!)
【解决方案2】:

鉴于@Jens 发现的问题......您,Timur,可能想尝试

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

这将防止发生重新映射(即无限递归)。

【讨论】:

    猜你喜欢
    • 2018-12-30
    • 2012-10-08
    • 2016-05-29
    • 2012-10-30
    • 2012-02-03
    • 2017-03-14
    • 1970-01-01
    • 2019-08-06
    • 2018-06-17
    相关资源
    最近更新 更多