How to move delete current line and move text to the top in Vim? - vim

I have the following code.
var post = new Post("abc",
"def");
How do I move the whole second line to the above line which would result in this?
var post = new Post("abc", "def");

It's like you want to join the two lines. The command to use, in normal mode, is J (capital/shifted letter/key.)

Related

How can I paste to next line and enter insert mode on current line?

I'm brand new to vim. A common pattern I am dealing with looks like this
myFunction :: some code
myFunction = some more code
how could I create a command where after executing I look like this
myFunction
myFunction
and am in insert mode with my cursor on the end of the first 'myFunction' ?
If you are copying the first line to the down then maybe try yy for yanking the whole (first) line, P for pasting the line before the cursor and A to go in insert mode at the end of first line.
And you can use :map to do whole thing at one. Like :map 'l yyPA
I have found an almost perfect solution "using ultisnips plugin", the only thing missing is the cursor position. I am considering an already typed text:
You must select the target lines (use vip in normal mode) and use your defined trigger on ultisnips
snippet trigger "Description" w
`!p
import re
snip.rv = re.sub("(^\w+).*", r"\1", snip.v.text, flags=re.MULTILINE)
`
endsnippet

Line break is not working when editing at the end of previous line in fabric js

Line break is working fine when I am writing in current line but If I am trying to edit in previous line then line break is not working. I know the reason is line length is using as a array index of line width. so when I am going back to edit the array index remain same and the array width also remain same so it can't enter into the condition.please give some solution to over come this problem.
Demo
var tempwidth=270;
canvas.on('text:changed', function(e) {
console.log("Line Length",e.target._textLines.length);
console.log("TargetText",e.target);
objTEmp=e.target;
var tLine = e.target._textLines.length;
var lineWidthText = e.target.__lineWidths[tLine-1];
console.log("TargetText",e.target.__lineWidths[tLine-1]);
if (lineWidthText > tempwidth) {
objTEmp.setText(e.target.text+' ');
objTEmp.setText(objTEmp.getText());
objTEmp.selectAll();
objTEmp.setSelectionStart(objTEmp.text.length);
objTEmp.setSelectionEnd(objTEmp.text.length);
tempwidth=270;
canvas.renderAll();
console.log("TargetTextWidth",e.target.width);
console.log("Changed Text Width",tempwidth);
}
});

JTextPane, second word must not go to new line when typing and exceeding width

I'm using JTextPane because I need to markup text.
When typing into the JtextPane the second word always goes to new line. Then also when making the second word longer (after it went to a new line) the scroll bar appears and the JTextPane resizes. If I start typing in a new row then second word in that line does not go to a new line (as long the second word does not exceed width)
I tried adding a blank string that is very long in the first line and seems to do the trick, but this blank line is not really what I want to have.
Also tried adding it to after the text but it gives more problems
Is there something else that I can do to make the text only go to new line when I press enter? I can do it without a blank string using jtextarea, but then I can't markup text as I type.
I found the answer:
JTextPane textPane = new JTextPane()
{
public boolean getScrollableTracksViewportWidth()
{
return getUI().getPreferredSize(this).width
<= getParent().getSize().width;
}
};
We can overite the getScrollableTracksViewportWidth method to have a no wrapping text pane.
Website for more info: Here

How to indent a line starting from the position of the cursor in vim?

I want to indent a line partially in vim, starting from the cursor. For example: I have the line
var array = []
with cursor positioned on =.
And I want to get something like this as a result
var array = []
My AlignFromCursor plugin does that.
In your example, to align the = and following to column 20, use 20<Leader>le.
For aligning multiple instances, also look into Align - Help folks to align text, eqns, declarations, tables, etc or the alternative Tabular - Vim script for text filtering and alignment.

Whenever I type colon in insert mode it moves my text to the very beginning of line

Whenever I type a : (colon) it moves all the text on the current line to the beginning of the line, ignoring spaces and tabs.
So if I type
var combo = new Ext.form.ComboBox({
typeAhead //I'm about to type a colon, but right now it looks fine
})
Then I type the colon it moves the text and it now looks like
var combo = new Ext.form.ComboBox({
typeAhead: //text is no longer indented
})
This is a javascript file, so that might be causing the problem?
How can I stop my text from being moved to the beginning of the line when I type a colon?
Adding a colon to the end of a token is causing vim to interpret it as a jump label for C-indenting purposes. :set cino+=L0 should cause it to stay in the current column.
Also, doesn't the JSON syntax allow you to quote the thing that precedes the colon? That should prevent vim from thinking it's a label too.
var combo = new Ext.form.ComboBox({
"typeAhead": "foo" // this isn't a jump label
});

Resources