using idioms in vim for perl - perl

I have the perl-support plugin enabled. now, I tried the \idd idiom shortcut which would give you a my ($,$); statement with the cursor placed on the first var. Now the second var is displayed as <+name+>. In effect the my line after entering the first variables name would be
my ( $top, $<+name+> );
If it was a code snippet I could have easily used tab to go to the next field, but it is not working in this case. How do I quickly move to changing the 2nd part of the idiom?

Those are jump targets, and you can visit them with Ctrl+J. See perlsupport-templates-jump for details.

If this is VIM, why don't you just use VIM's navigation keys for this?
3W (that is a capital W) will move you three words to the left, right onto $<+name+>.
You could also try:
f< to put the cursor on the <, and then you can change <+name+>.

Related

Finish code folding in one line (and keep folding sign visible all the time)

Code folding in VScode doesn't seem as good as IntelliJ's.
eg. code block
def g(a):
print(a)
print(a)
print(a)
print(a)
print(a)
Or, for (...),{...},[...] (indentation isn't actually the real concern.)
eg code sample from dart(flutter):
OutlinedButton(
onPressed: () {
Navigator.pushNamed(
context,
SecondPage.id,
);
},
child: Text("Page 2"),
)
So, now if I fold this code and try to duplicate the folded line, it doesn't copy the entire fold as it does in IntelliJ. Is there an extension or settings, with which I can achieve the same as IntelliJ? I've found a comment which says I need to copy till the beginning of the next line which is not what I want. https://github.com/microsoft/vscode/issues/51232#issuecomment-395190470
If I press Enter after folding, it creates a new line in the folding section, I actually want it to create the line after the folding section.
VScode only shows the folding sign when I hover the mouse over it, I want it visible all the time.
I'm assuming that the code language is Python.
So, now if I fold this code and try to duplicate the folded line, it doesn't copy the entire fold as it does in IntelliJ
You need to select the whole region. To do that, simply do a Shift+Down, then you can copy/paste the region.
If I press Enter after folding, it creates a new line in the folding section, I actually want it to create the line after the folding section.
Python's folding regions are based on the indentation. So when pressing Enter after a folding, the new line is tabbed so it is inside the region. You need to delete the tab so the line isn't in the region.
Finish code folding in one line
To fold on a single line, you need to use the extension Explicit Folding and the following configuration:
"[python]": {
"explicitFolding.rules": [
{
"beginRegex": "\"\"\"",
"endRegex": "\"\"\"",
},
{
"indentation": true,
"offSide": true
}
]
}
Three points. Two addressed by others already but I'll include them here for completeness, with the third being my own contribution.
Fundamentally, Code's philosophy seems to be that the end of the line containing all the folded code seems to be considered the end of the first line of the folded code, not the end of all the folded code. The folded code exists between the start of the first line of the code in question, and the start of the next visible line (the first line after the folded section). Therefore:
As per daiyam's answer, press Shift+Down at the start of the folded code to select everything between it and the next visible line. This then includes all the folded code, which you can then copy/paste.
My own contribution here: Similarly, to add a new line after the folded code, either press Down from the start of the folded code line, or press Right from the end of that line, to get to the start of the next line. Then press Enter to add a new line there. Then Up to get to the start of the new line.^^
As per mark's comment set the Editor: Show Folding Controls to always.
^^ Some potentially overkill analysis 😉 ...
Yes, that seems like a lot of steps for something you're used to doing in one step in IntelliJ, except it's only two extra (arrow) key presses. If you're switching away from IntelliJ, to Code, then your muscle memory will likely adapt pretty quick. That might only be a problem if you're switching back and forth between them frequently.
Also, whatever keys or mouse click you've done to get to the start or end of that first folding line in the first place could be replaced by a different click or key presses to get you to the start of that next line instead. So the only extra really is the Up key after the Enter, plus the (presumably pretty tiny) learning curve to remember to go to that next line start instead of previous line end.
I suppose if that's a big deal, you could use any of the Macro applications to combine those extra arrow keystrokes and the Enter to one keystroke (say Shift+Enter or something). I find myself doing that sort of thing a lot to bring consistency to my use of different IDE's etc.
Just a couple of ideas in case they help.

How to select whole line in VSCode

I am using VSCode on a Mac.
Does anyone know how to select the entire line that the cursor is on? I know about Command+I, but that only selects what appears to be the whole line, which is not always the whole line if I have word wrap enabled.
I am looking for something like Sublime Text's "Expand Selection to Line" command.
All you need to do is put the cursor anywhere on the line, do not make any selection at all and then do the desired command (Cut, copy, or paste).
When no text selected, VS Code will automatically select the entire line.
just triple click the end of the line it will select the entire line
Triple click at any point on the line
Click once on number of the line
Press Command + L
An alternative to what people have posted is, when your cursor is at the start/end of the line, you can hit shift + end/home respectively.
I find this useful for wrapping a line in curly braces/quotes/etc. whereas the other answers include spaces in the select so whatever you're wrapping it in will be wrapped around that whitespace.
Install the MetaGo extension and use the "metaGo: selectLineDown" command, which will come installed already overriding the "expandLineSelection" command.
This extension has many additional commands that you'll likely find useful as well, including moving up/down over code blocks, centering the active line, and going to any character on the screen.
Now, when I press Command+I, the whole line is selected. I am guessing this was caused by an update to VS Code, but I am not sure.
Ctrl + L on Windows or Command + L on Mac to select the whole line in VS Code.
You can use your mouse to select the whole line by triple-clicking on the line but the better way is to click on the line number to select the whole line or multiple lines.
Tripple click at any point on the line
In case you're wondering why Cmd+L is not working, there might be a chance that there are duplicate shortcuts. You can find out by opening Keyboard Shortcuts in VSC and remove the one that's not needed.
I know its old but for anyone seeking, you can press Alt + arrow up/down to duplicate your cursor to other lines and then without selecting anything copy and paste multiple lines.

VS Code: Case sensitive replacement after pressing Crtl - D

Let's suppose I have the following code:
But I change my mind and I don't want to call it plan anymore. I want to call it schedule. So, because VS Code is so amazing and I'm so lazy, I press Ctrl + D hoping for VS Code to change the name respecting the case. But suddenly:
Is it there any way to tell VS Code to respect the case?
With 1.37 (July 2019), it is possible through a find/replace (which now can replace by preserving case).
Issue 9798 has been implemented by PR 78003.
issue 78397 has been implemented by PR 79111 (1.38 only) for search/replace.
From 1.37 release notes:
You can now preserve case when doing replacement in the editor's Find widget. The feature is turned on when the Preserve Case option (AB button) is turned on in the editor's Replace input box.
Currently VS Code only supports preserve Full Upper Case, Full Lower Case, and Title Case.
Shortcuts are Alt + C for case sensitive. There is a little toolbar appears at the top-right corner of the VS Code, to let you toggle search options.
or you just Ctrl + F to toggle replace mode.
The v1.38 release in early September will extend the Preserve Case functionality to replacements while searching across files using the Search Panel. See add Preserve Case to Searches (all files).
.
There is also a new case preservation mode for hyphen-separated words.
v1.39 is adding preserve case for _underscore separated words. Like foo_bar.
See https://github.com/microsoft/vscode/pull/79660
If you want to achieve this without using the find/replace menu, there is an extension which solves your problem: https://marketplace.visualstudio.com/items?itemName=Cardinal90.multi-cursor-case-preserve
As far as I know it isn't, a workaround could be using the buttons that appear on top right after you press Ctrl + D. The second lets you select occurrences respecting the case, this way you could replace the text in 2 steps, first Plan and then plan.
So select the code bit, ctrl+h to open replace, edit find and replace, turn off match case in find, turn on preserve case within replace, Alt+L to find all occurences in selection, and Ctrl+Alt+Enter to execute.
9/10 cases you'll get it wrong, doesn't worth the effort. Just use ctr+d, then do the same for the uppercase.
Personally looking forward for a simpler/safer solution through the ctrl+d way. :)

