繁体   English   中英

在vim中找到光标下的字符

[英]Find character under cursor in vim

在vim中,如何在光标下找到下一个字符? 我想要类似*但是对于单个字符而不是单词。

例:

H|o|w are you?

去:

How are y|o|u?

我想要它的原因是因为我的文件中有一个看起来奇怪的字符(我甚至不知道如何键入),我想快速删除它们。

另外看看

g a (在光标下显示字符为ascii)

g 8 (将光标下的字符显示为utf8,包括Unicode内容,十六进制代码等)

最有用的是:

8 8

Find an illegal UTF-8 byte sequence at or after the
        cursor.  This works in two situations:
        1. when 'encoding' is any 8-bit encoding
        2. when 'encoding' is "utf-8" and 'fileencoding' is
           any 8-bit encoding
        Thus it can be used when editing a file that was
        supposed to be UTF-8 but was read as if it is an 8-bit
        encoding because it contains illegal bytes.
        Does not wrap around the end of the file.
        Note that when the cursor is on an illegal byte or the
        cursor is halfway a multi-byte character the command
        won't move the cursor.

更新

使用Tim Pope的vim-characterize插件获取完整的UNICODE名称和数据:

在Vim里,按ga上的字符显示其十进制,八和十六进制表示。

Characterize.vim通过以下附加功能对其进行现代化:

  • Unicode字符名称:U + 00A9 COPYRIGHT SYMBOL
  • Vim有向图(输入后插入字符):Co,cO
  • 表情符号代码::版权:
  • HTML实体:©

在一行上你可以使用fo然后; 前进(或者,向后)。

在多行上,您必须使用/o然后n前进(或N后退)。

或者,您的问题可以通过使用regexp和替换来解决,即:%s/[your odd character]//g

要管理复制和粘贴“奇字”,你应该在视觉使用V选择字符,那么y ESC。

然后输入:: :%s/<CTRL+r>"//g

<CTRL+r>"将在命令行中复制复制寄存器的内容。

以下将映射<leader>z (通常为\\z

:nnoremap <leader>z xhp/<CR>-<CR>

如果这对您有用,请告诉我。

然后只需使用规则来替换它们

:%s/search/replacement/

这将替换出现的所有searchreplacement

好吧,对于一次性快速黑客只是使用* ,它什么也没找到,但你要按/ ,<up>并编辑模式。 仅在vim将字符识别为单词的一部分时才有效。

:exec '%s/'.getline('.')[col('.')-1].'//g'

如果它是特殊字符,你必须添加反斜杠,但由于所有特殊字符都是可输入的,我想它不是。

编辑:为了使用多字节字符,用matchstr(getline('.'), '.', col('.')-1)替换getline('.')[col('.')-1] matchstr(getline('.'), '.', col('.')-1) (见这个答案 )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM