1

Recently I figured out that pressing CTRL-U locks/freezes vim in insert mode. The only CTRL-C helps to get it back. Terminal version and gvim have the same behaviour. Only in virtual console mode (CTRL-ALT-F1) the C-U works properly. Here is my .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

It's quite big, but the only one mapping related with C-U: imap <C-U> <C-G>u<C-U>. What's going on?

4
  • 1
    Does it work with vim -u NONE -U NONE?
    – Jens
    Nov 7, 2015 at 12:27
  • Hm...C-U behaves a little bit strange (like go backward by one word and replace S-R). But it doesn't freeze the vim! Nov 7, 2015 at 12:38
  • 1
    Hmm. Very unusual. Maybe your TERM environment variable does not match your actual terminal?
    – Jens
    Nov 7, 2015 at 12:59
  • Doing :echo $TERM and just echo $TERM in both vim and terminal gives the same xterm value. How can I check what the term uses vim? Nov 7, 2015 at 13:08

2 Answers 2

3

I've copied your vimrc and used it. Same effect. It's this line:

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

which apparently causes a recursion. When commented out, <C-u> erases back to start-of-line.

1
  • Yep, already figured it!) Great! Because of the trouble I have known some new and interesting to me insert commands)), like i_CTRL-A and i_CTRL-G+(J,K,A,u) etc. Thank you!) Nov 7, 2015 at 13:35
2

Given the problem that @Jens found... you, Timur, might want to try

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

That will prevent remapping (ie. an infinite recursion) from taking place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.