deleting collapsed code section in Eclipse

Collapsing code sections is nice. But everytime I select the collapsed part in the editor and cut/delete it the selection expands and I have to find the start/end manually in the expanded code.
Is there an easier way?
Many thanks!
When your cursor is inside the element you can use Select Enclosing Element Shift+Alt+Up. You may need to press it a few times, depending how many levels of enclosing elements there are (blocks like loops).
You may use a desktop environment that thinks it is a good idea to define a few hundred shortcuts that you will never use but that override all your application shortcuts (Ubuntu Unity). In this case you may need to change your desktop environment (by far the most painless way to solve this problem).
Using Neon
Collapse the code
Double click the collapsed code
Hit ctrl-x or the Delete key.
Hitting Backspace or the Enter key still just expands the collapsed code

Multiline sentence in emacs

If I have a multiline sentence in Emacs it naturally overflows onto the the following lines. Now, if my cursor is at the beginning of such a sentence and I press the DOWN ARROW key, the cursor is placed at the beginning of the next sentence (which might be at 4-5 lines down), rather than on the next line itself (which other editors do). Same is the behavior of the END and HOME keys.
Is there a way in which I can change this behavior and get the cursor on the next line instead of the next sentence?
I haven't yet tried it myself, but I think what you are asking for is the default behavior for emacs 23. What version are you running?
You might want to check out the page Move By Visible Lines page on the emacswiki.
You might want to try auto-fill-mode or longlines-mode. To get either use M-X then type the command you want. Toggle them off the same way.
If that doesn't work you may want to examine the binding that is being applied to your down arrow. Type C-h k then hit the down arrow key.
It sounds as though the text is wrapping, so by definition (a line being a group of characters separated by a carriage return), it is moving down to the next line.
I agree it is a pain, however a lot of other editors also have this behaviour.
One way is to turn off wrapping:
M-x toggle-truncate-lines
You wont be able to see all of the text in the editor, however it will move down to the next line.