{"id":242275,"date":"2016-06-07T06:30:34","date_gmt":"2016-06-07T13:30:34","guid":{"rendered":"http:\/\/css-tricks.com\/?p=242275"},"modified":"2016-06-13T09:33:25","modified_gmt":"2016-06-13T16:33:25","slug":"run-multiple-find-replace-commands-sublime-text","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/run-multiple-find-replace-commands-sublime-text\/","title":{"rendered":"Run Multiple Find & Replace Commands in Sublime Text"},"content":{"rendered":"

I run Find & Replace commands a lot. Sometimes I’m changing a class name. Sometimes I’m looking for a function reference and want to make sure all instances have been accounted for. Sometimes I’m working on an article and and some conversion process requires some global changes. I’ve often wished I could run a single command to run all the Find & Replace commands I normally have to do individually. I finally web searched my way through a solution so figured I’d write it down.<\/p>\n

<\/p>\n

Install the RegReplace Package<\/h3>\n

There is no way to do this directly within Sublime Text, so we’ll need a little help. RegReplace<\/a> works very nicely for this. <\/p>\n

Package control is typically the easiest way to do this kind of thing:<\/p>\n

\"\"<\/figure>\n

Edit the User Settings<\/h3>\n
\"\"<\/figure>\n

The settings for this package is where you define all the find & replace commands you want to be able to call. You add new objects to the replacements section in the JSON. It’s fairly self explanitory. Here’s two I added that I’ll want to be running together:<\/p>\n

{\r\n  \"replacements\": {\r\n    \"remove_opening_ps\": {\r\n      \"find\": \"<p>\",\r\n      \"replace\": \"\",\r\n      \"greedy\": true,\r\n      \"case\": false\r\n    },\r\n    \"remove_closing_ps\": {\r\n      \"find\": \"<\/p>\",\r\n      \"replace\": \"\",\r\n      \"greedy\": true,\r\n      \"case\": false\r\n    }\r\n  }\r\n}<\/code><\/pre>\n

Edit the User Commands<\/h3>\n
\"\"<\/figure>\n

The find & replace chunks we set up don’t do anything by themselves, we need to attach them to a command. This chunk of config is an array of commands we can add to. We could call our two new find\/replace bits in a single command we create, like this:<\/p>\n

[\r\n  {\r\n    \"caption\": \"Reg Replace: Remove All P's\",\r\n    \"command\": \"reg_replace\",\r\n    \"args\": {\r\n      \"replacements\": [\r\n        \"remove_opening_ps\",\r\n        \"remove_closing_ps\"\r\n      ]\r\n    }\r\n  },\r\n]<\/code><\/pre>\n

You can name the command (the caption) whatever you want. It then becomes available as a command to run.<\/p>\n

Run the new command!<\/h3>\n

Easy cheesy.<\/p>\n

\"\"<\/figure>\n","protected":false},"excerpt":{"rendered":"

I run Find & Replace commands a lot. Sometimes I’m changing a class name. Sometimes I’m looking for a function reference and want to make sure all instances have been accounted for. Sometimes I’m working on an article and and some conversion process requires some global changes. I’ve often wished I could run a single […]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[4],"tags":[756,755],"jetpack_publicize_connections":[],"acf":[],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":189015,"url":"https:\/\/css-tricks.com\/sublime-text-front-end-developers\/","url_meta":{"origin":242275,"position":0},"title":"Sublime Text for Front End Developers","date":"November 24, 2014","format":false,"excerpt":"The following is a guest post by Wes Bos. Wes has been writing about Sublime Text and all the great stuff it brings to code editing for a while now. He has a new book and video package out now: Sublime Text Power User. I met him at a conference\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":270523,"url":"https:\/\/css-tricks.com\/turn-sublime-text-3-into-a-javascript-ide\/","url_meta":{"origin":242275,"position":1},"title":"Turn Sublime Text 3 into a JavaScript IDE","date":"May 11, 2018","format":false,"excerpt":"Sublime Text is one of the most popular editors for web development and software development in general. It\u2019s very smooth and fast compared to other editors (being written in C++ helps that speed). Sublime also has tons of plugins you can find through Package Control. But it\u2019s only a text\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2018\/05\/sublime-text-logo.jpg?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":341298,"url":"https:\/\/css-tricks.com\/to-or-not-to-displaying-terminal-code-snippets\/","url_meta":{"origin":242275,"position":2},"title":"To $ or Not to $: Displaying Terminal Code Snippets","date":"May 27, 2021","format":false,"excerpt":"It's very popular to put a $ on lines that are intended to be a command in code documentation that involves the terminal (i.e. the command line). Like this: $ brew install somepackage The point of that is that it mimics the prompt that you (may) see on your command\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2021\/05\/CleanShot-2021-05-24-at-11.55.07@2x.png?fit=1200%2C573&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":361320,"url":"https:\/\/css-tricks.com\/what-the-heck-are-npm-commands\/","url_meta":{"origin":242275,"position":3},"title":"What the Heck Are npm Commands?","date":"January 20, 2022","format":false,"excerpt":"npm is, as you now know, a package manager. But like similar, earlier tools that run tasks in the command line, such as Grunt and Gulp, npm can also run tasks\u2014which is perfect for us because now that we installed the Sass package in the previous chapter, we can starting\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2022\/01\/s_AF038BF04094A70509D67F40885F11F49B56FA082F53552BB58B184DA068C273_1638416625430_01-43-wvtkv-5cnvv.png?fit=1200%2C883&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":319881,"url":"https:\/\/css-tricks.com\/one-action-multiple-terminal-windows-running-stuff\/","url_meta":{"origin":242275,"position":4},"title":"One Action, Multiple Terminal Windows Running Stuff","date":"September 8, 2020","format":false,"excerpt":"Many development environments require running things in a terminal window. npm run start, or whatever. I know my biggest project requires me to be running a big fancy Docker-based thing in one terminal, Ruby on Rails in another, and webpack in another. I've worked on other projects that require multiple\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2020\/09\/terminal-windows.jpg?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":338855,"url":"https:\/\/css-tricks.com\/text-that-sometimes-turns-to-emojis\/","url_meta":{"origin":242275,"position":5},"title":"Text That Sometimes Turns to Emojis","date":"April 22, 2021","format":false,"excerpt":"There are some Unicode characters that some browsers just decide they are going to turn into emojis for you. I couldn't tell you why exactly, but here's what I see: Chrome on the left. Safari in the simulator on top and to the right. Those text Unicode characters (\u25b6, \u21a9,\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/css-tricks.com\/wp-content\/uploads\/2018\/05\/emoji-trio.jpg?fit=1200%2C600&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]}],"featured_media_src_url":null,"_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/242275"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=242275"}],"version-history":[{"count":5,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/242275\/revisions"}],"predecessor-version":[{"id":242821,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/posts\/242275\/revisions\/242821"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=242275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/categories?post=242275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=242275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}