将“jj”映射到<esc>会导致光标尝试向前跳转</esc>

时间:2014-12-29 05:23:06

标签: vim windows-7

迁移到Windows后,我已开始调试.vimrc文件(请参阅相关问题here)。在Ubuntu中,我将jj组合键映射到ESC,如此

inoremap jj <Esc>                       

虽然按jj确实有助于我退出插入模式,但它会尝试向前搜索10或15个字符(我实际上没有计算过)。以下是一些可能相关的其他事项,

  • ;进入命令模式但q;没有给我命令模式历史记录,我必须输入q:
  • 我已将SHIFT + J<S-J>)映射到之前的缓冲区命令(bp)。它也会左/右移动光标。同样地,SHIFT + K<S-K>)映射到bn
  • jk命令正常运行
  • 似乎仅适用于触发ENTERESC按钮的情况

这是我的vimrc文件,以防它

" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = ","
let g:mapleader = ","

" Swap ; and :  Convenient.
nnoremap ; :
nnoremap : ;

" Create Blank Newlines and stay in Normal mode
nnoremap <silent> zj o<Esc>
nnoremap <silent> zk O<Esc>

"Make cursor move as expected with wrapped lines:
inoremap <Down> <C-o>gj
inoremap <Up> <C-o>gk

"Map Shift+ J to previous buffer
noremap <S-J> :bp<CR>           

"Map Shift + K to next buffer
noremap <S-k> :bn<CR>               

"Turn on syntax (I guess)
syntax on

" Needed for Syntax Highlighting and stuff
filetype on
filetype plugin on
syntax enable
set grepprg=grep\ -nH\ $*

" Tell vim to remember certain things when we exit
"  '10  :  marks will be remembered for up to 10 previously edited files
"  "100 :  will save up to 100 lines for each register
"  :20  :  up to 20 lines of command-line history will be remembered
"  %    :  saves and restores the buffer list
"  n... :  where to save the viminfo files
" set viminfo='10,\"100,:20,%,n~/.viminfo

