简体   繁体   中英

Vim: inoremap works in buffer, not in .vimrc

I'm really eager to include the following in my .vimrc file:

inoremap <Tab> <C-x><C-u>

If I set it within a buffer (via :inoremap <Tab> <Cx><Cu> ) it works exactly as I'd hoped.

But, if I place it in my .vimrc, it doesn't seem to be acknowledged at all.

I've attached my .vimrc below. A few things:

  • Other changes to the .vimrc file are picked up, so it's not the wrong file
  • Have tried adding at the very bottom of the .vimrc & still doesn't work, so it's not being overwritten

Any ideas appreciated. Many thanks.

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
  finish
endif

" Word complete
" :autocmd BufEnter * call DoWordComplete() 
" let g:WC_min_len = 4


" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
map j gj
map k gk

set showmatch " Show matching brackets
set mat=5 " Bracket blinking
set noerrorbells " No noise

" Ruby autocomplete

" Autocomplete behaviour
set completeopt=longest,menuone
open omni completion menu closing previous if open and opening new menu without changing the text
inoremap <expr> <C-Space> (pumvisible() ? (col('.') > 1 ? '<Esc>i<Right>' : '<Esc>i') : '') .
            \ '<C-x><C-o><C-r>=pumvisible() ? "\<lt>C-n>\<lt>C-p>\<lt>Down>" : ""<CR>'
" open user completion menu closing previous if open and opening new menu without changing the text
inoremap <expr> <S-Space> (pumvisible() ? (col('.') > 1 ? '<Esc>i<Right>' : '<Esc>i') : '') .
            \ '<C-x><C-u><C-r>=pumvisible() ? "\<lt>C-n>\<lt>C-p>\<lt>Down>" : ""<CR>'


autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
" highlight Pmenu ctermbg=238 gui=bold "improve autocomplete menu color

" Colours
highlight Pmenu ctermfg=6 ctermbg=238 guibg=grey30


" allow backspacing over everything in insert mode
set backspace=indent,eol,start

" if has("vms")
"   set nobackup        " do not keep a backup file, use versions instead
" else
"   set backup      " keep a backup file
" endif

" Set backupdir to tmp
" Do not let vim create <filename>~ backup files
set nobackup
" set nowritebackup

set history=50      " keep 50 lines of command line history
set ruler       " show the cursor position all the time
set showcmd     " display incomplete commands
set incsearch       " do incremental searching

" Set tab to 2 spaces
set ts=2
set shiftwidth=2

" Ignore case
set ignorecase
set smartcase

" Menu autocomplete
set wildmode=longest,list
set wildmenu

" Call pathogen
call pathogen#infect()

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
  set mouse=a
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

" Turn syntax highlighting on (Added by John Bayne, 18/08/2012)
syntax on

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

  augroup END

else

  set autoindent        " always set autoindenting on

endif " has("autocmd")

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
          \ | wincmd p | diffthis
endif

" My customisations
" No backup files
set nobackup
set nowritebackup
set noswapfile

" Whitespace identifier
:highlight ExtraWhitespace ctermbg=darkgreen guibg=lightgreen
:match ExtraWhitespace /\s\+$/



" Colour options
" color codeschool
" set guifont=Monaco:h12
" let g:NERDTreeWinPos = "right"
" set guioptions-=T " Removes top toolbar
" set guioptions-=r " Removes right hand scroll bar
" set go-=L " Removes left hand scroll bar
" autocmd User Rails let b:surround_{char2nr('-')} = "<% \r %>" " displays <% %> correctly
" :set cpoptions+=$ " puts a $ marker for the end of words/lines in cw/c$ commands

" Tab behaviour for ultisnips
let g:UltiSnipsExpandTrigger="<tab>" 
let g:UltiSnipsJumpForwardTrigger="<tab>" 
let g:UltiSnipsJumpBackwardTrigger="<s-tab>" 


inoremap <Tab> <C-x><C-u>

In this case, :scriptnames , while useful, is not the best way to see where a mapping was last set.

:verbose map <tab>

is a lot more precise.

Maybe another script is overwriting it after your .vimrc is read.

You can use :scriptnames to see what files are read on startup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM