I am looking for a Sublime Text 3 plugin/snippet that allow me to paste a multicursor selection where lines are joined to eachother with a separator I am defining right away.
For example, let's say I have those lines in my clipboard:
foo
bar
baz
When pressing the command, it would be pasted, and I would have a multicursor selector between each item:
Then I can write my separator:
Additionally to separators, I could also set data in the beginning and in the end or each item:
and then, after pressing tab:
Ideally, pressing tab would circle on the different muticursors:
separatorCursor <=> beginingCursor <=> endCursor
Do you know any plugin that does what I'm looking for?
Thank you
The absence of answers seemed to indicate that no such plugin exists yet, so I made my own.
https://github.com/OoDeLally/MultiCaretPaste
So far it only manage central separator. I don't know yet how to circle through TABs as indicated in my original post.
Related
VScode has an annoying feature where it adds a new line into the text box during find and replace when I press ctrl+enter. I would like to use the keyboard shortcut ctrl+enter to replace all, but when I configure it that way in keyboard shortcuts, it is still inserting a newline before replacing, adding an extra newline to every match that is replaced. Example:
Find: "foo"
Replace: "bar"
Before:
foofoofoo
foo
Expected result:
barbarbar
bar
Actual result:
bar
bar
bar
bar
This is highly infuriating since I've already become accustomed to this keyboard shortcut and it is disrupting my normal workflow. Does anyone know how to fix this?
Use CTRL+K+S , you will get list of all defaults.
Change whatever you want from the first option in the line of edit.
This issue is now fixed in at least 1.67, probably a version before that.
The question is, how do I move the selected block of code by one or several tabs, but not to the right (which is done by selecting a code and pressing Tab key), but to the left? Without selection each line one by one and deleting whitespace?
Moving parts of code from one place to another with differences in indent levels is a bit hard without knowing the shortcut.
What I mean (Imgur)
Thanks!
For what you want,
Shift+Tab
should do the trick. However, I would like to recommend this extension which I find easier to use when formatting blocks of text: Indent One space
Note however this extension only indents selections by exactly one space, forward or backwards.
Say you have the following text:
abc
123
abc
456
789
abc
abc
I want to remove all "abc" lines and just keep one. I don't mind sorting. The result should be like this:
abc
123
456
789
If the order of lines is not important
Sort lines alphabetically, if they aren't already, and perform these steps:
(based on this related question: How do I find and remove duplicate lines from a file using Regular Expressions?)
Control+F
Toggle "Replace mode"
Toggle "Use Regular Expression" (the icon with the .* symbol)
In the search field, type ^(.*)(\n\1)+$
In the "replace with" field, type $1
Click ("Replace All").
If the order of lines is important so you can't sort
In this case, either resort to a solution outside VS Code (see here), or - if your document is not very large and you don't mind spamming the Replace All button - follow the previous steps, but in steps 4 and 5, enter these:
(based on Remove specific duplicate lines without sorting)
Caution: Blocks for files with too many lines (1000+); may cause VS Code to crash; may introduce blank lines in some cases.
search: ((^[^\S$]*?(?=\S)(?:.*)+$)[\S\s]*?)^\2$(?:\n)?
replace with: $1
and then click the "Replace All" button as many times as there are duplicate occurrences.
You'll know it's enough when the line count stops decreasing when you click the button. Navigate to the last line of the document to keep an eye on that.
Coming in vscode v1.62 is a command to eliminate duplicate lines from a selection:
Delete Duplicate Lines in the Command Palette
or
editor.action.removeDuplicateLines as a command in a keybinding
(there is no default keybinding for this command)
Here is a very interesting extension: Transformer
Features:
Unique Lines As New Document
Unique Lines
Align CSV
Align To Cursor
Compact CSV
Copy To New Document
Count Duplicate Lines As New Document
Encode / Decode
Filter Lines As New Document
Filter Lines
Join Lines
JSON String As Text
Lines As JSON String Array
Normalize Diacritical Marks
Randomize Lines
Randomize Selections
Reverse Lines
Reverse Selections
Rotate Backward Selections
Rotate Forward Selections
Select Highlights
Select Lines
Selection As JSON String
Sort Lines By Length
Sort Lines
Sort Selections
Split Lines After
Split Lines Before
Split Lines
Trim Lines
Trim Selections
Unique Lines
Removes duplicate lines from the document Operates on selection or
current block if no selection
Unique Lines As New Document
Unique lines are opened in a new document Operates on selection or
current block if no selection
I haven't played with it much besides the "Unique Lines" command but it seems quite nicely done (including attempting a macro recorder!).
To add to #Marc.2377 's reply.
If the order is important and you don't care that you just keep the last of the duplicate lines, simply search for the following regexp if you want to only remove duplicte non-empty lines
^(.+)\n(?=(?:.*\n)*?\1$)
If you also want to remove duplicate empty lines, use * instead of +
^(.*)\n(?=(?:.*\n)*?\1$)
and replace with nothing.
This will take a line and try to find ahead some more (maybe 0) lines followed by the exact same line taken. It will remove the taken line.
This is just a one-shot regex. No need to spam the replace button.
This now also takes the comment of #awk into account, in where the last line has to have a linefeed in order to be identified as a duplicate. This is no longer the case now by excluding the \n from the line to search and adding a $ to the line found.
I just had the same issue and found the Visual Studio Code package "Sort lines". See the Visual Studio Code market place for details (e.g. Sort lines).
This package has the option "Sorting lines (unique)", which did it for me. Take care of any white spaces at the beginning/end of lines. They influence whether lines are considered unique or not.
Install the DupChecker extension, hit F1, and type "Check Duplicates".
It will check for duplicates and ask if you want to remove them.
Try find and replace with a regular expression.
Find:
^(.+)((?:\r?\n.*)*)(?:\r?\n\1)$
Replace:
$1$2
It is possible to introduce some variance in the first group.
If you don't mind some Vim in your VS Code. You can install Vim emulation plugin.
Then you can use vim commands
:sort u
It will sort lines and it will remove duplicates
Sublime Text 3
It has blisteringly fast native permutation functions.
Edit > Permute Lines > Unique or ⇧⌘U, and
Edit > Permute Selections > Unique
Visual Studio Code is my daily driver. But, I keep Sublime Text on standby for these situations.
Not actually in Visual Studio Code, but if it works, it works.
Open a new Excel spreadsheet
Paste the data into a column
Go to the Data tab
Select the column of data (if you haven't already)
Click Remove Duplicates (somewhat in the middle of the bar)
Click OK to remove duplicates.
It is not the best answer, as you specified Visual Studio Code, but as I said: If it works, it works :)
I understand how to get Eclipse to insert spaces in place of tabs, but then I'd rather not have to arrow through 12 spaces to reach an indented block.
Bonus points if there's a way to hide the spaces from the 'show whitespace characters'. I like to see whitespace characters for tabs and carriage returns, but the display gets too cluttered when spaces are also displayed.
Try CTRL+[right,left] arrow key. Certainly one of my most-used combos.
As it turns out, this appears to not be possible in Eclipse.
With the next Eclipse 20199.12/4.14, that might actually be possible! (albeit ten years later)
See "Backspace/delete can treat spaces as tabs"
If you use the Insert spaces for tabs option, now you can also change the backspace and delete keys behavior to remove multiple spaces at once, as if they were a tab.
The new setting is called Remove multiple spaces on backspace/delete and is found on the General > Editors > Text Editors preference page.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I use Netbeans (nightly build) for Ruby on Rails development and I'm looking to beef up my macros. I've created a few myself:
copy identifier:
select-identifier copy-to-clipboard
paste clipboard over identifier:
select-identifier paste-from-clipboard
double quote element
select-element-next "\""
single quote element:
select-element-next "'"
But I'm looking for other useful ones and Google is giving me nothing.
The record macro feature usually doesn't work too well so I'd rather just "write" the macros myself but I can't even find a reference that lists what commands (like "select-identifier") are actually available.
Any Netbeans macro gurus out there?
Here is a list of macro codes with short explanations. Might be useful for someone.
Update: replaced old link with one to the Netbeans site and included the macro list in here.
abbrev-debug-line Debug Filename and Line Number
adjust-caret-bottom Move Insertion Point to Bottom
adjust-caret-center Move Insertion Point to Center
adjust-caret-top Move Insertion Point to Top
adjust-window-bottom Scroll Insertion Point to Bottom
adjust-window-center Scroll Insertion Point to Center
adjust-window-top Scroll Insertion Point to Top
all-completion-show Show All Code Completion Popup
annotations-cycling Annotations Cycling
beep Beep
build-popup-menu Build Popup Menu
build-tool-tip Build Tool Tip
caret-backward Insertion Point Backward
caret-begin Insertion Point to Beginning of Document
caret-begin-line Insertion Point to Beginning of Text on Line
caret-begin-word Insertion Point to Beginning of Word
caret-down Insertion Point Down
caret-end Insertion Point to End of Document
caret-end-line Insertion Point to End of Line
caret-end-word Insertion Point to End of Word
caret-forward Insertion Point Forward
caret-line-first-column Insertion Point to Beginning of Line
caret-next-word caret-next-word
caret-previous-word caret-previous-word
caret-up Insertion Point Up
collapse-all-code-block-folds Collapse All Java Code
collapse-all-folds Collapse All
collapse-all-javadoc-folds Collapse All Javadoc
collapse-fold Collapse Fold
comment Comment
complete-line Complete Line
complete-line-newline Complete Line and Create New Line
completion-show Show Code Completion Popup
copy-selection-else-line-down Copy Selection else Line down
copy-selection-else-line-up Copy Selection else Line up
copy-to-clipboard Copy
cut-to-clipboard Cut
cut-to-line-begin Cut from Insertion Point to Line Begining
cut-to-line-end Cut from Insertion Point to Line End
default-typed Default Typed
delete-next Delete Next Character
delete-previous Delete Previous Character
documentation-show Show Documentation Popup
dump-view-hierarchy Dump View Hierarchy
expand-all-code-block-folds Expand All Java Code
expand-all-folds Expand All
expand-all-javadoc-folds Expand All Javadoc
expand-fold Expand Fold
fast-import Fast Import
find-next Find Next Occurrence
find-previous Find Previous Occurrence
find-selection Find Selection
first-non-white Go to First Non-whitespace Char
fix-imports Fix Imports
format Format
generate-code Insert Code
generate-fold-popup Generate Fold Popup
generate-goto-popup Generate Goto Popup
generate-gutter-popup Margin
goto Go to Line...
goto-declaration Go to Declaration
goto-help Go to Javadoc
goto-implementation Go to Implementation
goto-source Go to Source
goto-super-implementation Go to Super Implementation
in-place-refactoring Instant Rename
incremental-search-backward Incremental Search Backward
incremental-search-forward Incremental Search Forward
insert-break Insert Newline
insert-date-time Insert Current Date and Time
insert-tab Insert Tab
introduce-constant Introduce Constant...
introduce-field Introduce Field...
introduce-method Introduce Method...
introduce-variable Introduce Variable...
java-next-marked-occurrence Navigate to Next Occurrence
java-prev-marked-occurrence Navigate to Previous Occurrence
jump-list-last-edit Last edit
jump-list-next Forward
jump-list-prev Back
last-non-white Go to Last Non-whitespace Char
make-getter Replace Variable With its Getter
make-is Replace Variable With its is* Method
make-setter Replace Variable With its Setter
match-brace Insertion Point to Matching Brace
move-selection-else-line-down Move Selection else Line down
move-selection-else-line-up Move Selection else Line up
org.openide.actions.PopupAction Show Popup Menu
page-down Page Down
page-up Page Up
paste-formated Paste Formatted
paste-from-clipboard Paste
redo Redo
reindent-line Re-indent Current Line or Selection
remove-line Delete Line
remove-line-begin Delete Preceding Characters in Line
remove-selection Delete Selection
remove-tab Delete Tab
remove-trailing-spaces Remove Trailing Spaces
remove-word-next remove-word-next
remove-word-previous remove-word-previous
replace Replace
run-macro Run Macro
scroll-down Scroll Down
scroll-up Scroll Up
select-all Select All
select-element-next Select Next Element
select-element-previous Select Previous Element
select-identifier Select Identifier
select-line Select Line
select-next-parameter Select Next Parameter
select-word Select Word
selection-backward Extend Selection Backward
selection-begin Extend Selection to Beginning of Document
selection-begin-line Extend Selection to Beginning of Text on Line
selection-begin-word Extend Selection to Beginning of Word
selection-down Extend Selection Down
selection-end Extend Selection to End of Document
selection-end-line Extend Selection to End of Line
selection-end-word Extend Selection to End of Word
selection-first-non-white Extend Selection to First Non-whitespace Char
selection-forward Extend Selection Forward
selection-last-non-white Extend Selection to Last Non-whitespace Char
selection-line-first-column Extend Selection to Beginning of Line
selection-match-brace Extend Selection to Matching Brace
selection-next-word selection-next-word
selection-page-down Extend Selection to Next Page
selection-page-up Extend Selection to Previous Page
selection-previous-word selection-previous-word
selection-up Extend Selection Up
shift-line-left Shift Line Left
shift-line-right Shift Line Right
split-line Split Line
start-macro-recording Start Macro Recording
start-new-line Start New Line
stop-macro-recording Stop Macro Recording
switch-case Switch Case
to-lower-case To Lowercase
to-upper-case To Uppercase
toggle-case-identifier-begin Switch Capitalization of Identifier
toggle-comment Toggle Comment
toggle-highlight-search Toggle Highlight Search
toggle-line-numbers Toggle Line Numbers
toggle-non-printable-characters Toggle Non-printable Characters
toggle-toolbar Toggle Toolbar
toggle-typing-mode Toggle Typing Mode
tooltip-show Show Code Completion Tip Popup
uncomment Uncomment
undo Undo
word-match-next Next Matching Word
word-match-prev Previous Matching Word
I needed to surround text fragments with HTML tags, but couldn't figure out how to do it quickly, so I came up with this macro:
cut-to-clipboard "<strong>" paste-from-clipboard "</strong>"
Simple, clean, and you can put any tag/text you want. Give it a shortcut like Alt+B and you have quick way to insert HTML
for php add semicolon to end line ("complete line")
but keep your cursor at the current point,
so you can keep typing the rest of the line
split-line
caret-down
caret-end-line ";"
caret-begin-line
selection-begin-line remove-selection
delete-previous
This is my first netbeans macro.
"echo '< pre >';print_r();die();"
my shortcut key => Alt+A
for this you can use any shortcut
Oh well, just experimenting with netbeans.
I add a simple new macro for netbeans.
name: "scrollup_newline"
code:
insert-break
scroll-up
It works well, so every i press enter, the editor move one line down. This way i can code and have the caret in the middle of the editor.
This is for HTML. I just made:
caret-begin-line "<li>" caret-end-line "</li>" caret-down
Mapped it to ctrl+shift+L This is my first netbeans macro. Later maybe I can make it work for an entire selection somehow.
Edit: Can't figure out doing it for selections, but adding "caret-down" at the end was almost as good.
Here is the macro I wrote today. I am very much missing an "extract method" or "introduce method" refactoring in PHP, so I wrote this macro. I know this is far less complex than the refactorings in Java, but it can be used and it saves a few copy/pastes and writing repetitive code.
cut-to-clipboard
"$this->UNNAMED_METHOD();"
collapse-fold
caret-end-line caret-backward caret-end-line insert-break
"private function UNNAMED_METHOD() {"insert-break
paste-from-clipboard insert-break
This macro inserts -moz- and -webkit- prefixed equivalents of a css3 style rule:
caret-end-line selection-begin-line copy-to-clipboard caret-backward insert-break caret-up "-webkit-" paste-from-clipboard insert-break "-moz-" paste-from-clipboard
insert-date-time remove-word-previous remove-word-previous
Mapped to CTRL+SHIFT+D to insert the short date, so useful cause I like to date my comments / TODOs but often don't know the date!
Although I think Code Templates and more useful, for example:
// <editor-fold defaultstate="collapsed" desc="${cursor}">
and
// </editor-fold>
Mapped to 'fold' then tab and 'endfold' then tab respectively.
Also
JOptionPane.showMessageDialog(null, "${EXP default="Got here"}");
Mapped to 'jop' then tab is handy.
Probably not the most efficient but it helps me out lol
"(() ? : );"
caret-backward
caret-backward
caret-backward
caret-backward
caret-backward
caret-backward
caret-backward
caret-backward
As one can see, this is for PHP quick conditionals. This then places the cursor in the spot where you start typing the condition. Perfect no matter where your throwing it into. I put this to Ctrl+NUMPAD0 for quick typing access. I orignally had it to two TABs but that quickly got annoying haha
I often like to have commas as the first character separating properties or list items in JavaScript; like so:
var foo = {
a : 'a'
//, b : 'B' //todo: make lcase
, c : 'c'
};
Sometimes, I either forget to do this, or have a mass of text to update. To fix these quickly, I bound the keyboard shortcut C-, C-, -- That's two presses of ',' while holding CTRL key -- to:
caret-end-line selection-next-word selection-next-word " " caret-backward caret-backward insert-break
I found Code Templates to be very useful, especially this one (for HTML):
<${tag}>${cursor}</${tag}>
The abbreviation is "tt", and it can also surround any text with custom tag, when called by the code template menu.
<${param_name default="tag"}${cursor}>
${selection}
</${param_name default="tag"}>
This one will surround anything with any tag. Select something, then Alt+F3, then just select this template from the menu. After that type the tag you want, e.g. "div".
This is a code template for creating a static logger in a class using SLF4J. I tie it to "Log".
private static final ${loggerType type="org.slf4j.Logger" default="Logger" editable="false"} log = ${loggerFactoryType type="org.slf4j.LoggerFactory" default="LoggerFactory" editable="false"}.getLogger(${classType editable="false" currClassName default="getClass()"}.class);
This makes a log.debug line which I tie to "log":
log.debug("${message}", "${variables}");