Using CTRL-O in vim help files breaks with jumping to previous file - vim

I'm using Vim 8.0, and when I browse the vim help files using CTRL-] to jump around, I find that trying to go back through the jumplist using CTRL-O works fine when the Old positions are in the current file, but things break as soon as I try to CTRL-O to an old position in a previous file. Somehow this gets treated as a jump itself, and instead of going back in the jumplist, a whole new entry is added to the jumplist instead.
The following is an example to illustrate. Suppose I was jumping around in motion.txt.gz, and then followed a link to map.txt.gz using CTRL-] and jumped around in that file. Then my jump list might look like this:
:jump
jump line col file/text
9 1 0 help.txt
8 1 0 motion.txt.gz
7 313 19 motion.txt.gz
6 75 6 motion.txt.gz
5 87 6 motion.txt.gz
4 96 64 motion.txt.gz
3 1 0 *map.txt* For Vim version 8.0. Last change: 2017 Mar 10
2 56 23 :lm[ap]^I{lhs} {rhs}^I^I|mapmode-l|^I^I*:lm* *:lmap*
1 361 12 *omap-info*
>
Great! So far so good. But now I want to use CTRL-O to navigate back through the jump list, one-by-one, say all the way back to #7 above (line 313 col 19 in motion.txt.gz). I find that CTRL-O will work fine all the way to #3 above, like so:
:jump
jump line col file/text
6 1 0 help.txt
5 1 0 motion.txt.gz
4 313 19 motion.txt.gz
3 75 6 motion.txt.gz
2 87 6 motion.txt.gz
1 96 64 motion.txt.gz
> 0 1 0 *map.txt* For Vim version 8.0. Last change: 2017 Mar 10
1 56 23 :lm[ap]^I{lhs} {rhs}^I^I|mapmode-l|^I^I*:lm* *:lmap*
2 361 7 *omap-info*
But then the next CTRL-O does something I did not expect. Instead of moving me up one more position in the jump list, vim mysteriously treats my action as a jump from the beginning of motion.txt to line 96 col 64 of motion.txt, thus adding the beginning of motion.txt to the end of the jump list (and, by rules of the vim jump list, removing its duplicate from the list):
:jump
jump line col file/text
9 1 0 help.txt
8 313 19 character |linewise|.
7 75 6 *exclusive* *inclusive*
6 87 6 *exclusive-linewise*
5 96 64 motion isn't yet), a special set of mappings can be used. See |:omap|.
4 1 0 map.txt.gz
3 56 23 map.txt.gz
2 361 7 map.txt.gz
1 1 0 *motion.txt* For Vim version 8.0. Last change: 2017 Mar 12
>
While the end result is that I am indeed at line 96 col 64 of motion.txt (not shown by the >), the problem is that my jump history is now fudged. In fact the problem repeats itself with continued use of CTRL-O from #1 above to #2 above (the top of map.txt is added and I end up at line 361 col 7 of map.txt). Basically, I am unable to navigate back to line 313 col 19 of motion.txt as I had originally wanted to.
Would really love to understand what is causing this behavior. I think I've been encountering this problem repeatedly in vim for years and just never looked into it. I hope to finally find an answer. Thanks for any help!

Related

How to add a string to line 13 in my text file

I have a very large text file that is difficult to open in text editors.
Lines 12 - 15 are:
1 15.9994
2 24.305
Atoms
I would like to add:
3 196 to line 14 and then have a blank line between 3 196 and Atoms like it is currently. I tried:
sed '14 a <3 196>' file.data
But it did not seem to change anything. Anyone know of how I can do this?
Normally, sed only writes out the changes. It does not modify the file.
If you want the input file to be modified, you can use GNU sed -i:
sed -i '14 a <3 196>' file.data
Before:
[...]
9
10
11
1 15.9994
2 24.305
Atoms
16
17
[...]
After:
[...]
9
10
11
1 15.9994
2 24.305
<3 196>
Atoms
16
17
[...]
Note: If you want it after line 13 instead of 14, change 14 to 13 in your code. Similarly, if you wanted 3 196 instead of <3 196>, change <3 196> to 3 196 in your code.

Vim slow down in python mode after I type "=" (equal) or " "(while space).

It seems to happen after I installed YCM. I also have Python-mode plugin installed because I like the lint and "run inside vim" feature, but I turned off "rope". My YCM settings are like below.
31 " Use gcc syntastic checker
30 let g:ycm_show_diagnostics_ui = 0
29
28 " Skip checking of ycm config file at vim startup
27 let g:ycm_confirm_extra_conf=0
26
25 " Includes tags in completion
24 let g:ycm_collect_identifiers_from_tags_files=1
23
22 " Include text in comments and strings
21 let g:ycm_collect_identifiers_from_comments_and_strings = 0
20
19 " Start completion from second char
18 let g:ycm_min_num_of_chars_for_completion=2
17
16 " Disable chache, rebuild every time
15 let g:ycm_cache_omnifunc=1
14
13 " Enable syntax based completion
12 let g:ycm_seed_identifiers_with_syntax=1
11
10 " Enable completion while in comments
9 let g:ycm_complete_in_comments = 1
8
7 " Enable completion while in strings
6 let g:ycm_complete_in_strings = 1
I tried to profile vim, but I don't get a clue from the result. Below is my profiling report.
0 FUNCTIONS SORTED ON SELF TIME
1 count total (s) self (s) function
2 60 0.883352 0.782989 <SNR>93_GetCompletions()
3 2967 0.905869 0.579009 pymode#folding#expr()
4 1997 0.275032 <SNR>110_BlockStart()
5 302 0.168611 <SNR>93_Pyeval()
6 120 0.968933 0.066387 youcompleteme#Complete()
7 1997 0.051828 <SNR>110_BlockEnd()
8 76 0.030649 0.028957 <SNR>97_GetNearbyTag()
9 154 0.026513 <SNR>69_Highlight_Matching_Pair()
10 61 0.025747 <SNR>93_InsideCommentOrString()
11 61 0.057955 0.016587 <SNR>93_IdentifierFinishedOperations()
12 6 0.013762 0.013707 <SNR>93_OnFileReadyToParse()
13 60 0.012566 <SNR>93_OnCompleteDone()
14 4 0.011961 <SNR>143_SearchParensPair()
15 74 0.040687 0.010170 Powerline#Functions#fugitive#GetBranch()
16 76 0.114571 0.009806 <SNR>93_OnCursorMovedInsertMode()
17 2 0.006829 0.006792 SyntasticRefreshCursor()
18 61 0.040498 0.005477 <SNR>93_InvokeCompletion()
19 74 0.005211 308()
20 91 0.004580 Pl#Statusline()
21 74 0.005954 0.004241 <SNR>59_buffer_spec()
Vim doesn't stand asynchronous job control and is basically mono-thread, so he can only do one thing after the other.
You can't type text while YCM is working.
You should try NeoVim who stand it, it won't solve your problem but will minimize it.