"Restore cursor position
function! ResCur()
  if line("'\"") <= line("$")
    normal! g`"
    return 1
  endif
endfunction

augroup resCur
  autocmd!
  autocmd BufWinEnter * call ResCur()
augroup END

" Fast saving
noremap <leader>w :w!<cr>

" Fast editing of the .vimrc
" map <leader>e :e! ~/.vimrc<cr>
" noremap <leader>e :e! c:\\Users/username/.vimrc<cr>

" When vimrc is edited, reload it
" autocmd! bufwritepost vimrc source ~/.vim_runtime/vimrc

"These two lines display the file name at the bottom
set modeline                        
set ls=2

"Default for checking marks is 4 seconds, make it faster
set updatetime=100          

"Persistent Undo
" set undodir=~/.vim/undodir
set undodir=c:\\Users\user\vim\undodir
set undofile
set undolevels=10000    "maximum number of changes that can be undone
set undoreload=10000 "maximum number lines to save for undo on a buffer reload

"Keep undo history when switching buffers
set hidden

"Don't use vi-compatibility mode
set nocompatible                    

"Use the smart version of backspace (jumps over tabs apparently instead of
"spaces 
set backspace=2                     

"Use spaces instead of tabs
set expandtab                       

"Line Numbers
set number                                              

"Makes unnamed clipboard accesible to X window
set clipboard=unnamedplus

"Number of spaces to use for each step of (auto)indent.
set shiftwidth=4

"This shows what you are typing as a command
set showcmd

"Not too sure what this does
set smarttab

"Indent every time you press enter
set autoindent
set smartindent                                          

"Use C style indent instead (note this causes problems with non C code)
" set cindent

"Cursor Always in middle
"NOTE This causes problems with word wrap of long lines as they are not
"displayed correctly
set scrolloff=999                       

"Always display row/column info 
set ruler                           

"make word wrap wrap words, not character
set formatoptions=l
set lbr

"Use ... when word wrapping
set showbreak=...

"enable status line always
set laststatus=2

"
" statusline
" cf the default statusline: %<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
" format markers:
"   %< truncation point
"   %n buffer number
"   %f relative path to file
"   %m modified flag [+] (modified), [-] (unmodifiable) or nothing
"   %r readonly flag [RO]
"   %y filetype [ruby]
"   %= split point for left and right justification
"   %-35. width specification
"   %l current line number
"   %L number of lines in buffer
"   %c current column number
"   %V current virtual column number (-n), if different from %c
"   %P percentage through buffer
"   %) end of width specification
set statusline=%f%m%r%h%w[%n]\ [F=%{&ff}][T=%Y]\ %=[LINE=%l][%p%%]

"set it up to change the status line based on mode
if version >= 700
  au InsertEnter * hi StatusLine term=reverse ctermbg=4
  au InsertLeave * hi StatusLine term=reverse ctermbg=2
endif

"start searching as you type
set incsearch

"Map jj to escape
inoremap jj <Esc>                       

"Highlight search strings
set hlsearch 

" Set off the other paren
highlight MatchParen ctermbg=4

"Ignore case when searching
set ignorecase 

"But remember case when capitals used
set smartcase

" Use english for spellchecking, but don't spellcheck by default
if version >= 700
   set spl=en spell
   set nospell
endif

"Show matching brackets when text indicator is over them
set showmatch 

"How many tenths of a second to blink
"Does not seem to change anything
set mat=2 

"Highlight current line
set cul

"adjust highlight color
hi CursorLine term=none cterm=none ctermbg=232

"enable 256 color
set t_Co=256

"Do not want spell checking in my commented blocks
let g:tex_comment_nospell= 1

if &t_Co == 256
    " colorscheme xoria256
    colorscheme desert
else
    colorscheme peachpuff
endif

" Restore cursor position to where it was before
augroup JumpCursorOnEdit
   au!
   autocmd BufReadPost *
            \ if expand("<afile>:p:h") !=? $TEMP |
            \   if line("'\"") > 1 && line("'\"") <= line("$") |
            \     let JumpCursorOnEdit_foo = line("'\"") |
            \     let b:doopenfold = 1 |
            \     if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
            \        let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
            \        let b:doopenfold = 2 |
            \     endif |
            \     exe JumpCursorOnEdit_foo |
            \   endif |
            \ endif
   " Need to postpone using "zv" until after reading the modelines.
   autocmd BufWinEnter *
            \ if exists("b:doopenfold") |
            \   exe "normal zv" |
            \   if(b:doopenfold > 1) |
            \       exe  "+".1 |
            \   endif |
            \   unlet b:doopenfold |
            \ endif
augroup END

function! Time()
  return strftime("%c", getftime(bufname("%")))
endfunction

" Font size
if has("gui_running")
  if has("gui_gtk2")
    set guifont=Inconsolata\ 12
  elseif has("gui_macvim")
    set guifont=Menlo\ Regular:h14
  elseif has("gui_win32")
    set guifont=Consolas:h14:cANSI
  endif
endif

2 个答案:

答案 0 :(得分:7)

您的命令中有尾随空格。 (实际上有一堆映射有它)

删除它。

将尾随空格添加到命令中,并将光标向前移动等于空格数。

在整个文件上执行此操作的简便方法是运行

:%s/\s\+$//

答案 1 :(得分:2)

像这样的评论有什么意义:

"Turn on syntax (I guess)
syntax on

或者这个:

"Keep undo history when switching buffers
set hidden

或者这个:

"Not too sure what this does
set smarttab

或者这个:

"These two lines display the file name at the bottom
set modeline                        
set ls=2

(特别是考虑到你第二次启用状态栏)

也...


"enable 256 color
set t_Co=256

if &t_Co == 256
    colorscheme desert
else
    colorscheme peachpuff
endif
  1. 感谢set t_Co=256,你永远不会看到桃花。
  2. set t_Co=256与您的vimrc无关。请改为设置终端模拟器。

  3. "Always display row/column info 
    set ruler
    
    " statusline
    set statusline=%f%m%r%h%w[%n]\ [F=%{&ff}][T=%Y]\ %=[LINE=%l][%p%%]
    

    您的自定义状态行会覆盖'ruler'。从配置中删除set ruler


    set smartindent
    

    根本不是“智能” 。从配置中删除它。


    "Don't use vi-compatibility mode
    set nocompatible
    

    既错又无用。从配置中删除它。


    "Turn on syntax (I guess)
    syntax on
    
    " Needed for Syntax Highlighting and stuff
    filetype on
    filetype plugin on
    syntax enable
    
    • syntax on隐含filetype on
    • filetype plugin on隐含filetype on
    • 您已经syntax on,因此无需执行syntax enable

    请改用:

    filetype plugin indent on
    syntax on
    

    noremap <S-k> :bn<CR>
    

    应该是:

    nnoremap K :bn<CR>
    

    但是K - 关键字查找 - 非常有用,所以这不是一个好主意。


    noremap <S-J> :bp<CR>
    

    应该是:

    nnoremap J :bp<CR>
    

    但是J - 加入 - 对于重新映射到任何东西都太有用了。


    let g:mapleader = ","
    

    没用,可以安全移除。