Lowercasing and underscoring text in Sublime Text - sublimetext

Hi I wondering how I could make a snippet in Sublime Text for doing this.
selected text:
Lorem Ipsum 200
result (in lowercase):
lorem_ipsum_200

This can be done with a macro. First, however, you'll need to install the Case Conversion plugin via Package Control in order to get the convert_to_snake command.
Open a new file in Sublime (use JSON syntax if you want) with the following contents:
[
{
"command": "lower_case", "args": null
},
{
"command": "convert_to_snake", "args": null
}
]
Save the file in your Packages/User directory (Packages can be located by selecting Preferences -> Browse Packages...) as lower_snake.sublime-macro.
Next, select Preferences -> Key Bindings-User and add the following entry. If the file is empty, surround the keybinding with square brackets [ ].
{ "keys": ["ctrl+alt+shift+l"], "command": "run_macro_file", "args": {"file": "res://Packages/User/lower_snake.sublime-macro"} }
Save the file, highlight the text you want to modify, and press CtrlAltShiftL to run the macro. You can change the keybinding to whatever you want, just make sure it doesn't conflict with anything else on your system.
Good luck!

Related

error msg setting editor preferences, format on save, format on paste for Prettier - unable to write into user settings. How do I correct this, pls?

Installed Prettier. Want to set preferences to format on paste and save but getting error message - unable to write into user settings. Please open the user settings to correct errors/warnings in it and try again.
To format prettier I went into the extension, typed in format and tried to select Format on paste and format on save. That's when the error message appeared. When I check settings, I see this:
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
What can I do?
Follow the steps it might help you:
Open the user settings file by going to Preferences > Settings in the VS Code editor, or by pressing the keyboard shortcut Ctrl+ (on Windows) or Cmd+ (on Mac).
In the Settings editor, find the section for "editor.formatOnPaste" and "editor.formatOnSave". Make sure that these settings are set to true, like this:
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
Check the rest of the file for any syntax errors or warnings. In your case, it looks like there is an extra comma at the end of the "[jsonc]" and "[html]" sections, which is causing the error. Remove the extra comma, and make sure that the file is properly formatted and indented.
Save the changes to the file, and try setting the formatting options again.
This should work now that the syntax errors have been fixed.

Copy file name and path in Sublime

I have tried to find command, plugin or anything that can do this. Essentially I need two keyboard shortcuts. One to copy current file path(only current directory, not file name). Another to copy only file name(with extension eg; "test.txt" ).
You can do this with a simple plugin such as this (see this video on using plugins in Sublime if you're not sure how to put it in place):
import sublime
import sublime_plugin
import os
class CopyFilePathCommand(sublime_plugin.TextCommand):
def run(self, edit, name=False):
path, filename = os.path.split(self.view.file_name())
sublime.set_clipboard(filename if name else path)
self.view.window().status_message(
'Copied file %s' % ("name" if name else "path"))
def is_enabled(self, name=False):
return self.view.file_name() is not None
This implements a command named copy_file_path which will copy the path of the current file to the clipboard by default, switching to copying the name of the file instead if you pass true for the value of the name argument.
A message is displayed in the status bar to tell you which thing was copied, and the command will disable itself for any file that hasn't been saved to disk yet (since it would thus have no path to copy).
Sample key bindings might look something like the following:
{ "keys": ["ctrl+shift+alt+p"], "command": "copy_file_path", "args": {"name": false}},
{ "keys": ["ctrl+shift+alt+f"], "command": "copy_file_path", "args": {"name": true}},

Sublime Text start without opening previous/old files

Sublime text opens, wants to reload old files because they have changed, I reload a few and then it crashes.
Is there a way to start Sublime Text afresh, letting it forget the last files that it had open?
In Sublime Text 3 set hot_exit to false in "Preferences -> Settings-User"
"hot_exit": false
remember_open_files doesn't exist in Sublime Text 3 settings anymore.
Go to Sublime Text
Choose
Preferences >> Settings-User
Add the code below to the current settings. (Remember to add a comma at the end of the first line if it doesn’t) and save it.
{
"remember_open_files": false,
"hot_exit": false,
}

Hide files with certain extension in Sublime Text Editor?

is it possible to hide all the files with certain extension from the sidebar (lateral nav bar) in Sublime Text Editor 3?
Are you talking about the sidebar? For example, if you select File → Open and select a folder, then the folder and its contents are displayed along the left side, allowing you to navigate amongst its contents and sub-directories. If that is the case, then the answer is yes, files can be excluded.
Select Preferences → Settings – Default to open a tab called Preferences.sublime-settings – Default. This file is read-only, so you'll also need to open Preferences → Settings – User. The first time you open your user preferences it will be blank. It (and all Sublime config files) are in the JSON format, so you'll need opening and closing curly braces at the beginning and end of the file, respectively:
{
}
Activate the default preferences tab and search for file_exclude_patterns (which is on line 377 in ST3 build 3083) and also folder_exclude_patterns if desired. Copy its contents to your user preferences file, like so:
{
"file_exclude_patterns": ["*.pyc", "*.pyo", "*.exe", "*.dll", "*.obj","*.o", "*.a", "*.lib", "*.so", "*.dylib", "*.ncb", "*.sdf", "*.suo", "*.pdb", "*.idb", ".DS_Store", "*.class", "*.psd", "*.db", "*.sublime-workspace"]
}
and feel free to add your own customizations. Please note that there is no comma (,) after the closing square bracket, as in this example this is the only customized preference. If you have multiple ones (changing fonts, window options, themes, or whatever) you'll need a comma after each item except the last one (trailing commas are illegal JSON):
{
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
"word_wrap": true,
"wrap_width": 0
}
You can also set them up per project and ignore folders, in your .sublime-project file, e.g.:
{
"folders": [{
"path": ".",
"folder_exclude_patterns": [".svn", "._d", ".metadata", ".settings"],
"file_exclude_patterns": ["*.pyc", "*.pyo", ".project"]
}]
}

How to record a macro in sublime text 2?

I am using sublime text 2 and want to record a macro for uploading the current file vie transmit docsend (super+u) and saving it locally (super+s).
So I start to record a macro ctrl+q and see the status notification in the footer
Starting to record macro ...
Then I hit super+s and it saves and the upload it vie super+u. After hitting ctrl+q for stopping macrorecording the footer says
Stopping recording macro
But I do not have the Option in the menu "Tools/Playback macro" and when I hit save Macro it doesnt do anything.
Any Idea?
PS: I am working on OS X and I have no directory
/Library/Application\ Support/Sublime\ Text\ 2
Have I to create it as admin?
Thanks a lot
Now I realized that I dont need the folder /Library... but ~/Library...
But after saving the File ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/transmit-upload-and-save.sublime-macro
[
{"command": "save"},
{"command": "transmit_docksend"}
]
and adding the following to user shortcuts
[
{ "keys": ["super+u"], "command": "run_macro_file", "args": {"file": "Packages/User/transmit-upload-and-save.sublime-macro"} }
]
it does not save but uploads ... whats wrong?
To simply playback last recorded Macro press Ctrl+Shift+q.
In Sublime Text2 Macros are not saved to file by default they reside in the macro buffer instead. More here
The reason it's uploading is because your key is only defined as [super+u] which is for upload - it should be [super+s] for save.
Hope that helps

Resources