When I'm using shortcut ctrl+shift+D to duplicate line, sometimes the new line will be created in the next line, but sometimes it just append in the same line. I just want to it always to be created in the new line.
Well, it depends on your selection. If your selected line containes a new line character then duplicated line will be the new line else duplicated text will be created as a continuation of the same line:
if you select the line below (without CR)
select
result of duplication will be
selectselect
if there is a new line char at the end of your line and
your selection captures it too
select
then the result will be
select
select
Regards...
Related
In vscode when the cursor is on a blank line and I save the document the cursor jumps to the first column of the line. How can I prevent this?
So the line really isn't blank if the cursor isn't already in the first column. The whitespace you have on that line is being removed when you do a save. To prevent all the whitespace on a line from being removed, disable this setting:
Files : Trim Trailing Whitespace
Once in a time I remember that in VSCode I could move my cursor after the final line. That is, if a file doesn't end with a trailing newline and I click the space after the last line, the cursor would be placed after the final line where there is no line number at the left. However, now in VSCode 1.37.1 it not longer behave like this. When I click the space, it just put the cursor at the end of the last line. How can I restore the old behaviour? I searched the settings but I can't find relevant option.
Try:
"editor.renderFinalNewline": false
I think that is what you want - if there is a newline at the end of the final line you can click in the line below (which has no line number) and enter text there.
When i'm writing sql in sql developer and typing out a query quickly and do a new line, it'll bring the last character over to the new line and put my cursor behind the character.
SELECT *
SELECT
//cursor is here *
I have a .json file which is about 600+ lines and it looks like this:
{data0..}
{data1..}
{data2..}
To use it i need to add [ before and ] after to make it an array (no problem)
but i need to add " , " after every row. Is there a function/method to do that faster than manual typing?
Every object contain data in it.
Or anything to make it readble?
Alternatively, and simpler,
Ctrl-A to select all.
Shift-All-I to put a cursor at each line end.
Type your ,.
Press Ctrl-H for the Search-Replace window
In the first line type \n which means new line and make sure the regular expressions button is pushed - it's 3rd in the row and looks like this: .*
In the second line type ,\n - to replace new line with a comma followed by a new line
Push the "replace all" button
Notice: it assumes every JSON object occupies strictly single line
I use this key mapping to duplicate a line, and go to the same cursor position on this newly created line:
nnoremap , mqYp`qj
What this does:
Create mark 'q'
Yank line
Paste/put line (below current line, cursor is now at start of new line)
Go back to mark at previous line
Move one line down. (cursor is now on new line at the same place of start of previous line)
This works perfectly fine, however I see a flaw when putting a number in front of the command. Imagine I want to duplicate this line 10 times. It would try to create 10 marks basically. I could do Y10p for this, I do understand that. My problem with that approach is that I'm not on the same cursor position as I was in the first line, the one I'm duplicating.
So I'm looking for a way to do basically 10,, using my previously made mapping, and ending on the last line, at the same cursor position of where I was in the first line. Note that I am using IdeaVIM exclusively to code, which means I can't make any functions for this.
Is it possible to get this 10, working in this situation?
Edit #1:
Example text
# Start
# Initialize new variables
new_invoice_name_one = 'New Name One'
new_invoice_name_two = 'New Name Two'
new_invoice_address_one = 'New Address One'
Command executed: 3, with the cursor being on the first I of line 2
Desired output
# Start
# Initialize new variables
# Initialize new variables
# Initialize new variables
# Initialize new variables
new_invoice_name_one = 'New Name One'
new_invoice_name_two = 'New Name Two'
new_invoice_address_one = 'New Address One'
with the cursor being on the first I of line 5 `
Edit #2:
I see some potential at the LetHandler.java here, however I can not seem to figure out how to use it to match the use case. On the other hand, here it says it is not supported at all.
When I play vimgolf, I use a trick [count]#='... sometimes. It could be used for your requirement.
you can map:
nnoremap , #='mqYp`q'<cr>
Then you can just simple press 200, to achieve what you want.
You can achieve this by pasting to the above of current line. Do this nnoremap , YmqP`q
update
You cannot do that since vim's key mapping is just string concatenation. One way to achieve this is to predefine a macro. Put this in the related rc file,
let #q="mqYP`q"
nnoremap , #q