surround.vim 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. " surround.vim - Surroundings
  2. " Author: Tim Pope <http://tpo.pe/>
  3. " Version: 2.2
  4. " GetLatestVimScripts: 1697 1 :AutoInstall: surround.vim
  5. if exists("g:loaded_surround") || &cp || v:version < 700
  6. finish
  7. endif
  8. let g:loaded_surround = 1
  9. " Input functions {{{1
  10. function! s:getchar()
  11. let c = getchar()
  12. if c =~ '^\d\+$'
  13. let c = nr2char(c)
  14. endif
  15. return c
  16. endfunction
  17. function! s:inputtarget()
  18. let c = s:getchar()
  19. while c =~ '^\d\+$'
  20. let c .= s:getchar()
  21. endwhile
  22. if c == " "
  23. let c .= s:getchar()
  24. endif
  25. if c =~ "\<Esc>\|\<C-C>\|\0"
  26. return ""
  27. else
  28. return c
  29. endif
  30. endfunction
  31. function! s:inputreplacement()
  32. let c = s:getchar()
  33. if c == " "
  34. let c .= s:getchar()
  35. endif
  36. if c =~ "\<Esc>" || c =~ "\<C-C>"
  37. return ""
  38. else
  39. return c
  40. endif
  41. endfunction
  42. function! s:beep()
  43. exe "norm! \<Esc>"
  44. return ""
  45. endfunction
  46. function! s:redraw()
  47. redraw
  48. return ""
  49. endfunction
  50. " }}}1
  51. " Wrapping functions {{{1
  52. function! s:extractbefore(str)
  53. if a:str =~ '\r'
  54. return matchstr(a:str,'.*\ze\r')
  55. else
  56. return matchstr(a:str,'.*\ze\n')
  57. endif
  58. endfunction
  59. function! s:extractafter(str)
  60. if a:str =~ '\r'
  61. return matchstr(a:str,'\r\zs.*')
  62. else
  63. return matchstr(a:str,'\n\zs.*')
  64. endif
  65. endfunction
  66. function! s:fixindent(str,spc)
  67. let str = substitute(a:str,'\t',repeat(' ',&sw),'g')
  68. let spc = substitute(a:spc,'\t',repeat(' ',&sw),'g')
  69. let str = substitute(str,'\(\n\|\%^\).\@=','\1'.spc,'g')
  70. if ! &et
  71. let str = substitute(str,'\s\{'.&ts.'\}',"\t",'g')
  72. endif
  73. return str
  74. endfunction
  75. function! s:process(string)
  76. let i = 0
  77. for i in range(7)
  78. let repl_{i} = ''
  79. let m = matchstr(a:string,nr2char(i).'.\{-\}\ze'.nr2char(i))
  80. if m != ''
  81. let m = substitute(strpart(m,1),'\r.*','','')
  82. let repl_{i} = input(match(m,'\w\+$') >= 0 ? m.': ' : m)
  83. endif
  84. endfor
  85. let s = ""
  86. let i = 0
  87. while i < strlen(a:string)
  88. let char = strpart(a:string,i,1)
  89. if char2nr(char) < 8
  90. let next = stridx(a:string,char,i+1)
  91. if next == -1
  92. let s .= char
  93. else
  94. let insertion = repl_{char2nr(char)}
  95. let subs = strpart(a:string,i+1,next-i-1)
  96. let subs = matchstr(subs,'\r.*')
  97. while subs =~ '^\r.*\r'
  98. let sub = matchstr(subs,"^\r\\zs[^\r]*\r[^\r]*")
  99. let subs = strpart(subs,strlen(sub)+1)
  100. let r = stridx(sub,"\r")
  101. let insertion = substitute(insertion,strpart(sub,0,r),strpart(sub,r+1),'')
  102. endwhile
  103. let s .= insertion
  104. let i = next
  105. endif
  106. else
  107. let s .= char
  108. endif
  109. let i += 1
  110. endwhile
  111. return s
  112. endfunction
  113. function! s:wrap(string,char,type,removed,special)
  114. let keeper = a:string
  115. let newchar = a:char
  116. let s:input = ""
  117. let type = a:type
  118. let linemode = type ==# 'V' ? 1 : 0
  119. let before = ""
  120. let after = ""
  121. if type ==# "V"
  122. let initspaces = matchstr(keeper,'\%^\s*')
  123. else
  124. let initspaces = matchstr(getline('.'),'\%^\s*')
  125. endif
  126. let pairs = "b()B{}r[]a<>"
  127. let extraspace = ""
  128. if newchar =~ '^ '
  129. let newchar = strpart(newchar,1)
  130. let extraspace = ' '
  131. endif
  132. let idx = stridx(pairs,newchar)
  133. if newchar == ' '
  134. let before = ''
  135. let after = ''
  136. elseif exists("b:surround_".char2nr(newchar))
  137. let all = s:process(b:surround_{char2nr(newchar)})
  138. let before = s:extractbefore(all)
  139. let after = s:extractafter(all)
  140. elseif exists("g:surround_".char2nr(newchar))
  141. let all = s:process(g:surround_{char2nr(newchar)})
  142. let before = s:extractbefore(all)
  143. let after = s:extractafter(all)
  144. elseif newchar ==# "p"
  145. let before = "\n"
  146. let after = "\n\n"
  147. elseif newchar ==# 's'
  148. let before = ' '
  149. let after = ''
  150. elseif newchar ==# ':'
  151. let before = ':'
  152. let after = ''
  153. elseif newchar =~# "[tT\<C-T><]"
  154. let dounmapp = 0
  155. let dounmapb = 0
  156. if !maparg(">","c")
  157. let dounmapb = 1
  158. " Hide from AsNeeded
  159. exe "cn"."oremap > ><CR>"
  160. endif
  161. let default = ""
  162. if newchar ==# "T"
  163. if !exists("s:lastdel")
  164. let s:lastdel = ""
  165. endif
  166. let default = matchstr(s:lastdel,'<\zs.\{-\}\ze>')
  167. endif
  168. let tag = input("<",default)
  169. if dounmapb
  170. silent! cunmap >
  171. endif
  172. let s:input = tag
  173. if tag != ""
  174. let keepAttributes = ( match(tag, ">$") == -1 )
  175. let tag = substitute(tag,'>*$','','')
  176. let attributes = ""
  177. if keepAttributes
  178. let attributes = matchstr(a:removed, '<[^ \t\n]\+\zs\_.\{-\}\ze>')
  179. endif
  180. let s:input = tag . '>'
  181. if tag =~ '/$'
  182. let tag = substitute(tag, '/$', '', '')
  183. let before = '<'.tag.attributes.' />'
  184. let after = ''
  185. else
  186. let before = '<'.tag.attributes.'>'
  187. let after = '</'.substitute(tag,' .*','','').'>'
  188. endif
  189. if newchar == "\<C-T>"
  190. if type ==# "v" || type ==# "V"
  191. let before .= "\n\t"
  192. endif
  193. if type ==# "v"
  194. let after = "\n". after
  195. endif
  196. endif
  197. endif
  198. elseif newchar ==# 'l' || newchar == '\'
  199. " LaTeX
  200. let env = input('\begin{')
  201. if env != ""
  202. let s:input = env."\<CR>"
  203. let env = '{' . env
  204. let env .= s:closematch(env)
  205. echo '\begin'.env
  206. let before = '\begin'.env
  207. let after = '\end'.matchstr(env,'[^}]*').'}'
  208. endif
  209. elseif newchar ==# 'f' || newchar ==# 'F'
  210. let fnc = input('function: ')
  211. if fnc != ""
  212. let s:input = fnc."\<CR>"
  213. let before = substitute(fnc,'($','','').'('
  214. let after = ')'
  215. if newchar ==# 'F'
  216. let before .= ' '
  217. let after = ' ' . after
  218. endif
  219. endif
  220. elseif newchar ==# "\<C-F>"
  221. let fnc = input('function: ')
  222. let s:input = fnc."\<CR>"
  223. let before = '('.fnc.' '
  224. let after = ')'
  225. elseif idx >= 0
  226. let spc = (idx % 3) == 1 ? " " : ""
  227. let idx = idx / 3 * 3
  228. let before = strpart(pairs,idx+1,1) . spc
  229. let after = spc . strpart(pairs,idx+2,1)
  230. elseif newchar == "\<C-[>" || newchar == "\<C-]>"
  231. let before = "{\n\t"
  232. let after = "\n}"
  233. elseif newchar !~ '\a'
  234. let before = newchar
  235. let after = newchar
  236. else
  237. let before = ''
  238. let after = ''
  239. endif
  240. let after = substitute(after ,'\n','\n'.initspaces,'g')
  241. if type ==# 'V' || (a:special && type ==# "v")
  242. let before = substitute(before,' \+$','','')
  243. let after = substitute(after ,'^ \+','','')
  244. if after !~ '^\n'
  245. let after = initspaces.after
  246. endif
  247. if keeper !~ '\n$' && after !~ '^\n'
  248. let keeper .= "\n"
  249. elseif keeper =~ '\n$' && after =~ '^\n'
  250. let after = strpart(after,1)
  251. endif
  252. if keeper !~ '^\n' && before !~ '\n\s*$'
  253. let before .= "\n"
  254. if a:special
  255. let before .= "\t"
  256. endif
  257. elseif keeper =~ '^\n' && before =~ '\n\s*$'
  258. let keeper = strcharpart(keeper,1)
  259. endif
  260. if type ==# 'V' && keeper =~ '\n\s*\n$'
  261. let keeper = strcharpart(keeper,0,strchars(keeper) - 1)
  262. endif
  263. endif
  264. if type ==# 'V'
  265. let before = initspaces.before
  266. endif
  267. if before =~ '\n\s*\%$'
  268. if type ==# 'v'
  269. let keeper = initspaces.keeper
  270. endif
  271. let padding = matchstr(before,'\n\zs\s\+\%$')
  272. let before = substitute(before,'\n\s\+\%$','\n','')
  273. let keeper = s:fixindent(keeper,padding)
  274. endif
  275. if type ==# 'V'
  276. let keeper = before.keeper.after
  277. elseif type =~ "^\<C-V>"
  278. " Really we should be iterating over the buffer
  279. let repl = substitute(before,'[\\~]','\\&','g').'\1'.substitute(after,'[\\~]','\\&','g')
  280. let repl = substitute(repl,'\n',' ','g')
  281. let keeper = substitute(keeper."\n",'\(.\{-\}\)\(\n\)',repl.'\n','g')
  282. let keeper = substitute(keeper,'\n\%$','','')
  283. else
  284. let keeper = before.extraspace.keeper.extraspace.after
  285. endif
  286. return keeper
  287. endfunction
  288. function! s:wrapreg(reg,char,removed,special)
  289. let orig = getreg(a:reg)
  290. let type = substitute(getregtype(a:reg),'\d\+$','','')
  291. let new = s:wrap(orig,a:char,type,a:removed,a:special)
  292. call setreg(a:reg,new,type)
  293. endfunction
  294. " }}}1
  295. function! s:insert(...) " {{{1
  296. " Optional argument causes the result to appear on 3 lines, not 1
  297. let linemode = a:0 ? a:1 : 0
  298. let char = s:inputreplacement()
  299. while char == "\<CR>" || char == "\<C-S>"
  300. " TODO: use total count for additional blank lines
  301. let linemode += 1
  302. let char = s:inputreplacement()
  303. endwhile
  304. if char == ""
  305. return ""
  306. endif
  307. let cb_save = &clipboard
  308. set clipboard-=unnamed clipboard-=unnamedplus
  309. let reg_save = @@
  310. call setreg('"',"\032",'v')
  311. call s:wrapreg('"',char,"",linemode)
  312. " If line mode is used and the surrounding consists solely of a suffix,
  313. " remove the initial newline. This fits a use case of mine but is a
  314. " little inconsistent. Is there anyone that would prefer the simpler
  315. " behavior of just inserting the newline?
  316. if linemode && match(getreg('"'),'^\n\s*\zs.*') == 0
  317. call setreg('"',matchstr(getreg('"'),'^\n\s*\zs.*'),getregtype('"'))
  318. endif
  319. " This can be used to append a placeholder to the end
  320. if exists("g:surround_insert_tail")
  321. call setreg('"',g:surround_insert_tail,"a".getregtype('"'))
  322. endif
  323. if &ve != 'all' && col('.') >= col('$')
  324. if &ve == 'insert'
  325. let extra_cols = virtcol('.') - virtcol('$')
  326. if extra_cols > 0
  327. let [regval,regtype] = [getreg('"',1,1),getregtype('"')]
  328. call setreg('"',join(map(range(extra_cols),'" "'),''),'v')
  329. norm! ""p
  330. call setreg('"',regval,regtype)
  331. endif
  332. endif
  333. norm! ""p
  334. else
  335. norm! ""P
  336. endif
  337. if linemode
  338. call s:reindent()
  339. endif
  340. norm! `]
  341. call search("\032",'bW')
  342. let @@ = reg_save
  343. let &clipboard = cb_save
  344. return "\<Del>"
  345. endfunction " }}}1
  346. function! s:reindent() abort " {{{1
  347. if get(b:, 'surround_indent', get(g:, 'surround_indent', 1)) && (!empty(&equalprg) || !empty(&indentexpr) || &cindent || &smartindent || &lisp)
  348. silent norm! '[=']
  349. endif
  350. endfunction " }}}1
  351. function! s:dosurround(...) " {{{1
  352. let sol_save = &startofline
  353. set startofline
  354. let scount = v:count1
  355. let char = (a:0 ? a:1 : s:inputtarget())
  356. let spc = ""
  357. if char =~ '^\d\+'
  358. let scount = scount * matchstr(char,'^\d\+')
  359. let char = substitute(char,'^\d\+','','')
  360. endif
  361. if char =~ '^ '
  362. let char = strpart(char,1)
  363. let spc = 1
  364. endif
  365. if char == 'a'
  366. let char = '>'
  367. endif
  368. if char == 'r'
  369. let char = ']'
  370. endif
  371. let newchar = ""
  372. if a:0 > 1
  373. let newchar = a:2
  374. if newchar == "\<Esc>" || newchar == "\<C-C>" || newchar == ""
  375. if !sol_save
  376. set nostartofline
  377. endif
  378. return s:beep()
  379. endif
  380. endif
  381. let cb_save = &clipboard
  382. set clipboard-=unnamed clipboard-=unnamedplus
  383. let append = ""
  384. let original = getreg('"')
  385. let otype = getregtype('"')
  386. call setreg('"',"")
  387. let strcount = (scount == 1 ? "" : scount)
  388. if char == '/'
  389. exe 'norm! '.strcount.'[/d'.strcount.']/'
  390. elseif char =~# '[[:punct:][:space:]]' && char !~# '[][(){}<>"''`]'
  391. exe 'norm! T'.char
  392. if getline('.')[col('.')-1] == char
  393. exe 'norm! l'
  394. endif
  395. exe 'norm! dt'.char
  396. else
  397. exe 'norm! d'.strcount.'i'.char
  398. endif
  399. let keeper = getreg('"')
  400. let okeeper = keeper " for reindent below
  401. if keeper == ""
  402. call setreg('"',original,otype)
  403. let &clipboard = cb_save
  404. if !sol_save
  405. set nostartofline
  406. endif
  407. return ""
  408. endif
  409. let oldline = getline('.')
  410. let oldlnum = line('.')
  411. if char ==# "p"
  412. call setreg('"','','V')
  413. elseif char ==# "s" || char ==# "w" || char ==# "W"
  414. " Do nothing
  415. call setreg('"','')
  416. elseif char =~ "[\"'`]"
  417. exe "norm! i \<Esc>d2i".char
  418. call setreg('"',substitute(getreg('"'),' ','',''))
  419. elseif char == '/'
  420. norm! "_x
  421. call setreg('"','/**/',"c")
  422. let keeper = substitute(substitute(keeper,'^/\*\s\=','',''),'\s\=\*$','','')
  423. elseif char =~# '[[:punct:][:space:]]' && char !~# '[][(){}<>]'
  424. exe 'norm! F'.char
  425. exe 'norm! df'.char
  426. else
  427. " One character backwards
  428. call search('\m.', 'bW')
  429. exe "norm! da".char
  430. endif
  431. let removed = getreg('"')
  432. let rem2 = substitute(removed,'\n.*','','')
  433. let oldhead = strpart(oldline,0,strlen(oldline)-strlen(rem2))
  434. let oldtail = strpart(oldline, strlen(oldline)-strlen(rem2))
  435. let regtype = getregtype('"')
  436. if char =~# '[\[({<T]' || spc
  437. let keeper = substitute(keeper,'^\s\+','','')
  438. let keeper = substitute(keeper,'\s\+$','','')
  439. endif
  440. if col("']") == col("$") && virtcol('.') + 1 == virtcol('$')
  441. if oldhead =~# '^\s*$' && a:0 < 2
  442. let keeper = substitute(keeper,'\%^\n'.oldhead.'\(\s*.\{-\}\)\n\s*\%$','\1','')
  443. endif
  444. let pcmd = "p"
  445. else
  446. let pcmd = "P"
  447. endif
  448. if line('.') + 1 < oldlnum && regtype ==# "V"
  449. let pcmd = "p"
  450. endif
  451. call setreg('"',keeper,regtype)
  452. if newchar != ""
  453. let special = a:0 > 2 ? a:3 : 0
  454. call s:wrapreg('"',newchar,removed,special)
  455. endif
  456. silent exe 'norm! ""'.pcmd.'`['
  457. if removed =~ '\n' || okeeper =~ '\n' || getreg('"') =~ '\n'
  458. call s:reindent()
  459. endif
  460. if getline('.') =~ '^\s\+$' && keeper =~ '^\s*\n'
  461. silent norm! cc
  462. endif
  463. call setreg('"',original,otype)
  464. let s:lastdel = removed
  465. let &clipboard = cb_save
  466. if newchar == ""
  467. silent! call repeat#set("\<Plug>Dsurround".char,scount)
  468. else
  469. silent! call repeat#set("\<Plug>C".(a:0 > 2 && a:3 ? "S" : "s")."urround".char.newchar.s:input,scount)
  470. endif
  471. if !sol_save
  472. set nostartofline
  473. endif
  474. endfunction " }}}1
  475. function! s:changesurround(...) " {{{1
  476. let a = s:inputtarget()
  477. if a == ""
  478. return s:beep()
  479. endif
  480. let b = s:inputreplacement()
  481. if b == ""
  482. return s:beep()
  483. endif
  484. call s:dosurround(a,b,a:0 && a:1)
  485. endfunction " }}}1
  486. function! s:opfunc(type, ...) abort " {{{1
  487. if a:type ==# 'setup'
  488. let &opfunc = matchstr(expand('<sfile>'), '<SNR>\w\+$')
  489. return 'g@'
  490. endif
  491. let char = s:inputreplacement()
  492. if char == ""
  493. return s:beep()
  494. endif
  495. let reg = '"'
  496. let sel_save = &selection
  497. let &selection = "inclusive"
  498. let cb_save = &clipboard
  499. set clipboard-=unnamed clipboard-=unnamedplus
  500. let reg_save = getreg(reg)
  501. let reg_type = getregtype(reg)
  502. let type = a:type
  503. if a:type == "char"
  504. silent exe 'norm! v`[o`]"'.reg.'y'
  505. let type = 'v'
  506. elseif a:type == "line"
  507. silent exe 'norm! `[V`]"'.reg.'y'
  508. let type = 'V'
  509. elseif a:type ==# "v" || a:type ==# "V" || a:type ==# "\<C-V>"
  510. let &selection = sel_save
  511. let ve = &virtualedit
  512. if !(a:0 && a:1)
  513. set virtualedit=
  514. endif
  515. silent exe 'norm! gv"'.reg.'y'
  516. let &virtualedit = ve
  517. elseif a:type =~ '^\d\+$'
  518. let type = 'v'
  519. silent exe 'norm! ^v'.a:type.'$h"'.reg.'y'
  520. if mode() ==# 'v'
  521. norm! v
  522. return s:beep()
  523. endif
  524. else
  525. let &selection = sel_save
  526. let &clipboard = cb_save
  527. return s:beep()
  528. endif
  529. let keeper = getreg(reg)
  530. if type ==# "v" && a:type !=# "v"
  531. let append = matchstr(keeper,'\_s\@<!\s*$')
  532. let keeper = substitute(keeper,'\_s\@<!\s*$','','')
  533. endif
  534. call setreg(reg,keeper,type)
  535. call s:wrapreg(reg,char,"",a:0 && a:1)
  536. if type ==# "v" && a:type !=# "v" && append != ""
  537. call setreg(reg,append,"ac")
  538. endif
  539. silent exe 'norm! gv'.(reg == '"' ? '' : '"' . reg).'p`['
  540. if type ==# 'V' || (getreg(reg) =~ '\n' && type ==# 'v')
  541. call s:reindent()
  542. endif
  543. call setreg(reg,reg_save,reg_type)
  544. let &selection = sel_save
  545. let &clipboard = cb_save
  546. if a:type =~ '^\d\+$'
  547. silent! call repeat#set("\<Plug>Y".(a:0 && a:1 ? "S" : "s")."surround".char.s:input,a:type)
  548. else
  549. silent! call repeat#set("\<Plug>SurroundRepeat".char.s:input)
  550. endif
  551. endfunction
  552. function! s:opfunc2(...) abort
  553. if !a:0 || a:1 ==# 'setup'
  554. let &opfunc = matchstr(expand('<sfile>'), '<SNR>\w\+$')
  555. return 'g@'
  556. endif
  557. call s:opfunc(a:1, 1)
  558. endfunction " }}}1
  559. function! s:closematch(str) " {{{1
  560. " Close an open (, {, [, or < on the command line.
  561. let tail = matchstr(a:str,'.[^\[\](){}<>]*$')
  562. if tail =~ '^\[.\+'
  563. return "]"
  564. elseif tail =~ '^(.\+'
  565. return ")"
  566. elseif tail =~ '^{.\+'
  567. return "}"
  568. elseif tail =~ '^<.+'
  569. return ">"
  570. else
  571. return ""
  572. endif
  573. endfunction " }}}1
  574. nnoremap <silent> <Plug>SurroundRepeat .
  575. nnoremap <silent> <Plug>Dsurround :<C-U>call <SID>dosurround(<SID>inputtarget())<CR>
  576. nnoremap <silent> <Plug>Csurround :<C-U>call <SID>changesurround()<CR>
  577. nnoremap <silent> <Plug>CSurround :<C-U>call <SID>changesurround(1)<CR>
  578. nnoremap <expr> <Plug>Yssurround '^'.v:count1.<SID>opfunc('setup').'g_'
  579. nnoremap <expr> <Plug>YSsurround <SID>opfunc2('setup').'_'
  580. nnoremap <expr> <Plug>Ysurround <SID>opfunc('setup')
  581. nnoremap <expr> <Plug>YSurround <SID>opfunc2('setup')
  582. vnoremap <silent> <Plug>VSurround :<C-U>call <SID>opfunc(visualmode(),visualmode() ==# 'V' ? 1 : 0)<CR>
  583. vnoremap <silent> <Plug>VgSurround :<C-U>call <SID>opfunc(visualmode(),visualmode() ==# 'V' ? 0 : 1)<CR>
  584. inoremap <silent> <Plug>Isurround <C-R>=<SID>insert()<CR>
  585. inoremap <silent> <Plug>ISurround <C-R>=<SID>insert(1)<CR>
  586. if !exists("g:surround_no_mappings") || ! g:surround_no_mappings
  587. nmap ds <Plug>Dsurround
  588. nmap cs <Plug>Csurround
  589. nmap cS <Plug>CSurround
  590. nmap ys <Plug>Ysurround
  591. nmap yS <Plug>YSurround
  592. nmap yss <Plug>Yssurround
  593. nmap ySs <Plug>YSsurround
  594. nmap ySS <Plug>YSsurround
  595. xmap S <Plug>VSurround
  596. xmap gS <Plug>VgSurround
  597. if !exists("g:surround_no_insert_mappings") || ! g:surround_no_insert_mappings
  598. if !hasmapto("<Plug>Isurround","i") && "" == mapcheck("<C-S>","i")
  599. imap <C-S> <Plug>Isurround
  600. endif
  601. imap <C-G>s <Plug>Isurround
  602. imap <C-G>S <Plug>ISurround
  603. endif
  604. endif
  605. " vim:set ft=vim sw=2 sts=2 et: