Jump to line in vim with relativenumber on - ide

In a normal situation it's possible to look at the line number and use [number]G to goto that line. But I like to work with the setting relativenumber on. The disadvantage is that I can't jump to lines anymore by looking at the displayed line number.
Is it possible to redefine the behavior of [number]G to fix this? Also, would it be possible to make the current line number 1 instead of 0 with relativenumber on? And how?

You can simply [number]j or [number]k to do this.

Related

I would like to MOVE just one line in Vim

yy and p should copy and paste 1 line of text.
But I have to go back and delete the original line.
:2,5m10
should move lines from 2 to 5 to line 10. however I need to enable :set number
to see what lines I am moving
I would like to move just 1 line of text, sort of like yy+p and not use :2,3m10
to move just one line.
Is there something like mm+p ?
so it copies the current line into buffer and deletes the line and you p paste it where you want ?
:3m . moves line 3 to your current line.
Above line does the function I want. Can I set a key mapping so
that "mm" replaces ":3m." ? I find it easier to type. TIA
What you're describing is the default behaviour when using dd -it deletes a
line into the buffer and p will paste it.
So dd and p works.
If you're new to vim, then it might seem a little strange that 'yanking' (with
y) and 'deleting' (with d) both copy to the buffer, given the 'cut', 'copy'
and 'paste' behaviours of most other editors.
You can read more about it with :help change.txt and in particular :help registers.
Also, since you say you need to enable :set number, I wonder if you've come
across :set relativenumber? This is very useful - in the example below, the
numbers would look this way if the your cursor was on the line with
'demonstrate':
3 This is just
2 a small
1 example to
0 demonstrate
1 how relative
2 numbers can
3 be useful
Thus if you wanted to move the line 'a small' below the line with 'numbers
can', you could use the relative line numbers to know that 2k would put the
cursor on the line you want, where you'd hit dd, then you'd have this
situation (the deleted line is now in the buffer:
1 This is just
0 example to
1 demonstrate
2 how relative
3 numbers can
4 be useful
Then you can do 3j to move to the 'numbers can' line, and hit p. So
relative numbers are a nice way to move quickly to lines you can see. Also,
just for completeness, you can use relative numbers in a similar way on the
command line::-2m+3 (although I know this isn't what you're after). You can
even set both relative number and set number at the same time, in which case
it's like in the example above, only you have the absolute line number
displayed on the current line instead of a zero.

In Vim can I automatically soft wrap comments with alignment at the first character

I'm currently using vim to take notes and the way I'll usually do that is as follows:
- First line of info
- Sub line of info
- More sub information
- Second point
- Third point, etc
However, when writing long lines the output will look as follows:
- First line of info that is really long
goes down to here
- Subpoint line of info that is short
- Subpoint line that is really long goes to
here and continues
- Subpoint line that is short again
- Second point that is really long goes to
here, etc, etc
What I'd really like is if it looked like this:
- First line of info that is really long
goes down to here
- Subpoint line of info that is short
- Subpoint line that is really long goes to
here and continues
- Subpoint line that is short again
- Second point that is really long goes to
here, etc, etc
This would make it easier to see when each new point or subpoint was started because of the "-" sticks out more.
If possible I'd like:
automatic inserting of the leading character (doesn't have to be a dash) on enter
automatic inserting of the leading character (doesn't have to be a dash) on o and O
automatic soft wrapping of the text to the correct indentation level
automatic soft wrapping of the text to the first character after the leading character
I've been able to achieve the first three using the following:
set formatoptions=ro
set comments=b:-
set breakindent
set autoindent
However, when trying to get the soft wrapping at the first character after the "-" I am having trouble.
I've tried using set formatoptions+=n with an accompanying formatlistpat=^\s*-\s*. However, then it is not automatic and I need to use gq which seems like it makes a second line instead of just soft wrapping. If using set formatoptions+=wan I can get it sometimes automatically wrapping but it is once again a hard line break, not a soft wrapping.
If anyone could help that would be greatly appreciated!
So I've finally figured it out. The answer was breakindentopt :help breakindentopt
Specifically set breakindentopt=shift:2
This causes the line that is wrapped due to breakindent to shift two spaces two the right which lines everything up the way I wanted.
The full settings which achieve what I was going for are:
set formatoptions=ro
set comments=b:-
set breakindent
set autoindent
set breakindentopt=shift:2

IDEA break fromat when introduce local variable

I am trying to introduce local variable and IDEA breaks my formatting, what i doing wrong?
I have tried cntrl+enter at end of line and cntrl+alt+v.
Go to settings->Editor->Code style->Java-> Wrapping and braces at the Keep when formatting section enable line breaks.

Enable show differences in line separators in a diff with Intellij IDEA 13

I'm using IDEA 13.0.1. A unit test is failing because of some line separator stuff. But when I try to compare the two results, IDEA says "Contents have differences only in line separators".
And I can't find a setting where I can say show me these differences. Is there one?
I ran into the same issue, I couldn't find a way to show the difference by clicking show differences, but if you put a break point and look at the strings, they have the line separator written out. For me one string had \n and one had \r\n. \r is also a possible line separator.
I ran into the same problem recently. I found a workaround for it, is not that pretty but did the job:
yourString.replaceAll("\n", "").replaceAll("\r", "");
The key is in what #user1633977 said.
To solve this problem, always use System.lineSeparator() to create your separators. That way they will always be the same and will be OS-independant.
(Remember that different OS can use different symbols as line separators).

Limiting a match in vim to certain filetypes?

I have the following in my .vimrc to highlight lines longer than 80 chars:
highlight OverLength ctermbg=red ctermfg=white guibg=#592929
match OverLength /\%81v.*/
This works quite well. However, the problem is that I would prefer it if it only worked on certain file types. Basically, any programming language should be highlighted and things like html, xml, and txt files should not be. I'm pretty sure I could do this easily with an autocmd, but I'm not sure if that is the best way to accomplish that goal. Anybody have any opinions?
Sounds like you might want something like:
autocmd FileType html,xml highlight OverLength ctermbg=red ctermfg=white guibg=#592929
autocmd FileType html,xml match OverLength /\%81v.*/
Seems to work for me anyway :-)
The issue with using match for a task like this is that it is local to the active window, not to the buffer being edited. I'd try something along the following lines:
highlight OverLength ctermbg=red ctermfg=white guibg=#592929
fun! UpdateMatch()
if &ft !~ '^\%(html\|xml\)$'
match OverLength /\%81v.*/
else
match NONE
endif
endfun
autocmd BufEnter,BufWinEnter * call UpdateMatch()
Basically, you want to trigger whenever the buffer in the current window changes. At that point, you evaluate what filetype the buffer has and adjust whether the match should be active or not.
If you also want to support editing an unnamed buffer and then setting its filetype (either via saving or manually setting &ft), the FileType even should be added to the list.