无论如何改变VIM Surround的键映射?

时间:2013-07-08 22:42:06

标签: vim vim-plugin surround

我目前已设置.vimrc以便

  • s保存我的文件
  • d删除以可视模式突出显示的任何文字
  • c将评论光标所在的任何行(或任何突出显示的行组)

很明显,这阻止了我使用Surround的默认命令。有没有办法可以在.vimrc中创建自己的命令来替换Surround的默认命令?

这是我的.vimrc

set nocompatible

filetype off  " required!

set rtp+=~/.vim/bundle/vundle
call vundle#rc()

" let Vundle manage Vundle
" required! 
Bundle 'gmarik/vundle'

" My Bundles here:
"
" original repos on github
Bundle 'tpope/vim-fugitive'
Bundle 'jistr/vim-nerdtree-tabs'
" Bundle 'tpope/vim-haml'
Bundle 'ap/vim-css-color'
Bundle 'Lokaltog/vim-easymotion'
Bundle 'rstacruz/sparkup', {'rtp': 'vim/'}
Bundle "pangloss/vim-javascript"
" vim-scripts repos
Bundle 'surround.vim'
Bundle 'delimitMate.vim'
Bundle 'hail2u/vim-css3-syntax'
" Bundle 'AutoComplPop'
" Bundle 'ervandew/supertab'
Bundle 'snipMate'
Bundle 'tComment'
" Bundle 'mru.vim'
Bundle 'scrooloose/nerdtree'
Bundle 'matchit.zip'
Bundle 'Vimball'
Bundle 'ScrollColors'
Bundle 'L9'
Bundle 'FuzzyFinder'
" non github repos
Bundle 'git://git.wincent.com/command-t.git'

" Shortcuts

" Basic pair completion
" inoremap {      {}<Left>
" inoremap {<CR>  {<CR>}<Esc>O
" inoremap {{     {
" inoremap {}     {}

" inoremap :      :;<Left>
"inoremap :<CR>  :;
"noremap ::     :;<Left>
"inoremap :;     :;   

" Create new buffers vertically or horizontally 
nnoremap ,v <C-w>v
nnoremap ,h <C-w>s

" Toggle between the buffers
nnoremap ,, <C-w>w

" Increase or decrease buffer size
noremap <C-Up> <C-W>+
noremap <C-Down> <C-W>-
noremap <C-Left> <C-W>>
noremap <C-Right> <C-W><


nmap gf <S-g>
nmap f :FufFile <CR>
vmap c gc 
nmap c gcc
nmap tt :tabnew <CR>
nmap tc :tabclose <CR>
nmap ml :MRU <CR>
nmap ,n :NERDTree <CR>;
nmap s :w! <CR>
nmap q :q! <CR>
syntax on
set mouse=a "enables mouse

" map <F2> :NERDTreeToggle<CR>;
map <F2> :NERDTreeTabsToggle<CR>;

" Selecting different color schemes
map <silent> ,3 :NEXTCOLOR<cr>
map <silent> ,2 :PREVCOLOR<cr>
map <silent> ,1 :SCROLL<cr>

" Directory Set up

set backup "backs up files
set backupdir=$HOME/.vimbackup
set directory=$HOME/.vimswap
set viewdir=$HOME/.vimviews
"
" silent execute '!mkdir -p $HOME/.vimbackup'
" silent execute '!mkdir -p $HOME/.vimswap'
" silent execute '!mkdir -p $HOME/.vimviews'

" au BufWinLeave * silent! mkview "makes vim save view state
" au BufWinEnter * silent! loadview "makes vim load view state

" Appearance

set columns=60

set guifont=Monaco\ 11

if has("autocmd")
  au InsertEnter * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape ibeam"
  au InsertLeave * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape block"
  au VimLeave * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape ibeam"
endif

" set guicursor=n-v-c:block-Cursor
" set guicursor+=i:ver100-iCursor
" set guicursor+=n-v-c:blinkon0
" set guicursor+=i:blinkwait10

if has("gui_running") 
  set guioptions=aiA " Disable toolbar, menu bar, scroll bars 
  colorscheme jellybeans
else
  colorscheme desert256
endif " has("gui_running") 

set t_Co=256
set tabpagemax=10 "show only 10 tabs
set background=dark

set number

set scrolloff=3 "minimum lines to keep above/below cursor
set foldenable "auto fold code
set foldmethod=manual 

" Behaviour
" set nowrap "wrap long lines
set linebreak
:filetype plugin indent on  " lets filetype plugins be used

" Treat SCSS files as CSS files
" au BufRead,BufNewFile *.scss set filetype=css

" Close VIM even if NERDTree is the last buffer 
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif

" after appending closing delimiter, it indents
let delimitMate_expand_cr=1

" if bufwinnr(1)
"   map <kPlus><C-W>+
"   map <kMinus><C-W>-  
"   map <kDivide><c-w><
"   map <kMultiply><c-w>>
" endif

set autoindent
set smartindent                                
set tabstop=2
set shiftwidth=2
set smarttab
set expandtab
set softtabstop=2
set spell

set showmatch "shows matching parens, brackets

set winminheight=0

set go-=T "eliminates tool bar in gVim
set go-=m "eliminates menu bar in gVim
set go-=r "eliminates right scroll bar
set lines=50 "50 lines of text instead of 24

set backspace=2 "makes backspace work like normally it does
:fixdel

set vb t_vb= "prevents vim from beeping when command is bad. instead it flashes screen.            

set ruler "shows statusline, displays curor position

set incsearch "vim searches text as you enter it
" set hlsearch "hilights searched items
set ignorecase "case insensitive search
set smartcase "case sensetive when using captials
set wildmenu "shows list instead of completing
set wildmode=list:longest,full "command <TAB> completeiton, lists matches,
set virtualedit=all "lets cursor freely roam anywhere like in command mode

1 个答案:

答案 0 :(得分:6)

如果您查看环绕声插件的来源,您会注意到以下块:

if !exists("g:surround_no_mappings") || ! g:surround_no_mappings
  nmap ds  <Plug>Dsurround
  nmap cs  <Plug>Csurround
  nmap ys  <Plug>Ysurround
  nmap yS  <Plug>YSurround
  nmap yss <Plug>Yssurround
  nmap ySs <Plug>YSsurround
  nmap ySS <Plug>YSsurround
  xmap S   <Plug>VSurround
  xmap gS  <Plug>VgSurround
  if !exists("g:surround_no_insert_mappings") || ! g:surround_no_insert_mappings
    if !hasmapto("<Plug>Isurround","i") && "" == mapcheck("<C-S>","i")
      imap    <C-S> <Plug>Isurround
    endif
    imap      <C-G>s <Plug>Isurround
    imap      <C-G>S <Plug>ISurround
  endif
endif

如您所见,您可以通过将以下内容添加到.vimrc来阻止插件映射任何内容:

let g:surround_no_mappings = 1

然后,您可以为这些块中定义的函数添加自己的映射。