g]
, then this command will be used much more often.
ciw
(not to be confused with the CIA, the CIA manual on Vim ) and the like. And there are articles of experts who are immersed in subsystems. But no one really talks about these special tricks that make exclaiming: damn it, how I needed it in the last six years!
<cr>
means pressing the Enter key. When you need to get help :h
for a specific line, for example :h E676
, then the line will be in brackets.
":
is the register that stores the last command executed. You can type ":p
to print it to the buffer. @:
repeats the last command.
"=strftime("%c")<cr>p
.
m{letter}
sets the mark at the cursor location. Then '{letter}
will go to this line. For lower case letters, it acts within the limits of the buffer, therefore it is suitable for navigation. For capital letters, it acts globally: even if you are in another file, 'A
will go to the file with the label
You can view all your tags with the command :marks:
10c-A
much simpler than wwwwwciw20
.
<CR>
. This allows you to quickly change and restart commands or look for old ones for reuse.
q:
except search.
v_O
.
g ctrl-A
will increase the increment by one with each line. This is much easier to explain in the table:
selected | ctrl-A | g ctrl-A | 2 g ctrl-A |
---|---|---|---|
a 0 b 0 c d 0 | a 1 b 1 c d 1 | a 1 b 2 c d 3 | a 2 b 4 c d 6 |
abc
abc
abc
b
and press d2j
, it will delete all three lines, because j
moves line by line. If you press d<cV>2j
instead, the movement becomes block by block and only the middle column with three letters b
is deleted.
d/
moves character by character. Therefore, I use dV/
for line-by-line movement with deletion. There is another way to do this:
regex
, you can enter d/regex//0
.
:s
. In addition to the replacement, there are many other useful commands. All of these examples require a range, such as %
.
g/regex/d
to remove all lines that match regex. The v
command is similar to g
, but works on all strings that do not match the regular expression.
g/regex/norm f dw
will remove the first word after the first space in each line corresponding to the regex regular expression. This is often much simpler than a macro.
norm
is subject to all your comparisons. For example, if you assigned the jk
keys to <esc>
in insert mode, then norm I jk$diw
adds a space to the beginning of the line, leaves insert mode , and then deletes the last word in the line. I really like this functionality, but if you prefer not to use your own mappings, you can then apply norm!
.
+3
or 'a. mv
'a. mv
to move.
{reg}
. If {reg}
capitalized, it is added to the existing register. i.e. such a command
let @a = '' | %g/regex/y A
a
all the lines corresponding to the regex
in the whole file. It helps to extract broken text from a file and copy it to the system clipboard (using let @+ = @a
).
:windo $
all windows down. There are bufdo
, cdo
, tabdo
and others.
g
and s
. To replace all AA
combinations with BB
with replacement preview, you can enter vimgrep AA
by loading all matches in quickfix, and then cdo s/AA/BB/cge
to search / replace all matches.
H
to the cap ^
, so these things are not worth mentioning. Also, it makes no sense to talk about vim-sensible
or vim-surround
, but only about more exotic plugins.
command! Vimrc :vs $MYVIMRC
n
, the more convolved blocks are shown in the column, and for the others the number is indicated.
gf
usually means “go to the file under the cursor,” but it requires the file extension in the string. suffixesadd
adds the specified extension. If you set suffixesadd=.md
, then the gf
command on the 'foo' line will look for the files foo
and foo.md
incommand
shows in real time what changes the team will make. Now only s
is supported, but even this is incredibly useful. If you enter :s/regex
, all matches will be highlighted. If you then add /change
, it will show all replacements. Works with all regular expression properties, including backlinks and groups.
:set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
%P
(the percentage of the file above the cursor). The format of the status bar is the value after the percent sign in curly brackets. Therefore, for Markdown files, you can write this:
:set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %{wordcount()[\"words\"]}
tabline
. If you do not use tabs, then this line can be made a “global status line”. For example,
set tabline=%{strftime('%c')}
s
is synonymous with cl
(saving one pressing), and U
is the same as u
, except for recording undo as a new change, which is functionally useless. Q
identical to gQ
and in any case is a huge trap. Z
used only for ZZ
and ZQ
. Heck, even the Vim manual recommends reassigning the _
keys and ,
for some functions, since “you probably never use them”. I would prefer not to save one click, but to add completely new functions to the keyboard. Here are some of my bindings:
s
key (with the appropriate settings for ss
and S
) to work as d, only without saving the deleted text in the register. Useful in order not to litter the register.
h
, k
, l
. Working with windows becomes much easier.
q:
.
map <buffer> lhs rhs
command map <buffer> lhs rhs
activates key assignment only for this buffer. It really works conveniently with autocommands as a temporary keyboard shortcut or when defining assignments through a function. Buffer assignments take precedence over global ones, that is, you can redefine a common command more useful in a particular situation.
map <expr> {lhs} {expr}
command map <expr> {lhs} {expr}
checks {expr}
and uses the return value as the final key remap. One simple use case is binding depending on conditions. I have these:
nnoremap <expr> k (v:count == 0 ? 'gk' : 'k')
nnoremap <expr> j (v:count == 0 ? 'gj' : 'j')
j
and k
to move along the line until a number is encountered, and after that the key assignment is canceled. Therefore, I can move through long paragraphs of prose without disturbing combinations like 10j
.
<silent>
argument helps if some bindings run ex commands.
inoremap
bindings work in insert mode. There they start working, so inoremap ;a aaaa
will enter 'aaaa' instead of '; a'. If you want to do something normally, use <cO>
. For example, if we have
inoremap ;1 <co>ma
;1
set at this point the label 'a
.
augroup {name} autocmd! " Prevents duplicate autocommands au {events} {file regex} {command} augroup END
:h event
. For example, if you write
augroup every autocmd! au InsertEnter * set norelativenumber au InsertLeave * set relativenumber augroup END
au {event} <buffer> {ex}
command applies the autocommand only to the current buffer. Sometimes I use this to add short-term event handlers to a specific file.
BufnewFile
launched when creating a new file, BufRead
- when you first open the buffer. They are usually used to add parameters and reassignments to specific file types. I have one such:
augroup md autocmd! au BufNewFile,BufRead *.md syntax keyword todo TODO au BufNewFile,BufRead *.md inoremap <buffer> ;` ```<cr><cr>```<Up><Up> augroup END
;`
in insert mode adds a code designation.
au
for BufWriteCmd
overrides the standard save, allowing you to implement non-standard logic. It goes beyond the "tricks" and goes into the area of ​​"dark magic".
vim-surround
and NERDtree
. Here is a list of some lesser known ones that I find very useful.
u
command rolls back the action in the current tree branch, and g
moves to the previous chronological version. You can view the list of canceled actions with the command :undolist
.
Undotree
does: lays out a good ASCII representation of the tree of undone actions with easy navigation.
(a, f(b, c))
with (f(b, c), a)
in a couple of keystrokes. I regularly have to make such edits, so this is a strong improvement in the quality of life.
:T {text}
sends {text} to the console. Good for creating an interactive environment.
Source: https://habr.com/ru/post/454742/