vim下一键替换中文标点

作为码农无法接受中文标点,遂一怒之下写了个vim脚本,一键替换中文标点为英文标点.
将下面的代码拷贝到你的vimrc,在normal mode下按下Ctrl + S,完成替换.
(中途参照了cold night的代码)

点击(此处)折叠或打开

  1. "ctrl-s将中文标点换为英文标点
  2. function! ChangeChineseMark()
  3. if search(\'。\')
  4. execute \"1,$s/。/\\./g\"
  5. endif
  6. if search(\',\')
  7. execute \"1,$s/,/,/g\"
  8. endif
  9. if search(\';\')
  10. execute \"1,$s/;/,/g\"
  11. endif
  12. if search(\'?\')
  13. execute \"1,$s/?/?/g\"
  14. endif
  15. if search(\':\')
  16. execute \"1,$s/:/\\:/g\"
  17. endif
  18. if search(\'‘\')
  19. execute \"1,$s/‘/\\\'/g\"
  20. endif
  21. if search(\'’\')
  22. execute \"1,$s/’/\\\'/g\"
  23. endif
  24. if search(\'”\')
  25. execute \"1,$s/”/\\\"/g\"
  26. endif
  27. if search(\'“\')
  28. execute \"1,$s/“/\\\"/g\"
  29. endif
  30. if search(\'《\')
  31. execute \"1,$s/《/\\
  32. endif
  33. if search(\'》\')
  34. execute \"1,$s/》/\\>/g\"
  35. endif
  36. if search(\'—\')
  37. execute \"1,$s/——/-/g\"
  38. endif
  39. if search(\')\')
  40. execute \"1,$s/)/\\)/g\"
  41. endif
  42. if search(\'(\')
  43. execute \"1,$s/(/\\(/g\"
  44. endif
  45. if search(\'…\')
  46. execute \"1,$s/……/^/g\"
  47. endif
  48. if search(\'¥\')
  49. execute \"1,$s/¥/$/g\"
  50. endif
  51. if search(\'!\')
  52. execute \"1,$s/!/!/g\"
  53. endif
  54. if search(\'·\')
  55. execute \"1,$s/·/`/g\"
  56. endif
  57. if search(\'、\')
  58. execute \"1,$s/、/,/g\"
  59. endif
  60. endfunction
  61. noremap :call ChangeChineseMark()

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30156807/viewspace-1657810/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/30156807/viewspace-1657810/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值