Excel formula to get the count of certain value based on odd/even line

I have this data in Excel.
A B C
--------------------------------------
Line Number Value #1 Value #2
1 21 35
2 21 27
3 21 18
4 10 47
5 50 5
6 37 68
7 10 21
8 75 21
I tried to calculate the total "21" based on odd line number. In this situation, the answer should be 3. However, neither" IF(MOD(A1:A8,2)=1,COUNTIF(B1:C8,21)) " nor " {IF(MOD(A1:A8,2)=1,COUNTIF(B1:C8,21))} "worked and Google didn't yield anything helpful. Could anyone help me? Thanks!!
This works for odd lines:
=SUM(COUNTIF(A:B,21)-SUMPRODUCT((A:B=21)*(MOD(ROW(A:B),2)=0)))
there may be a better way of writing this formula.
Use this to count even lines:
=SUMPRODUCT((A:B=21)*(MOD(ROW(A:B),2)=0))

File Reading problems in Python

While Reading the files in python using
f = open ("filename.txt")
and accessing the data with
f.read(1)
and finally finding the position of stream usibg
f.tell()
for every step; We get a continous numbering starting from 0 to the current position.
The problem i am facing is that i am actually getting a random number as f.tell() for some positions and then continung the numbers.
For examle, the f.tell() outputs look something ike the following
0
1
2
3
133454568679978
6
7
8...
Any idea why this is happening?
My Code :
f=open("temp_mcompress.cpp")
current = ' '
while current != '' :
print(f.tell())
current = f.read(1)
f.close()
Temp_mcompress.cpp file :
#include <iostream>
int main(int a)
{
}
OUtput :
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
18446744073709551636
18446744073709551638
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
18446744073709551655
40
41
43
44
It seems I might have found the problem which may still be applicable to python 3.x:
source: http://docs.python.org/2.4/lib/bltin-file-objects.html
tell()
Return the file's current position, like stdio's ftell().
Note: On Windows, tell() can return illegal values (after an fgets())
when reading files with Unix-style line-endings. Use binary mode
('rb') to circumvent this problem.

How can I align columns where the biggest number or greatest string is the align indicator?

How can I right align (and left align?) a block of numbers or text in vim like this:
from:
45 209 25 1
2 4 2 3
34 5 300 5
34 120 34 12
to this:
45 209 25 1
2 4 2 3
34 5 300 5
34 120 34 12
That means the biggest number or greatest string in every column doesn't move.
In the first column it is 45+34, in the second column 209+120, in the third column 300 and in the last column 12.
Have a look at the align plugin, it can do this and much more. Great tool in your utility belt!
Found here
After some serious vimhelp/reading I found the correct AlignCtrl mapping...
Visually select the table, e.g. by using ggVG, then do a \Tsp i.e. <leader>Tsp
Then I get this:
45 209 25 1
2 4 2 3
34 5 300 5
34 120 34 12
From vimhelp:
\Tsp : use Align to make a table separated by blanks |alignmap-Tsp|
(right justified)
You can look into the Tabularize plugin. So if you have something like
45 209 25 1
2 4 2 3
34 5 300 5
34 120 34 12
just select those lines in the visual mode and type :Tab/ and it will format it as
45 209 25 1
2 4 2 3
34 5 300 5
34 120 34 12
Also, it looks like you don't have an equal number of spaces separating the numbers at the moment. So before you use the plugin, replace all the multiple spaces with a single space with the following regex:
%s![^ ]\zs \+! !g
With the Align plugin you can select the rows you want to align and hit :
<Leader>Tsp
From Align.txt
\Tsp : use Align to make a table separated by blanks |alignmap-Tsp|
(right justified)
(The help mention \ because it is the default leader but in case you have changed it to something else you must adapt accordingly)
Just trying on my install, I got the following result :
45 209 25 1
2 4 2 3
34 5 300 5
34 120 34 12
In my opinion Align plugin is great but the "align maps" and various commands are not really easy to remember.
With the Align and AlignMaps plugins: select using V, then \anum (AlignMaps comes with Align). One advantage of \anum is that it also handles decimal points (commas) and scientific notation.
I think the best thing to do is to first eat all multiple spaces with
:{range}s/ \+/ /g
And then call Tabularize
:Tab / /r1
Or change that r to l.

Resources