So in VIM, I do select all the lines demanded using V (visual-line mode).
Then I want to align all the lines into she same position, how do you do that?
If you look at a the screen, you will notice that I have selected the lines and then I can possibly do < but that will only align some of the lines to the very beginning and then I have to press > in order to align them outwards.
Can I align all the lines into the same position?
From :left:
:le :left
:[range]le[ft] [indent]
Left-align lines in [range]. Sets the indent in the
lines to [indent] (default 0).
Have you tried?
gg=G
Because the = in normal mode reindents lines based on your settings
Related
I'm found of Ctrl-V select your block I type yours characters ESC
with vim, that helps a lot to indent a block by adding few characters on its left.
Very useful to put > when you forgotten them, for example!
But how to do the opposite?
Unindent a block, but the same way I've indented it: by removing few contiguous columns of selected lines?
# I have this text:
ABC%/1234
DEF$-542
GHI§*756
JKL£^288
I want to shift left my text for two columns for some of its lines.
Remove the:
%/
$-
§*
characters that are disturbing me on columns 7 and 8 on three of the four lines of data.
Starting with the caret on the % of my text,
what block command and other command should I type to achieve the result I'm willing? This one:
# I have this text:
ABC1234
DEF542
GHI756
JKL£^288
Visual-block mode is just a special case of visual mode: once you have selected the text you want to delete, well… press d to delete it.
The various visual modes are introduced in chapter 4 of the user manual, :help usr_04, with the example for visual-block mode being pretty much exactly what you want to do:
<C-v><motion>d
I would suggest you take the time to learn Vim properly instead of trying random commands found on the web:
:help user-manual
As you can see in the image the selected line is black and the empty lines in the buffer are a different colour is there a way I can use the highlight command in order to make empty lines completely black like the selected line?
I solved this by highlighting this field:
hi EndOfBuffer guibg=black
Intro
In gVim under Windows i have to replace insert and mod in each string of file some character in a specifics position.
Example
QWAER;PA 0X000055;123WAAAA
TYUIO;PA 0Y000056;123VAAAA
need to become
QWAE#;PAX000055;123;WAAAA
TYUI#;PAY000056;123;VAAAA
modify char 5 in #
delete char 9,10
insert ; in original pos 22 or after delete in pos 20
More Info
Usually I do
Put cursor and beginning of text to select
Press CTRL-V (CTRL-Q in gVim) to begin select of the column
keep press SHIFT and selecte the interested area
the go at the end of file
then do the replace insert or modification.
(This is where I learn about Keyboard-only column block selection in GVim Win32, or why does Ctrl-Q not emulate Ctrl-V when mswin.vim is included?
and here i learn how to do the insert(http://pivotallabs.com/column-edit-mode-in-vi/)
It's not a correct way to do the things.
In vim i can do the replaceof a fange of rows, and so on using commands.
I think that should be possible to use commands to replace a portion of each string but i have no Knoledge about those command.
this is the main idea
Replacing alternate line in vi text file with a particular string
Question
Is there a way to do the operations using commands with absolute position and not selection.
Thanks
:{range}normal 5|r#9|2x20|i;
Does what you want on the lines covered by {range}:
5|r# " go to column 5 and replace the character with #
9|2x " go to column 9 and cut 2 characters
20|i; " go to column 20 and insert a ; to the right
So…
:5,25norm 5|r#9|2x20|i; would apply that transformation to lines 5 to 25,
:.,$norm 5|r#9|2x20|i; would apply that transformation from the current line to the last,
:'<,'>norm 5|r#9|2x20|i; would apply that transformation to the current (or last) visual selection,
:'{,'}norm 5|r#9|2x20|i; would apply that transformation to the current "paragraph",
:%norm 5|r#9|2x20|i; would apply that transformation to the whole buffer,
and so on…
You could also record it, let's say in register q:
qq
5|r#
9|2x
20|i;<Esc>
q
and play it back on {range}:
:{range}#q
Or spend 30 minutes trying to come up with the right :s// command…
Reference:
:help range
:help :normal
:help |
:help r
:help x
:help i
:h recording
I want to indent an entire text file with n spaces in VIM.
My current method is:
Go to the beginning of the file
Type Ctrl + V
Press the down key ↓ or the j key to select the lines to indent
Type Shift + I
Type the Space Bar key n times
Press Esc
Is there a way to accomplish this without using visual mode and having to manually go through the entire file?
Use a Global Substitution
Assuming you want to indent four spaces, you can do this:
:%s/^/ /
This will effectively insert four spaces at the start of each line. Adjust the number of spaces on the right-hand side of the substitution expression to suit your indentation needs.
Using Visual Mode
Alternatively, you can go into normal mode and then:
gg
SHIFT+V
SHIFT+G
SHIFT+>
to indent the entire file by the value of shiftwidth.
how about:
:%s/^/(you count n spaces here)/
A :normal variant that adds two spaces at the beginning of every line:
:%norm 0i<space><space><CR>
Another :normal variant that adds two spaces before the first printable character of every line:
:%norm I<space><space><CR>
You can indent a set of lines like this:
:1,44>
If you press ctrl-g, it will give you the last line of the file.
Is there a command in vim which will delete n lines in the up direction.
I know I can use 4dd which will delete 4 lines downwards.
In VIM, 3dk would delete 4 lines in the upward direction. Further documentation can be found at http://www.vim.org/docs.php
V3kd would do it.
Thats "V" to enter visual line select mode, "3k" to move up 3 lines, and then "d" to delete the 4 lines you have selected.
You can do it with a backwards range.
:-4,.d
Deletes from minus 4 lines to current. But this is an ex mode command.
Position the cursor where you want to begin cutting.
Press v (or upper case V if you want to cut whole lines).
Move the cursor to the end of what you want to cut.
Press d.
Move to where you would like to paste.
Press P to paste before the cursor, or p to paste after.
http://vim.wikia.com/wiki/Copy,_cut_and_paste
stand at the end of the last line
hold Backspace and wait until the last character of the first line is deleted