Depending on what fits your situation you could look into customizing the filetype plugins (if you want tabstop settings by filetype) or enable modelines and accept the accompanying security risks if the settings are specific to individual files.
For the filetype approach, as an example I have the following in ~/.vim/after/ftplugin/python.vim
:
setlocal expandtab softtabstop=4 shiftwidth=4
By default, the paste commands use the "
(“unnamed”) register. Effectively, any command that writes to a register also writes to the unnamed register, so yanks, deletes, and changes all affect it. This is why your yank-delete-paste sequence pastes the deleted text instead of the yanked text.
The 0
register can help here. Any yank commands that do not specify a register put the yanked text in register 0
(in addition to "
). It is not affected by delete or change operations, so you can use it to paste a yanked line multiple times even if you do intermediate deletes or changes.
yy
: Registers 0
and "
both now have the yanked line.
- Move to a line to replace.
dd
: Register "
now has the deleted line, but register 0
still has the yanked line.
"0P
: Paste the originally yanked line from register 0
.
- Move to the next line to replace.
dd"0P
(same as above)
(Due to the way cursor positioning works when replacing the last line of a buffer, you will want to use "0p
instead of "0P
.)
This is very close to Bruce Ediger’s answer, except that you do not have to specify a register when initially yanking. Using one or more named registers can be very handy though if you need to (for example) replace some lines with AAA
, but other lines with BBB
(put AAA
in register a
, and BBB
in register b
(or leave one of them in register 0
), then paste them accordingly).
You can also paste from 0
in line-wise visual mode (V
) to save a keystroke: V"0p
.
If you do not like having to type "0
, you might find a mapping more convenient:
noremap <Leader>p "0p
noremap <Leader>P "0P
vnoremap <Leader>p "0p
An alternate approach is to delete to the _
(“blackhole”) register. When you delete to it, the "
register is not affected, so your yank-delete-paste sequence can still paste the yanked text from the unnamed register.
yy
: Register 0
and "
both now have the yanked line.
"_dd
: No change to the registers.
P
: Paste the originally yanked text from register "
.
Again, you might find a mapping more convenient:
noremap <Leader>d "_d
Best Answer
You can count words and lines inside
vi
usingvi
's own counter:Press g and then CTRL-g. Then the bottom line look for example like this:
Or use
vi
's method to call shell commands:This calls the save (
:w
) command first and thenwc -w
and shows the output. Example:Press Enter to go back to
vi
.