Loading ...
Sorry, an error occurred while loading the content.
 

[HELP]inoremap doesn't work!

Expand Messages
  • zhang listar
    ... function ClosePair(char) if getline( . )[col( . ) - 1] == a:char return else return a:char endif endf I have added the lines above to my vimrc,
    Message 1 of 4 , Nov 30, 2010
      :inoremap ( ()<ESC>i
      :inoremap ) <c-r>=ClosePair(')')<CR>
      :inoremap { {}<ESC>i
      :inoremap } <c-r>=ClosePair('}')<CR>
      :inoremap [ []<ESC>i
      :inoremap ] <c-r>=ClosePair(']')<CR>
      :inoremap < <><ESC>i
      :inoremap > <c-r>=ClosePair('>')<CR>

      function ClosePair(char)
      if getline('.')[col('.') - 1] == a:char
      return "\<Right>"
      else
      return a:char
      endif
      endf

      I have added the lines above to my vimrc, but vim does't automatically complete bracket,
      What's wrong with my vim?
      The vimrc is as follows:
        
      " All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
      " /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
      " you can find below.  If you wish to change any of those settings, you should
      " do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
      " everytime an upgrade of the vim packages is performed.  It is recommended to
      " make changes after sourcing debian.vim since it alters the value of the
      " 'compatible' option.

      " This line should not be removed as it ensures that various options are
      " properly set to work with the Vim-related packages available in Debian.
      runtime! debian.vim

      " Uncomment the next line to make Vim more Vi-compatible
      " NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous
      " options, so any other options should be set AFTER setting 'compatible'.
      "set compatible

      " Vim5 and later versions support syntax highlighting. Uncommenting the next
      " line enables syntax highlighting by default.
      syntax on

      " If using a dark background within the editing area and syntax highlighting
      " turn on this option as well
      "set background=dark

      " Uncomment the following to have Vim jump to the last position when
      " reopening a file
      "if has("autocmd")
      "  au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
      "    \| exe "normal g'\"" | endif
      "endif

      " Uncomment the following to have Vim load indentation rules according to the
      " detected filetype. Per default Debian Vim only load filetype specific
      " plugins.
      "if has("autocmd")
      "  filetype indent on
      "endif

      " The following are commented out as they cause vim to behave a lot
      " differently from regular Vi. They are highly recommended though.
      "set showcmd        " Show (partial) command in status line.
      "set showmatch        " Show matching brackets.
      "set ignorecase        " Do case insensitive matching
      "set smartcase        " Do smart case matching
      "set incsearch        " Incremental search
      "set autowrite        " Automatically save before commands like :next and :make
      "set hidden             " Hide buffers when they are abandoned
      "set mouse=a        " Enable mouse usage (all modes) in terminals

      " Source a global configuration file if available
      " XXX Deprecated, please move your changes here in /etc/vim/vimrc
      filetype plugin on
      if filereadable("/etc/vim/vimrc.local")
        source /etc/vim/vimrc.local
      endif
      syntax on
      set expandtab
      set tabstop=4
      set autoindent shiftwidth=2
      set autochdir
      set cindent
      set shiftwidth=4
      let mapleader=","
      map <silent><leader>w : w<cr>
      map <silent><leader>qa : qa<cr>
      map <silent><leader>qq : q!<cr>
      map <silent><leader>wq : wq<cr>
      map <silent><leader>q : q<cr>
      "Taglist
      map <silent><leader>tl :TlistToggle<cr>
      let Tlist_Ctags_Cmd = '/usr/bin/ctags'
      let Tlist_Show_One_File = 1
      let Tlist_Exit_OnlyWindow = 1
      let Tlist_Use_Right_Window = 1
      set nohlsearch
      let &termencoding=&encoding
      set fileencodings=cp936,ucs-bom,utf-8,gbk
      set fileencoding=cp936
      "set encoding=cp936
      set encoding=utf-8
      "colorscheme desert
      "colorscheme molokai
      " cscope
      if has("cscope")
          set csprg=/usr/bin/cscope
          set csto=1
          set cst
          set nocsverb
          " add any database in current directory
          if filereadable("cscope.out")
              cs add cscope.out
          endif
          set csverb
      endif
      nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
      nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
      nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
      nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
      nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
      nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
      nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
      nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
      " bufexploer
      map <silent><leader>be :BufExplorer<cr>
      map <silent><leader>bs :BufExplorerHorizontalSplit<cr>
      map <silent><leader>bv :BufExplorerVerticalSplit<cr>
      " quickfix
      nmap <F6> :cn<cr>
      nmap <F7> :cp<cr>
      nmap <F5> :make<cr>
      nmap <F8> :cw<cr>
      " press control + s to save
      "imap <C-c> <ESC> :w<cr>
      "nmap <C-c> <ESC> :w<cr>
      " quick jump between splits
      map <C-j> <C-w>j<C-w>_
      map <C-k> <C-w>k<C-w>_
      map <C-l> <C-w>l<C-w>_
      map <C-h> <C-w>h<C-w>_

      " A.vim
      map <silent><leader>a :A<cr>
      " NERD_tree
      map <silent><leader>t :NERDTreeToggle<cr>
      " another explorer
      map <silent><leader>e :Ex<cr>
      " only one window
      map <silent><leader>m :only<cr>
      " omnicppcomplete
      set completeopt=menu
      let OmniCpp_SelectFirstItem = 0
      map <F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
      set tags+=/home/listar/cppstltags
      " pydiction
      filetype plugin on
      let g:pydiction_location = '/home/listar/.vim/tools/pydiction/complete-dict'
      "php set
      "au FileType php source /usr/share/vim/vim72/colors/murphy.vim
      let g:phpColor = "murphy"
      let g:defaultColor = "desert"
      "au! FileType * exe ":colorscheme " . g:defaultColor
      "au! FileType php exe ":colorscheme " . g:phpColor
      " neocomplcache
      " Disable AutoComplPop.
      let g:acp_enableAtStartup = 0
      " Use neocomplcache.
      let g:neocomplcache_enable_at_startup = 1
      " Use smartcase.
       let g:neocomplcache_enable_smart_case = 1
      " Use camel case completion.
      let g:neocomplcache_enable_camel_case_completion = 1
      " Use underbar completion.
      let g:neocomplcache_enable_underbar_completion = 1
      " Set minimum syntax keyword length.
      let g:neocomplcache_min_syntax_length = 3
      let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*'
      colorscheme desertEx

      THANKS!

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Ben Fritz
      ... I don t see the content above in your .vimrc you posted. Are you sure you added it? On a related note, I like using instead of i in the
      Message 2 of 4 , Dec 1, 2010
        On Nov 30, 5:47 am, zhang listar <listarmings...@...> wrote:
        > :inoremap ( ()<ESC>i
        > :inoremap ) <c-r>=ClosePair(')')<CR>
        > :inoremap { {}<ESC>i
        > :inoremap } <c-r>=ClosePair('}')<CR>
        > :inoremap [ []<ESC>i
        > :inoremap ] <c-r>=ClosePair(']')<CR>
        > :inoremap < <><ESC>i
        > :inoremap > <c-r>=ClosePair('>')<CR>
        >
        > function ClosePair(char)
        > if getline('.')[col('.') - 1] == a:char
        > return "\<Right>"
        > else
        > return a:char
        > endif
        > endf
        >
        > I have added the lines above to my vimrc, but vim does't automatically
        > complete bracket,
        > What's wrong with my vim?
        > The vimrc is as follows:
        >

        I don't see the content above in your .vimrc you posted. Are you sure
        you added it?

        On a related note, I like using <Left> instead of <Esc>i in the
        mappings I have that do similar things. Fewer side effects.

        See our tip on the subject:

        http://vim.wikia.com/wiki/Automatically_append_closing_characters

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • zhang listar
        2010/12/1 Ben Fritz ... I am sure that I have added the content to my vimrc. Now, the character {, [ works fine. But when I type (,
        Message 3 of 4 , Dec 1, 2010
          2010/12/1 Ben Fritz <fritzophrenic@...>


          On Nov 30, 5:47 am, zhang listar <listarmings...@...> wrote:
          > :inoremap ( ()<ESC>i
          > :inoremap ) <c-r>=ClosePair(')')<CR>
          > :inoremap { {}<ESC>i
          > :inoremap } <c-r>=ClosePair('}')<CR>
          > :inoremap [ []<ESC>i
          > :inoremap ] <c-r>=ClosePair(']')<CR>
          > :inoremap < <><ESC>i
          > :inoremap > <c-r>=ClosePair('>')<CR>
          >
          > function ClosePair(char)
          > if getline('.')[col('.') - 1] == a:char
          > return "\<Right>"
          > else
          > return a:char
          > endif
          > endf
          >
          > I have added the lines above to my vimrc, but vim does't automatically
          > complete bracket,
          > What's wrong with my vim?
          > The vimrc is as follows:
          >
          I don't see the content above in your .vimrc you posted. Are you sure
          you added it?
          On a related note, I like using <Left> instead of <Esc>i in the
          mappings I have that do similar things. Fewer side effects.
          See our tip on the subject:
          http://vim.wikia.com/wiki/Automatically_append_closing_characters


          I am sure that I have added the content to my vimrc. Now, the character {, [ works fine.
          But when I type (, vim can't automatically append ) for me. Instead, the plugin acp or neocomplcache(I am not sure which one)
          take effect, and pops up a menu to choose the item.
          I doubt that some plugin of vim has affect inoremap of ( .

          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Benjamin R. Haskell
          ... It appeared in the other (double-) post to which I replied. Odd. ... I agree with this advice. ... If when you type ( some other plugin takes effect,
          Message 4 of 4 , Dec 2, 2010
            On Thu, 2 Dec 2010, zhang listar wrote:

            > 2010/12/1 Ben Fritz
            >>
            >> On Nov 30, 5:47 am, zhang listar wrote:
            >>> :inoremap ( ()<ESC>i
            >>> :inoremap ) <c-r>=ClosePair(')')<CR>
            >>> :inoremap { {}<ESC>i
            >>> :inoremap } <c-r>=ClosePair('}')<CR>
            >>> :inoremap [ []<ESC>i
            >>> :inoremap ] <c-r>=ClosePair(']')<CR>
            >>> :inoremap < <><ESC>i
            >>> :inoremap > <c-r>=ClosePair('>')<CR>
            >>>
            >>> function ClosePair(char)
            >>> if getline('.')[col('.') - 1] == a:char
            >>> return "\<Right>"
            >>> else
            >>> return a:char
            >>> endif
            >>> endf
            >>>
            >>> I have added the lines above to my vimrc, but vim does't
            >>> automatically complete bracket,
            >>> What's wrong with my vim?
            >>> The vimrc is as follows:
            >>>
            >> I don't see the content above in your .vimrc you posted. Are you sure
            >> you added it?

            It appeared in the other (double-) post to which I replied. Odd.


            >> On a related note, I like using <Left> instead of <Esc>i in the
            >> mappings I have that do similar things. Fewer side effects.

            I agree with this advice.


            >> See our tip on the subject:
            >> http://vim.wikia.com/wiki/Automatically_append_closing_characters
            >> <http://www.vim.org/maillist.php>
            >>
            >
            > I am sure that I have added the content to my vimrc. Now, the
            > character {, [ works fine.
            > But when I type (, vim can't automatically append ) for me. Instead,
            > the plugin acp or neocomplcache(I am not sure which one) take effect,
            > and pops up a menu to choose the item. I doubt that some plugin of
            > vim has affect inoremap of ( .

            If when you type '(' some other plugin takes effect, why wouldn't you
            think it affected the inoremap? Plugins use the same mechanisms you're
            using (:inoremap, etc.). That's probably what's happening.

            First, try:

            :imap (
            :map (

            To see if there are any mappings defined for '('. (My guess is that
            there's at least one.)

            Then, try running Vim with the --noplugin flag, and see if any are still
            there. Or even if not, just to see if that clears up the problem.

            If one of those plugins defines a mapping, there's certainly a way to disable
            it. Depends on how the plugin sets it up, though, what the best way
            will be. (modifying the plugin directly, moving your mappings to an
            'after' file [see: :help after-directory], moving your mappings to an
            autocmd.)

            --
            Best,
            Ben

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          Your message has been successfully submitted and would be delivered to recipients shortly.