On Thu, Mar 19, 2015 at 3:44 AM, Christian Brabandt <cblists@256bit.org> wrote:
Am 2015-03-18 23:38, schrieb Christian Bone:
I haven't used Vim in a while and when I started using it again I
noticed this line in $MYVIMRC
:nnoremap <f3> :%!awk '!a[$0]{a[$0]=1;print}'<bar>noh<cr>
I understand that it's mapping to the F3 key, but I can't figure out
what the rest of the line does. Can anyone tell me?
This pipes your current buffer through awk with the awk oneliner:
'!a[$0]{a[$0]=1;print}'
Which I believe is a kind of uniq function.
E.g. each line will be output, if awk hasn't seen it before.
After that the vim command <bar>noh<cr> is executed. I am not
quite sure about that one, I suspect it is trying to use :noh
(e.g. disable search highlighting using the :noh command), but
I wonder why the ':' is missing.
Best,
Christian
I think there are two problems.
First, the second "!" gets replaced by the previous external command. I think you want to escape it: '\!a[$0]{...}'.
Second, when the :nnoremap command is executed, the <bar> becomes a "|" character (pipe) and the <cr> becomes an end-of-line character ... but the latter is the only thing terminating the :!, meaning that the "|" is part of the external command. So, after applying the awk filter, you apply the noh filter. I don't know about you, but I have never heard of noh.
To get something that does not generate errors, I would try this:
nnoremap <F3> :%!awk '\!a[$0]{a[$0]=1;print}'<cr>:noh<cr>
I do not know if that matches the original intent. The awk command does seem to do what Christian described.
:help :!
:help 'cpoptions'
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment