2011-04-26 11 views
7

私は最近、vimを使い始めました。有用なプラグインのロードを追加するのが楽しいです。問題は、私のプラグインをすべて設定している途中で、エンターキーのマッピングが正しく機能しなくなったことに気付かなかったことです。Vim <CR>マッピングが機能しませんか?

"{{{Auto Commands 

" Improve python indentation and higlighting 
autocmd FileType python set complete+=k~/.vim/syntax/python.vim isk+=.,(

" Automatically cd into the directory that the file is in 
autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ') 

" Remove any trailing whitespace that is in the file 
autocmd BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | 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 

"}}} 

"{{{Misc Settings 

" Necesary for lots of cool vim things 
set nocompatible 

" This shows what you are typing as a command. I love this! 
set showcmd 

" Folding Stuffs 
set foldmethod=marker 

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

" Who doesn't like autoindent? 
set autoindent 

" Spaces are better than a tab character 
set expandtab 
set smarttab 

" Who wants an 8 character tab? Not me! 
set shiftwidth=4 
set softtabstop=4 

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

" Real men use gcc 
"compiler gcc 

" Cool tab completion stuff 
set wildmenu 
set wildmode=list:longest,full 

" Enable mouse support in console 
set mouse=a 

" Got backspace? 
set backspace=2 

" Line Numbers PWN! 
set number 

" Ignoring case is a fun trick 
set ignorecase 

" And so is Artificial Intellegence! 
set smartcase 

" This is totally awesome - remap jj to escape in insert mode. You'll never type jj anyway, so it's great! 
inoremap jj <Esc> 

nnoremap JJJJ <Nop> 

" Incremental searching is sexy 
set incsearch 

" Highlight things that we find with the search 
set hlsearch 

" Since I use linux, I want this 
let g:clipbrdDefaultReg = '+' 

" When I close a tab, remove the buffer 
set nohidden 

" Set off the other paren 
highlight MatchParen ctermbg=4 
" }}} 

"{{{Look and Feel 

" Favorite Color Scheme 
if has("gui_running") 
    colorscheme desert 
    " Remove Toolbar 
    set guioptions-=T 
    "Terminus is AWESOME 
    set guifont=Terminus\ 9 
    set lines=999 columns=999 
else 
    colorscheme desert 
endif 

"Status line gnarliness 
set laststatus=2 
set statusline=%F%m%r%h%w\ (%{&ff}){%Y}\ [%l,%v][%p%%] 

" }}} 

"{{{ Functions 

"{{{ Open URL in browser 

function! Browser() 
    let line = getline (".") 
    let line = matchstr (line, "http[^ ]*") 
    exec "!konqueror ".line 
endfunction 

"}}} 

"{{{Theme Rotating 
let themeindex=0 
function! RotateColorTheme() 
    let y = -1 
    while y == -1 
     let colorstring = "inkpot#ron#blue#elflord#evening#koehler#murphy#pablo#desert#torte#" 
     let x = match(colorstring, "#", g:themeindex) 
     let y = match(colorstring, "#", x + 1) 
     let g:themeindex = x + 1 
     if y == -1 
     let g:themeindex = 0 
     else 
     let themestring = strpart(colorstring, x + 1, y - x - 1) 
     return ":colorscheme ".themestring 
     endif 
    endwhile 
endfunction 
" }}} 

"{{{ Paste Toggle 
let paste_mode = 0 " 0 = normal, 1 = paste 

func! Paste_on_off() 
    if g:paste_mode == 0 
     set paste 
     let g:paste_mode = 1 
    else 
     set nopaste 
     let g:paste_mode = 0 
    endif 
    return 
endfunc 
"}}} 

"{{{ Todo List Mode 

function! TodoListMode() 
    e ~/.todo.otl 
    Calendar 
    wincmd l 
    set foldlevel=1 
    tabnew ~/.notes.txt 
    tabfirst 
    " or 'norm! zMzr' 
endfunction 

"}}} 

"}}} 

"{{{ Mappings 

" Toggle line numbers and fold column for easy copying 
nnoremap <silent> <F2> :set nonumber!<CR>:set foldcolumn=0<CR> 

" Open the Project Plugin 
nnoremap <silent> <Leader>pal :Project .vimproject<CR> 

" TODO Mode 
nnoremap <silent> <Leader>todo :execute TodoListMode()<CR> 

" Open the TagList Plugin <F3> 
nnoremap <silent> <F3> :Tlist<CR> 

" Open the Fuf Plugin 
nnoremap <silent> <F4> :FufFile<CR> 

" Open the MRU Plugin 
nnoremap <silent> <F5> :MRU<CR> 

" Next Tab 
nnoremap <silent> <C-Right> :tabnext<CR> 

" Previous Tab 
nnoremap <silent> <C-Left> :tabprevious<CR> 

" New Tab 
nnoremap <silent> <C-t> :tabnew<CR> 

" Rotate Color Scheme <F8> 
nnoremap <silent> <F8> :execute RotateColorTheme()<CR> 

" DOS is for fools. 
nnoremap <silent> <F9> :%s/$//g<CR>:%s// /g<CR> 

" Paste Mode! Dang! <F10> 
nnoremap <silent> <F10> :call Paste_on_off()<CR> 
set pastetoggle=<F10> 

" Execute python file being edited with <Shift> + e: 
map <buffer> <S-e> :w<CR>:!/usr/bin/env python % <CR> 

" Edit vimrc \ev 
nnoremap <silent> <Leader>ev :tabnew<CR>:e ~/.vimrc<CR> 

" Edit gvimrc \gv 
nnoremap <silent> <Leader>gv :tabnew<CR>:e ~/.gvimrc<CR> 

" Up and down are more logical with g.. 
nnoremap <silent> k gk 
nnoremap <silent> j gj 
inoremap <silent> <Up> <Esc>gka 
inoremap <silent> <Down> <Esc>gja 

" Good call Benjie (r for i) 
nnoremap <silent> <Home> i <Esc>r 
nnoremap <silent> <End> a <Esc>r 

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

" Space will toggle folds! 
nnoremap <space> za 

" Search mappings: These will make it so that going to the next one in a 
" search will center on the line it's found in. 
map N Nzz 
map n nzz 

" Testing 
set completeopt=longest,menuone,preview 

inoremap <expr> <cr> pumvisible() ? "\<c-y>" : "\<c-g>u\<cr>" 
inoremap <expr> <c-n> pumvisible() ? "\<lt>c-n>" : "\<lt>c-n>\<lt>c-r>=pumvisible() ? \"\\<lt>down>\" : \"\"\<lt>cr>" 
inoremap <expr> <m-;> pumvisible() ? "\<lt>c-n>" : "\<lt>c-x>\<lt>c-o>\<lt>c-n>\<lt>c-p>\<lt>c-r>=pumvisible() ? \"\\<lt>down>\" : \"\"\<lt>cr>" 

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

" Fix email paragraphs 
nnoremap <leader>par :%s/^>$//<CR> 

"ly$O#{{{ "lpjjj_%A#}}}jjzajj 

"}}} 

"{{{Taglist configuration 
let Tlist_Use_Right_Window = 1 
let Tlist_Enable_Fold_Column = 0 
let Tlist_Exit_OnlyWindow = 1 
let Tlist_Use_SingleClick = 1 
let Tlist_Inc_Winwidth = 0 
"}}} 

let g:rct_completion_use_fri = 1 
"let g:Tex_DefaultTargetFormat = "pdf" 
let g:Tex_ViewRule_pdf = "kpdf" 

let g:pydiction_location = "/home/axilus/.vim/after/ftplugin/python_pydiction/complete-dict" 

filetype plugin indent on 
syntax on 

そして、私のロードされた:ここで

pumvisible() ? "\" : "\" 

は私のvimrcである:それはこれを印刷します代わりに改行を作成するのではなく、現在のところ、オートコンプリートメニューが存在しない場合は挿入モードでは、私が押したときに、入力します。スクリプト:

1: /usr/share/vim/vimrc 
    2: /usr/share/vim/vim72/debian.vim 
    3: /usr/share/vim/vim72/syntax/syntax.vim 
    4: /usr/share/vim/vim72/syntax/synload.vim 
    5: /usr/share/vim/vim72/syntax/syncolor.vim 
    6: /usr/share/vim/vim72/filetype.vim 
    7: /home/axilus/.vimrc 
    8: /usr/share/vim/vim72/ftplugin.vim 
    9: /usr/share/vim/vim72/syntax/nosyntax.vim 
10: /usr/share/vim/vim72/colors/desert.vim 
11: /usr/share/vim/vim72/indent.vim 
12: /home/axilus/.vim/plugin/EasyMotion.vim 
13: /home/axilus/.vim/plugin/NERD_tree.vim 
14: /home/axilus/.vim/plugin/fuf.vim 
15: /home/axilus/.vim/autoload/l9.vim 
16: /home/axilus/.vim/autoload/fuf.vim 
17: /home/axilus/.vim/autoload/fuf/buffer.vim 
18: /home/axilus/.vim/autoload/fuf/file.vim 
19: /home/axilus/.vim/autoload/fuf/coveragefile.vim 
20: /home/axilus/.vim/autoload/fuf/dir.vim 
21: /home/axilus/.vim/autoload/fuf/bookmarkfile.vim 
22: /home/axilus/.vim/autoload/fuf/bookmarkdir.vim 
23: /home/axilus/.vim/autoload/fuf/tag.vim 
24: /home/axilus/.vim/autoload/fuf/buffertag.vim 
25: /home/axilus/.vim/autoload/fuf/taggedfile.vim 
26: /home/axilus/.vim/autoload/fuf/jumplist.vim 
27: /home/axilus/.vim/autoload/fuf/changelist.vim 
28: /home/axilus/.vim/autoload/fuf/quickfix.vim 
29: /home/axilus/.vim/autoload/fuf/line.vim 
30: /home/axilus/.vim/autoload/fuf/help.vim 
31: /home/axilus/.vim/autoload/fuf/givenfile.vim 
32: /home/axilus/.vim/autoload/fuf/givendir.vim 
33: /home/axilus/.vim/autoload/fuf/givencmd.vim 
34: /home/axilus/.vim/autoload/fuf/callbackfile.vim 
35: /home/axilus/.vim/autoload/fuf/callbackitem.vim 
36: /home/axilus/.vim/plugin/l9.vim 
37: /home/axilus/.vim/plugin/matchit.vim 
38: /home/axilus/.vim/plugin/mru.vim 
39: /home/axilus/.vim/plugin/pydoc.vim 
40: /home/axilus/.vim/plugin/snipMate.vim 
41: /home/axilus/.vim/plugin/supertab.vim 
42: /home/axilus/.vim/plugin/surround.vim 
43: /home/axilus/.vim/plugin/taglist.vim 
44: /home/axilus/.vim/plugin/tcomment.vim 
45: /usr/share/vim/vim72/plugin/getscriptPlugin.vim 
46: /usr/share/vim/vim72/plugin/gzip.vim 
47: /usr/share/vim/vim72/plugin/matchparen.vim 
48: /usr/share/vim/vim72/plugin/netrwPlugin.vim 
49: /usr/share/vim/vim72/plugin/rrhelper.vim 
50: /usr/share/vim/vim72/plugin/spellfile.vim 
51: /usr/share/vim/vim72/plugin/tarPlugin.vim 
52: /usr/share/vim/vim72/plugin/tohtml.vim 
53: /usr/share/vim/vim72/plugin/vimballPlugin.vim 
54: /usr/share/vim/vim72/plugin/zipPlugin.vim 
55: /home/axilus/.vim/after/plugin/snipMate.vim 
56: /home/axilus/.vim/nerdtree_plugin/exec_menuitem.vim 
57: /home/axilus/.vim/nerdtree_plugin/fs_menu.vim 

私はvimの新機能ですので、必要な場合はお知らせください。

+0

あなたはどのバージョンのvimを使用していますか?バージョン情報を取得するには ':version'を使います。式のマッピングには少なくともvim 7.0が必要です。 –

+0

7.2。 Ubuntuリポジトリからインストールされます。 –

答えて

2

このマッピングは何をする予定ですか?

inoremap <expr> <cr> pumvisible() ? "\<c-y>" : "\<c-g>u\<cr>" 

あなたの問題です。それを修正する方法はわかりませんが、それを取り出して再起動すると、戻りキーが再び機能します。返品は私のために選択された補完を箱から受け入れるので、私は理解しません。

+0

あなたが正しいと思います。マッピングはポップアップメニューの動作を変更して、がデフォルトではない現在の項目を選択するようになっています。式の中でpumvisible()を使うと、すぐ下にある2つのコマンドとは異なっているように見えます。なぜなら、両方のコマンドの後ろに '\ 'を使って引用符で囲まれた式に左括弧を入れるからです。 \ <'。 'map 'の働きに関するヘルプは ':h map- 'にあります。 –

2

コマンド:map <CR>を発行すると、キャリッジリターンの現在のマッピングが表示されます。それがmap <CR>および/またはpumvisibleと一致する文字列のために読み込んだすべてのプラグインファイルでgrepを試してみるといいかもしれません。

5

Supertabは "inoremap < exprの> <CR> ..." マッピングと競合<へのマッピングCR >が含まれています。特に、supertabが他のものの後にロードされている場合、それはそれを壊す。スーパーマップがロードされた後にinoremapマッピングが行われると、それは機能します。

supertabの後ろに.vim/after/plugin/mappings.vimなどを入れてinoremapマッピングを作成することができます。

+0

病原体を使用している人はどうですか? supertabが私のを台無しにするのを避けるにはどうすればいいですか? – nye17

+0

上書きされる前にsupertabがロードされていることを確認するだけです。 .vim/after/plugin /を介して病原体をロードするか、または病原体がそのサブパッケージをロードする順序を突き止め、そのリストの中にsupertabが最初にあることを確認することができます。 –

関連する問題