I know gv shows the last selection, but can I give the selection a name, so that later I can get the selection through its name? It's ok if the region is remembered by row and column.
Selections can't be named, but positions can. If the selection is gone:
`<ma`>mb
Saves the selection start and end to a and b markers. (The marker < is the selection start, > is selection end; we simply assign them to any custom markers, a-z.) If the selection is current, you can even do this (but pay attention to if you're top or bottom):
mboma
(o means "go to the other side of the selection"). Then, later,
`av`b
Reselects the selection corresponding to a and b markers.
Related
For example, I want to select lines starting with B28, B29 and B30 using Shift + v in row B28 , then select row B29 and so on..., then press 'd' and then move to ROW 1 and press 'Shift-p' in the first row to paste all these rows there.
ROW 1
A26 51.00824
D26 35.94841
D27 35.94841
B28 7.07486
A28 35.95497
D28 179.99932
B29 4.15400
A29 90.00068
D29 179.99932
B30 7.07490
Visual mode(s) can only select contiguous regions (this applies to characterwise, linewise, and blockwise visual mode, regardless of the value of virtualedit). The only exception is ragged line-endings with, say, vip$.
But you can accomplish your goal other ways. For example:
:global/^B\d+/move /ROW 1/-
Should move all lines starting with B followed by digits to the line after ROW 1. (They will probably be reversed; in your case, a simple :sort n will probably be do, but generally :[range]!tac or :[range]global/./move <firstline> can reverse lines.)
Or, you could record a macro like so:
Mark insertion point: :/ROW 1/mark a
start a recursive macro in register q: qqqq (the first three clear the register)
go to next occurence to move /^B\d+
move it dd'ap
adjust mark ma
recursive invocation #q
fini q
Now hit #q and watch the magic.
If you needed to repeat the above many times for different things, I would write a series of commands to get it working once, then turn that into a function and generalize the things that are variable. VoilĂ , automation.
Another method, just for fun:
:g/^B/normal! dd1G}P
:g/^B/<cmd> executes <cmd> on every line starting with a B,
normal! <macro> executes normal mode macro <macro>,
dd cuts the line to the unnamed register,
1G moves the cursor to line 1,
} moves the cursor to the empty line after the current paragraph, this is key because it allows us to put the next line below the last one that was put and thus to respect order,
P puts the content of the unnamed register above the current line.
Reference:
:help :global
:help :normal
:help /^
:help dd
:help G
:help }
:help P
--- EDIT ---
There are plenty of ways to address your target, even if it is not on line 1.
With a line number:
:g/^B/normal! dd23G}P
With a mark:
ma
:g/^B/normal! dd'a}P
With a search:
:g/^B/normal! dd?ROW1^M}P " ^M is obtained with <C-v><CR>
Say I have the following code
aaa;
bbb;
ccc void () {
xxx;
yyy;
}
ddd;
eee;
Now suppose my cursor is at yyy. I'd like to highlight all code between the parenthesis { and } inclusive of the complete line the brackets are on. This means the highlight will look like
before select
after select
va} is not a solution as that produces this
Effectively it should be a linewise selection. But the corresponding "text-object" forces a charwise one (so there's no difference between va{ and Va{).
However, you can make a selection linewise anytime. So va{V achieves the desired result.
I'm not sure if any mapping is needed at all. But at least ab should not be touched as it normally stands for parentheses ("()-block").
vnoremap aB aBV
Now vaB will select {}-block linewise, while va{ will do "normal" {}-block selection.
nmap vab va{$o0
Breaking it down
vab
highlights within the brackets inclusive of the brackets. The cursor finishes at the end of the highlight.
$
moves the cursor to the end of the line
o
moves the cursor to the other end of the highlight block
0
moves the cursor to the start of the line
If I have a visual selection in vim, how do I expand the selection to include the next paragraph? Also can I press o and do the same to select the previous paragraph?
You can use the ap or ip text-objects for "a paragraph" or "inner paragraph". A paragraph is a block of text separeated by blank lines. ap also includes the blank lines after the current paragraph. There is also { and } motions to move amongst paragraphs.
So to get the next paragraph you can do 2} or }ap.
For the previous paragraph, indeed, use o to go to the other end of your selection and 2{.
You can also add a count to ap, e.g 2ap will select the current and the next paragraph.
I am facing a challenge. In a chart with multiple lines, I would like to able when I click on a line or mouse over a line to see the corresponding datapoint in the the table or pivot table...So basically, filtering a table based on the element i click or select on a chart with my mouse.
Do you think that it is achievable ? What would be the methodology ? Is there a VBA code for this ? I have seen examples, but they are working on the oppiste way; click or mouse over an observation and the line is highlighted...
Thanks in advance
saskap
This is really complicated, you have to customize the code for each chart, this example code can be a starting point:
Dim p As Series
Dim pc As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ch As ChartObject: Set ch = Me.ChartObjects("Chart 1")
With ch
Dim s As Series: Set s = Nothing
On Error Resume Next: Set s = .Chart.SeriesCollection(Target.Value): On Error GoTo 0
If Not p Is Nothing And Not p Is s Then
p.Format.Fill.ForeColor.RGB = pc
End If
If Not s Is Nothing Then
Set p = s
pc = s.Format.Fill.ForeColor.RGB
With s
s.Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
End With
End If
End With
End Sub
The first two rows are global variables that store which Series
object was highlighted last time and what was its original color,
this is needed to restore the original color when a different cell is
selected. Unfortunately global variables in VBA loose their value when the project is reset (e.g. the Stop button is pressed or an error occurs), so it is possible that this code colors a bar and then cannot color it back. If important, these information may be stored in invisible Cells or Chart data but that complicates the code.
The next line means that this is an event handler, a function that is called in response to a certain event, in this case when the selection changes on a certain worksheet (the one on which you insert this - you have to insert this into a worksheet module not a standard code module).
Next we look up the chart based on its name and assign it to a variable, which is of type ChartObject, so early binding will allows us to depend on the support of intellisense (if you type a . it shows members of interfaces).
Then we look up the Series inside the chart based on the name found in the newly selected cell's contents. Since we don't know if the new cell will have a valid name, we have to protect this line with disabling error handling and checking later if the s has a non-nothing value. - This part depends largly on the type of chart and how it represents data, it is possible that you will have to select data based on Series::XValues.
We check if there is a saved value for a previously highlighted bar and if it is different from the current selection, restore its original color.
Finally if the looking up the Series earlier was successful then s is non-null and we save the color of the current bar and highlight it with red fill.
I'm using Power Builder 10.5 and I'm having a problem that seems simple at first, but can't get near the solution.
Is it possible to color rows differently depending on a condition? I have a select statement that retrieves numerous rows, that have different status: status A means the row is active, ERR that something is wrong, F that is finished, and so on...
What I need is the color of the column with status "ERR" to be red, and the color of the column with status "A" to be green. All else columns may be white.
I can do only half the job at the moment. I've added a dummy field in my Data Window, called "color". For all the cells I've written this in the design view, background color properties..
IF ( color =1, 65280, 16777215)
Now I move to the clicked event of my OK button where I retrieve data...
dw_1.Retrieve()
FOR ll_=1 to dw_1.RowCount()
ls_status=dw_1.GetItemString(ll_,"status")
IF ls_status='A' THEN
dw_1.SetItem(ll_, 'color', 1)
ELSEIF ls_status='ERR' THEN
??????
END IF
NEXT
The part with question marks is where I can't move forward. This highlights all my rows where status is "OK" green, but I can't seem to get the error ones red. I've tried manipulating the code in background color properties (trying to give him a condition if color=2), but I just keep getting the "Expression not valid" message.
Modify method also didn't help me much, as I can't seem to make him color only does rows with "ERR" status using Modify method.
Any advice will help.
You should set your 'color' column in the SQL statement itself.
SQL something like
CASE status WHEN 'ERR' THEN 'R' WHEN 'A' THEN 'G' END
Then in an expression on the background color of the columns of your datawindow you can put something like
if (color[0] = 'R', RGB(255,0,0), if (color[0] = 'G', RGB(0,255,0), RGB(0,0,0)))
In the datawindow properties of the object or band, go to the background tab. The Color property has a little button with an equal sign (=) on it. Click that and write an expression to derive a RGB value based on the value of a column.
I wrote an article about this stuff here: PBDJ Article
You can use case statements in the computed property. Something like this:
case( status when 'ERR' then RGB(255,0,0) when 'A' then RGB(0,255,0) else RGB(0,0,0) )