Is there a way to paste a multi-cursor (Ctrl+d, Ctrl+d, ... Ctrl+C) select, stripped of its newlines?
If [...] represents the highlight, and ⦙ the cursor:
The ⦙[red].
The ⦙[blue].
The ⦙[green].
And if I pasted I'd get:
red
blue
green⦙
but instead I want
redbluegreen⦙
Is this possible?
Save the following script #:
/Packages/Paste Without NewLines/paste_without_newlines.py
import sublime, sublime_plugin
class paste_without_newlines( sublime_plugin.TextCommand ):
def run( self, edit ):
clipboard = sublime.get_clipboard()
clipboard = clipboard.replace( "\n", "" )
sublime.set_clipboard( clipboard )
self.view.run_command( "paste" )
To execute via Command Palette > Paste Without NewLines, add the following code #:
/Packages/Paste Without NewLines/Default.sublime-commands
[
{
"caption": "Paste Without NewLines",
"command": "paste_without_newlines",
},
]
To execute via Ctrl + Shift + Alt + V, add the following code #:
/Packages/Paste Without NewLines/Default.sublime-keymap
[
{
"keys": ["ctrl+shift+alt+v"],
"command": "paste_without_newlines",
},
]
For anyone else stumbling across this, there's a sublime text package that solves this exact problem, it's called Paste PDF Text Block.
You can then Ctrl+Alt+v the text you want to copy from a pdf file into a new file in Sublime Text.
Worked a treat, and is a good solution if you don't know enough about making your own packages in sublime text, like me :(
Related
i have many pieces of code same for example like this
alt="Greece"
alt="Greece"
alt="Greece"
alt="Greece"
Can i somehow modify it to this? Is there any kind of function like in Excel or something like that please? Imagination write it manualy each is horrible
alt="Greece 1"
alt="Greece 2"
alt="Greece 3"
...
alt="Greece 200"
You can use the extension Regex Text Generator
select the word Greece
select all cases you want with
Ctrl+D multiple times
Ctrl+Shift+L to select all
use Shift+Alt+Click to create multiple cursors
if needed RightArrow to get all cursors after the word Greece
execute command: Generate text based on Regular Expression (regex)
As Original Text Regex use: .*
As Generator Regex use: {{=i+1}} (watch the space as first char)
Look at the preview, use Esc to cancel and Enter to accept
You can use any calculation based on i you want and you can also match number in the selected text and use that in the calculation N[...].
You can also add the word Greece by using Greece {{=i+1}}
You have a couple of options. First, using the extension, Find and Transform (disclaimer, I wrote that extension, this is very easy. Make this keybinding in your keybindings.json (after installing the extension):
{
"key": "alt+n", // whatever keybinding you like
"command": "findInCurrentFile",
"args": {
"find": "(alt=\"Greece\")",
"replace": "$1 ${matchNumber}",
"isRegex": true
}
},
Actually you can make it even easier if you first select what you want to modify (see the demo below). Then use this simple keybinding:
{
"key": "alt+n",
"command": "findInCurrentFile",
"args": {
"replace": "$1 ${matchNumber}", // what you select will be put into $1
"isRegex": true
}
},
Another option - not quite as easy
Snippets have a variable $CURSOR_NUMBER which is useful here.
Make this keybinding:
{
"key": "alt+n",
"command": "editor.action.insertSnippet",
"args": {
"snippet": "$TM_SELECTED $CURSOR_NUMBER"
},
"when": "editorHasSelection"
},
Do a find on your desired text match: alt="Greece"
Ctrl+Shift+L to select all occurrences of the find match.
Trigger the snippet via its keybinding.
Demo of this method:
So this second method is more steps but doesn't require an extension.
I need advice on how to write emmet HTML shortcut key in VS code on Linux mint for below. Thanks in advance.
<div><span>span=1</span></div>
<br>
<div><span>span=2</span></div>
<br>
<div><span>span=3</span></div>
<br>
<div><span>span=4</span></div>
<br>
<div><span>span=5</span></div>
<br>
I am not sure how to create an 'emmet' command, but you could create an html snippet to accomplish the same thing. Click on Preferences->User Snippets->html and it should open a file called html.json in the editor.
You can add the following to that html.json file:
"emmet spans": {
"prefix": "e-span",
"body": [
"<div><span>span=1</span></div>",
"<br>",
"<div><span>span=2</span></div>",
"<br>",
"<div><span>span=3</span></div>",
"<br>",
"<div><span>span=4</span></div>",
"<br>",
"<div><span>span=5</span></div>",
"<br>"
],
"description": "5 spans with line breaks"
}
A working sample snippet file would look like:
{
// Place your snippets for html here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"emmet spans": {
"prefix": "e-span",
"body": [
"<div><span>span=1</span></div>",
"<br>",
"<div><span>span=2</span></div>",
"<br>",
"<div><span>span=3</span></div>",
"<br>",
"<div><span>span=4</span></div>",
"<br>",
"<div><span>span=5</span></div>",
"<br>"
],
"description": "5 spans with line breaks"
}
}
Once that file is saved you should be able to edit .html files and when you type e-span that html snippet will be added to your .html file.
Emmet shotcut below will give the result you expected. You can find more on emmet cheat sheet
((div>span{span=$})^br)*5
<div><span>span=1</span></div>
<br>
<div><span>span=2</span></div>
<br>
<div><span>span=3</span></div>
<br>
<div><span>span=4</span></div>
<br>
<div><span>span=5</span></div>
<br>
I am trying to use the Sublime Text Plugin RegReplace package so I can highlight a line of text and replace spaces with dashes.
Goal
Hello My Name is Jesse, Highlight, CTRL + . replaces with:
Hello-My-Name-is-Jesse -- for the purpose for saving time creating markdown links.
Currently Working, But Runs Entire File
I would really like this to only replace the text I have highlighted wit a hotkey, is this possible?
I have this in reg_replace_rules.sublime-settings
{
"replacements": {
"replace_spaces_with_dash": {
"find" : "(\\s)",
"replace": "-",
"greedy": true,
"case": false
}
}
}
Here is my User Hotkeys
{
"keys": ["ctrl+."],
"command": "reg_replace",
"args": {"replacements": ["replace_spaces_with_dash"]}
},
However, this replaces the entire file with spaces. I am missing something I hope, I am not sure the scope. Any help would be appreciated.
I want that when ever I press ctrl+alt+m the Sublime Text find and replace all (in selected text).
Find for (regex):
(\.\w+)[[:blank:]]*(\(.+),
replace with:
\1 \2,
how can I do so?
As #longhua said, you could write a plugin for this, for example:
import sublime, sublime_plugin
import re
class ReplacerCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
selected_text = self.view.substr(region)
new_text = re.sub("(\.\w+)[[:blank:]]*(\(.+)", '\1 \2,', selected_text)
self.view.replace(edit, region, new_text)
Save it in your Packages folder, and then you can add a Keybinding to run it:
{ "keys": ["ctrl+alt+m"], "command": "replacer" }
Hope it helps
I work with files containing names to other files: stacktraces, documentation, etc.
I often need to jump to a specific file/position and to do that I select part of line containing filename, copy it, open 'go to' window and paste it and press enter.
It's working fine, but it pollutes my clipboard.
Are there any solutions to open 'go to' window with text selected already inserted there?
I've checked default keymap and found nothing like that.
Nothing built in, but you can do it with a plugin.
import sublime_plugin
class GoToFileCommand(sublime_plugin.WindowCommand):
def run(self):
window = self.window
view = window.active_view()
regions = view.sel()
if len(regions) == 1:
if not regions[0].empty():
window.run_command("show_overlay",
{"overlay": "goto", "show_files": True,
"text": view.substr(regions[0])})
return
window.run_command("show_overlay", {
"overlay": "goto", "show_files": True})
Then simply rebind ctrl/cmd+p to go_to_file.