Question

I currently have my .vimrc set up so that

  • s saves my file
  • d deletes any text that is highlighted in visual mode
  • c will comment any line the cursor is on (or any group of highlighted lines)

so obviously this prevents me from using Surround's default commands. Is there a way I can make my own commands in .vimrc to replace Surround's default ones?

Here is my .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
Was it helpful?

Solution

If you take a look at the source for the surround plugin you'll notice the following block:

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

As you can see, you can prevent the plugin from mapping anything by adding the following to your .vimrc:

let g:surround_no_mappings = 1

Then you can add your own mappings for the functions defined in these blocks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top