regex - Sublime Text macro to find and replace file path characters on current line -


i use sublime 2 developing r , php code, although imagine shortcut useful other languages.

if copy path of file windows explorer / xyplorer (or other source) has backslashes directories. when entering path source code, needs forward slashes.

sublime has reasonably powerful macro commands, cannot think of combination able to:

  • take string of text on current line
  • replace instances of '\' , replace them '/'

here workflow envisage:

  1. locate filename in explorer , copy path
  2. in sublime, write line of code , paste in path
  3. hit keyboard shortcut, ctrl+shift+\, , slashes converted forward slashes

the result:

mypath = "e:\work\code\myfile.csv"; 

becomes:

mypath = "e:/work/code/myfile.csv"; 

without running risk of backslashes elsewhere in file being changed (e.g. \n characters), , without having use multiple key presses or mouse clicks.

i imagine possible regex. 2 things no expert in sublime macros or regex, wonder if else knows magical commands achieve this?

i tried 15 minutes. few things:

  1. sublime text 2 doesn't allow find/replace macros
  2. sublime text 3 doesn't allow 'find in selection'

so, think kind of beat right other writing plugin, straightforward.


Comments