将"jj"映射为<ESC>会导致光标试图向前跳转。

3

我已经开始在迁移到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个回答

11

您的命令中存在尾随空格(实际上许多映射都有它)。

删除它。

尾随空格被添加到命令中,并使光标向前移动相应数量的空格。

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

:%s/\s\+$//

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 中没有任何作用。请设置您的终端仿真器。

"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 — join — 太有用了,不应该被重新映射成其他任何东西。


let g:mapleader = ","

是无用的,可以安全地删除。


这是一团糟。同时,我不会生气,因为这非常有帮助。 - puk

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接