vim set number在InsertEnter上不起作用

时间:2015-02-25 23:04:52

标签: vim

正如您将从下面的vimrc文件中看到的,我正在尝试在InsertEnter上设置“设置数字”。在正常模式下,我使用'set relativenumber'来更容易地使用j,k。下面的配置适用于我的macbook,但不适用于我正在运行的RHEL盒子。当我进入插入模式时,它不会为整个文件执行“设置编号”,而是仅为我所在的行设置编号。其余的文件行继续显示为相对数字。

我该如何解决这个问题?知道这里发生了什么吗?

execute pathogen#infect()
call pathogen#helptags()
syntax on
syntax enable
filetype plugin indent on
colorscheme molokai
set rnu
autocmd FocusLost * :set number
autocmd FocusGained * :set rnu
autocmd InsertEnter * :set number
autocmd InsertLeave * :set rnu
set rtp +=/home/evolution/.vim/bundle/powerline/powerline/bindings/vim
set splitright
set ttymouse=xterm2
set backspace=2
set laststatus=2
set t_Co=256
set laststatus=2
set showtabline=2
set noshowmode
set nocompatible
set background=dark
set shiftwidth=4  " operation >> indents 4 columns; << unindents 4 columns
set tabstop=4     " a hard TAB displays as 4 columns
set expandtab     " insert spaces when hitting TABs
set softtabstop=4 " insert/delete 4 spaces when hitting a TAB/BACKSPACE
set shiftround    " round indent to multiple of 'shiftwidth'
set autoindent    " align the new line indent with the previous line
set cursorline
hi CursorLine   cterm=NONE ctermbg=52

let g:CommandTAcceptSelectionMap = '<C-t>'
let g:CommandTAcceptSelectionTabMap = '<CR>'
let g:airline#extensions#tabline#enabled = 1

noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>

map  <C-l> :tabn<CR>
map  <C-h> :tabp<CR>

3 个答案:

答案 0 :(得分:3)

我发现这有效:

set rnu
function ToggleNumbersOn()
    set rnu!
    set nu
endfunction
function ToggleRelativeOn()
    set nu!
    set rnu
endfunction
autocmd FocusLost * call ToggleNumbersOn()
autocmd FocusGained * call ToggleRelativeOn()
autocmd InsertEnter * call ToggleNumbersOn()
autocmd InsertLeave * call ToggleRelativeOn()

答案 1 :(得分:0)

使用set number

替换自动命令nornu
set nu
autocmd InsertEnter * :set nornu
autocmd InsertLeave * :set rnu

固定时标记为固定

答案 2 :(得分:-1)

您可能对Vim 7.4混合相对绝对数模式感兴趣。

set relativenumber 
set number

这将显示相​​对数字,但是当前行号将为零。

但是,如果这对您不起作用,那么有一些插件可以满足您的要求:numbers.vimnumbertoggle