I am editing a large text array in vim, and I want to compute on one sub-column of it.
Simplified example of edited file:
name value name saturation
red 5 green 2
blue 7 yellow 7
other text
I want to pipe column 4 through an external program calc.pl,
calc.pl replaces numbers with new numbers in the input, for example:
name value name saturation
red 5 green 2.4
blue 7 yellow 7.14
other text
When I select rectangle in column 4, using v.motion, and !perl calc.pl
the whole lines gets piped to calc.pl, not just the rectangle.
A work around would be to: cut rectangle to temp file,
run calc.pl on temp file, and then read output as rectangle.
Is there a straight forward solution in vim, without having
to cut/shell/paste?
You might try the vis plugin by Charles Campbell
Use ctrl-v to select a column, then apply an external filter to that column. ctrl-v ..move.. :B !sort
Another plugin that might work for you is NrrwRgn by Christian Brabandt.
Use :NarrowRegion to narrow a line based selection or alternatively visually select a range and press nr
In the scratch buffer simply save it and the changes will be copied into the original file.
This is only a very simple help. You should probably read the help, that is provided with the plugin. See :h NarrowRegion
Related
General text editors can jump to a specific column number of a file by either using movement keybindings or mouse click.
This can only happen if there is already character or whitespace on that column, otherwise the cursor will be lock to the last column which contains that character or whitespace.
For example, in the following line:
1 2 3 4 5
012345678901234567890123456789012345678901234567890
The quick brown fox jumps over the lazy dog
I want to jump to column 35, just before the word lazy, I can click on the mouse to that column or use 8 words movement to get to that position.
If I want to jump to column 50 I can only get to column 43 because that is the newline character and there are no more characters after that.
Now I remember I used a text editor that I could click on the column 50 and automatically will insert the whitespaces and move the newline character to that column, but could not remember which text editor was.
So, I am wandering which text editor is able to do that, or a script for vim that can actually achieve the same effect.
Thank you
:set virtualedit=all
Afterwards 50| will jump to the 50th column, even when the actual line is shorter than that.
More information: :help 'virtualedit'
I have to compare two (assembly) files and see where the instructions do not match.
In the vimdiff I use there are two colors to mark the difference in text.
1. blue: when there is no text in the other file to compare.
2. pink: when both files have similar text but they differ in a few characters.
The lines which match completely have a black background.
I am looking for a shortcut to hop from one 'blue' area to the next.
Use [c to jump to the previous change and ]c to jump to the next change.
And read :h diff.
If I have this line visually selected
Alpha <-- selected
Bravo
Charlie
is there a vim command to move the selected area down, without adding to the original selection?
Alpha
Bravo
Charlie <-- selected
hjkl key will only add lines to your selection. And I didn't see anything in visual's help doc that indicated it could be done.
In selection mode, you can use o (lowercase o) to swap between moving the top and bottom boundary. So you can do this without leaving selection mode using jjojj.
This will certainly do it:
jjVV
But it isn't really any different from canceling the original selection first:
escjjV
Or:
VjjV
as far as I understand your question, you would like to select Alpha and move it down. Let us say move Alpha under Charlie. You need to select Alpha in visual mode and then type : (colon) and type m 3. So your typing format should like :m 3. This means that move selected text to line 3. I hope this will be your question answer. Have a great day.
I am a bit of a beginner when it comes to Vim and it is currently irritating me in many ways. One of which is the following:
Say i have the following text in a file
one
two
three
four
dog
frog
log
mog
and I have used visual mode to select the number words (4 lines) if I then use P to paste at the 'd' in dog i get the following:
one
two
three
four
one dog
two frog
threelog
four mog
My desired output would be:
one
two
three
four
one
two
three
four
dog
frog
log
mog
I've noticed that it behaves as I expect if i do a y4y instead of visually selecting the lines. So what is causing the difference in behavior that I am seeing? and how can I get my visually selected block to paste as I would like?
Seems that you are entering into the Visual Block selection mode (Ctrl-V).
To get your desired output, enter into a Linewise Selection mode, just by pressing V.
Use Shift+V, it selects line by line
try
:set paste
before pasting.
I have a vertically split window and the window is further horizontally split within each column. I want to make the height of the windows within one column the same, but do not want to change the heights within the other (let's say, one window in the other column is set to highest possible, like by using CTRL-W_, and I don't want to change that). What is the easiest way possible to accomplish this?
If the equalalways is on (it is by default), closing a split resizes the remaining splits to be equal. So just create a new split and then close it.
:new | q
Mapping it to a key (e.g. Leader+eq) would look like so:
nnoremap <Leader>eq :new \| :q<cr>
The easiest way that I can think of is using a mouse
:set mouse+=a
and then use your mouse to drag and resize the screen to fit your requirement accordingly.
Without the mouse, It is possible but involves extra typing. Go to the column
that you want to resize.
Then :resize #, where # is calculated from output of (set lines -2)/2 where 2 is accounting for cmdheight and 1 for statusline. The number need to be adjusted accordingly for "cmdheights and statusline". This is cumbersome.
The trick from #Ondrej should be preferred if mouse is disabled in vim