首页 > 解决方案 > VIM:退格键在正常模式下删除,但在插入模式下不执行任何操作。

问题描述

初步信息:

详细说明:

当我处于插入模式时,我可以正常输入文本,但退格键不起作用。在正常模式下,退格键删除文本。这与我今天早些时候的行为完全相反。我在网上阅读了许多其他描述 Vim 非正统退格行为的帖子,但建议的配置设置(即 bs=2 或 bs=indent,eol,start)什么也没做。

更不寻常的是 gVim 的行为“正常”,即:退格键在正常模式下将光标向左移动,并在插入模式下删除文本。

我想要的是退格键在插入模式下删除文本(就像大多数其他程序一样)并在正常模式下导航/禁用。我怎样才能恢复这种行为?

下面是我的 _vimrc 的副本:(我会把它放在 github 上,但我的 git 目前搞砸了,我还没有修复它。)此外,默认情况下,_vimrc 内部还有一个函数。我不知道它做了什么,但为了节省空间而省略了它。如果你想看看我是否可以在回复中发布它。

source $VIMRUNTIME/vimrc_example.vim

source $VIMRUNTIME/mswin.vim

behave mswin

" Pathogen - Plugin manager
execute pathogen#infect()

set nocompatible " Turns off Vi compatability gubbinz

" Color Theme
if !has("gui_running") " Allows some 256 color themes to work in Terminal
    set term=xterm
    set t_Co=256
    let &t_AB="\e[48;5;%dm"
    let &t_AF="\e[38;5;%dm"
    colorscheme gruvbox
endif

let g:gruvbox_dark_contrast = 'hard' " Both of these are just visual gruvbox tweaks

let g:gruvbox_light_contrast = 'hard'
set guifont=Consolas:h10:cANSI:qDRAFT " Changes font
set bs=indent,eol,start  " Makes backspace be normal
set filetype=ON     " Has vim check for filetype
set showcmd         " Displays incomplete commands
set ruler           " Shows position of cursor in document
set syntax=ON       " Turns on syntax highlighting
set number          " Show line numbers
set linebreak       " Break lines at word (requires Wrap lines)
set showbreak=+++   " Wrap-broken line prefix
set textwidth=100   " Line wrap (number of cols)
set showmatch       " Highlight matching brace

set hlsearch        " Highlight all search results
set smartcase       " Enable smart-case search
set incsearch       " Searches for strings incrementally

set autoindent      " Auto-indent new lines
set shiftwidth=4    " Number of auto-indent spaces
set smartindent     " Enable smart-indent
set smarttab        " Enable smart-tabs
set softtabstop=4   " Number of spaces per Tab
set undolevels=1000     " Number of undo levels
set backspace=indent,eol,start  " Backspace behaviour
set go=egrLTm           " Changes flags that specify how the GUI loads

标签: vim

解决方案


最有可能的是,您的插入模式退格键被映射为什么都不做(即<nop>)。通过键入来验证这一点:verbose imap <bs>。这将显示退格键是否已映射以及映射的设置位置。

我想要的是退格键在插入模式下删除文本(就像大多数其他程序一样)并在正常模式下导航/禁用。我怎样才能恢复这种行为?

你可以做:

iunmap <bs>
nnoremap <bs> <nop>

第一行在<bs>插入模式下取消映射,因此<bs>将恢复其默认功能。第二行在<bs>正常模式下映射什么都不做。


推荐阅读