Tip #272: automaticaly formating pasted text (p=`])
tip karma |
Rating 28/10, Viewed by 1568
|
created: |
|
July 4, 2002 14:32 |
|
complexity: |
|
basic |
author: |
|
RobertKellyIV |
|
as of Vim: |
|
5.7 |
In times past I used a nice editor that had the neat feature of automatically setting pasted text to the proper indent level. Recently I've begun to miss this so I went looking in the help and camp up with....
=`]
which will format to the end of the pasted text... Perfect to call right after you past something as the cursor ends up at the top of the pasted text, thus the mapping:
:map <c-p> =`]
" by the by the above may should be nmap and I am pretty sure c-p is unused, your mileage will vary no doubt.
However I wanted the formatting to automatically be done so it was two simple (once I figured out how!) nnoremap:
" [Feral:185/02@14:27] map c-p to what p was (past with no formatting), map p to p and = to end of pasted text.
:nnoremap p p=`]
:nnoremap <c-p> p
This simply (as the comment hints at) maps normal mode p to what p did (paste) then = to `] (last character in the previously changed text). While ctrl+p just does what p did. (just in case you find you don't want a bit of text auto formatted.).
reference:
:h :nnoremap
:h p
:h =
:h `]
Whatever the name of this idea is, tis something I find handy :)
Happy VIMing
<<easy (un)commenting out of source code |
Fast fixing of email quotations (too long lines) >>
Additional Notes
|