代码之家  ›  专栏  ›  技术社区  ›  Jordan S.

VIM:退格在正常模式下删除,但在插入模式下不执行任何操作。

vim
  •  1
  • Jordan S.  · 技术社区  · 7 年前

    初步信息:

    • 问题出现在端子Vim中,而不是gVim中
    • 我使用CMDER(基于conemu)作为终端仿真器
    • 我在Windows 10上

    详细说明:

    当我处于插入模式时,我可以按常规方式键入文本,但退格不起任何作用。在正常模式下,backspace键删除文本。这与我今天早些时候的行为完全相反。我在网上读过许多其他帖子,描述Vim的非常规退格行为,但建议的配置设置(即bs=2或bs=缩进、eol、开始)没有起到任何作用。

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

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

    下面是我的\u vimrc的副本:(我想把这个放在github上,但我的git现在已经坏了,我还没有修复它。)此外,默认情况下,\u 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
    
    1 回复  |  直到 7 年前
        1
  •  5
  •   builder-7000    7 年前

    最有可能的情况是,插入模式退格映射为不执行任何操作(即。 <nop> )。通过键入 :verbose imap <bs> 。这将显示是否映射了backspace键以及映射的设置位置。

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

    您可以执行以下操作:

    iunmap <bs>
    nnoremap <bs> <nop>
    

    第一行取消映射 <bs> 在插入模式下,因此 <bs> 将恢复其默认功能。第二行地图 <bs> 在正常模式下不执行任何操作。