effective use of vim: "incredibly tips, part I"
Kind all time of the day
trying to keep my promise, I want to publish a trace. article about the vim editor
The article assumes that the reader is already familiar with the basics of working in vim, she will be devoting more efficient use of the accumulated knowledge.
tips 1:
tips 2:
tips 3:
example:
has a line:
$ i-> love () -> mylove () -> because-> sheis-> VerySuccessfully ();
you need to print
$ i-> love () -> mylove () -> because-> sheis-> VerySexy ();
all that is highlighted in black is printed using CTRL-Y ,
they actually printed only VerySexy ();
example:
has a line:
$ i-> love () -> mylove () -> because-> sheis-> VerySilly ();
we want to build it here:
CRTL-A (and that's it, you don’t need to switch to another mode, copy it, etc.)
$ i-> love () -> mylove () -> because-> sheis-> VerySilly ();
spice 3, why consider, why suffer when there is CTRL-R =
* / # - search for the next / previous position of the word
[I,] I - shows all the lines that contain the word under the cursor
hmm ...
for more convenient use, let's do:
trying to keep my promise, I want to publish a trace. article about the vim editor
The article assumes that the reader is already familiar with the basics of working in vim, she will be devoting more efficient use of the accumulated knowledge.
tips 1:
I forgot which file I’m editing ...
view the file name - CTRL-G
"php.ini" 1255 lines --1% -
detailed information - gCTRL-G
Col 1 of 71; Line 18 of 1255; Word 79 of 6980; Byte 563 of 44684
tips 2:
You do not use gi ?????????
gi - very useful
you write in the 143rd line of the php.ini file, exit the insert mode, look at another file \ buffer, press gi and continue editing the 143rd line of php.ini.
tips 3:
Girl, we repeat!
spice 1, single repeat
CTRL-E, CTRL-Y in command mode, shifting the screen 1 line below / above
in insert mode inserts characters from the lower / upper line
example:
has a line:
$ i-> love () -> mylove () -> because-> sheis-> VerySuccessfully ();
you need to print
$ i-> love () -> mylove () -> because-> sheis-> VerySexy ();
all that is highlighted in black is printed using CTRL-Y ,
they actually printed only VerySexy ();
spice 2, repeat last entry
CRTL-A - inserts the last entered sentence (in insert mode!)
example:
has a line:
$ i-> love () -> mylove () -> because-> sheis-> VerySilly ();
we want to build it here:
CRTL-A (and that's it, you don’t need to switch to another mode, copy it, etc.)
$ i-> love () -> mylove () -> because-> sheis-> VerySilly ();
spice 3, why consider, why suffer when there is CTRL-R =
insert mode:
CRTL + R = 5 * 5 + 25 - insert 50;
spice 4
: read! date - inserts the current date
: read! cat file - inserts the contents of the file
: grep -iR "TODO" * + copen - shakes all TODOs in the project
: read! cat / dev / random - gives the administrator \ current user password ( ONLY FOR true unix users !?) the main thing is do not forget CTRL + C to press
spice 5 paragraph
CRTL-T, CRTL-D insert paragraphs in edit mode
Search is natural
* / # - search for the next / previous position of the word
[I,] I - shows all the lines that contain the word under the cursor
hmm ...
for more convenient use, let's do:
: nmap [I: let nr = input (“Which one:„) exe “normal”. nr. "[\ t"
so my mouth has already closed, and faith in reality seems to have returned, although spiritual values and faith in other editors no longer seem to resume ...
I will continue ...Searching in vim is natural
repetition - mother of learning
/ - looking for a track entry ? - searches for the entry n - repeat the last search
N - repeat the last search in the opposite direction
so:I would like to touch on the topic of regular expressions (bl *, pi **** =)
unfortunately regular language is a topic for the whole book.
here I want to show examples that I use more often than others:d / ^ # - delete everything from the current line to the first comment, asking for confirmation
10d / ^ # - respectively, until the 10th
y / ^ class /; function selects everything from the current position to the first occurrence of function in the class class.
:% s / foo / bar - replaces foo with bar in the whole file (equivalent: 1, $ s / foo / bar /)
:., / <\ / body> / s
,, <br />, gc - edit tag
from current line to tagwithout spaces, this was the habro-effect
(c - “cautios”, warn) the
author was so drunk ... that left the reader the opportunity to comment on the mark. expression::
-23, 'ts / wow / WOW /
?
& - repeat the last replacement in the current line
: && - repeat the last replacement in the current line with the same flags
g & - repeat the replacement for the entire fileshift + left to left left notepad’s hands move
aw, iw, as, ap, a {- vim’s soul sings
go to viral mode:iw, iW - highlight the word
aw, aW - highlight the word, whitespace is not counted
as, is - highlight the sequence of words (as, is - there is a difference, see - iw, aw)
ap, ip - highlight the paragraph
a {, i { - select the entire block {..} or the text inside it
a (, i ( - select the entire block (..) or the text inside it
a <, i < - select the entire block (..) or the text inside it
a ', i' - select a single-quote line or text inside it
a ", i" - select a double-quote line or text inside it
(vim knows that \ "does not need to be taken into account)
at, it - select the entire tag or text inside it (hi XML & HTML)
examples:
das - delete a sequence, including whitespace after it.
ci ( - replace the text inside (...)
yat - copy the entire tag inside which the cursor is
gU ' - sql queries are written in upper case! (changes case in the single-quote line to upper)
vip - selects the entire paragraph without whitespacesmart insert
: set autoindent - Formats a paragraph when inserting a new line.
] p,] P - insert before / after and format the indentation is
not always convenient (
: nnoremap P P '[v'] =
: nnoremap P P '[v'] =
to] - I do not reach, therefore I usework with registers
was partially described in the pre - habrahabr.ru/blog/vim/45414.html
I would like to add:“0 is the last copied text that was not entered into the register
” 1 - the last deleted text that was not entered into the register
(“ - and was longer than one line)
...
“ 2 - “9 deleted text for the 2.9th command
”. - last inserted text
"% - name of the current file
" _ - black box register (its use does not affect other registers in any way)
: reg - displays the value of all current registersmacro recording
q starts recording a macro, sequential q stops recording
@ executes the macro
@@ executes the last executed macro,
I think here you can give a small example
earlier in the code wrote
global $ db;
Now the style has changed a bit and I began to write
$ db = Database :: get ();
There is a lot of such code, although it is very small.
What actions do I need to replace it?
1.find global $ db;
2. replace global $ db;
3.on $ db = Database :: get ();
now through vim;
1st item -: grep -iR "global $ db;" * I
’ll try to make the 2nd and 3rd macro:
so, after the 1st item, command mode, press qa, d2W, i
enter $ db = Database :: get ( );
q.
wrote a macro
: copen
we are looking for the trace of the occurrence of global $ db;
now just press @a we’ll
go to the next occurrence
ps I ’m sorry to say that this is something like hello world for macros, those are a very simple example.Thourht time in the past
probably one of the vim’s features that amazes me =)
g- / g + - we slide between the older / newer text
: earler Ns, m, h - return the contents of the file that was s, m, h “time” later
: later - the opposite, return the contents of the file, which was s, m, h “time” after
: ealer 60m - damn it, well, they sold me wine today =)
thank you all for your attention ...
ps have any questions? write, a collective mind will help you!