本文翻译自:Traversing text in Insert mode

While in Insert Mode in Vim, is there any way to traverse the text moving some characters forward and backward other than using the arrow keys? 在Vim的插入模式下 ,除了使用箭头键之外,有没有办法遍历文本向前和向后移动一些字符?

If I press h , j , k and l while in Insert mode, the actual characters are printed on screen instead of moving through the text. 如果我在插入模式下按h , j , k和l ,则实际字符将打印在屏幕上而不是在文本中移动。

The way I'm doing it at the moment is having to resort to Ctrl + [ ( Esc ) and traversing the text then; 我现在这样做的方式是不得不求助于Ctrl + [ ( Esc )然后遍历文本; but obviously that is not productive. 但显然这不是很有成效。


#1楼

参考:https://stackoom.com/question/7Hul/在-插入-模式下遍历文本


#2楼

To have a little better navigation in insert mode, why not map some keys? 要在插入模式下获得更好的导航,为什么不映射一些键呢?

imap <C-b> <Left>
imap <C-f> <Right>
imap <C-e> <End>
imap <C-a> <Home>
" <C-a> is used to repeat last entered text. Override it, if its not needed

If you can work around making the Meta key work in your terminal, you can mock emacs mode even better. 如果您可以在终端中使Meta键工作,则可以更好地模拟emacs模式。 The navigation in normal-mode is way better, but for shorter movements it helps to stay in insert mode. 正常模式下的导航方式更好,但对于较短的移动,它有助于保持插入模式。

For longer jumps, I prefer the following default translation: 对于更长的跳跃,我更喜欢以下默认翻译:

<Meta-b>    maps to     <Esc><C-left>

This shifts to normal-mode and goes back a word 这转移到正常模式并返回一个单词


#3楼

You can create mappings that work in insert mode. 您可以创建在插​​入模式下工作的映射。 The way to do that is via inoremap. 这样做的方法是通过inoremap。 Note the 'i' at the beginning of the command (noremap is useful to avoid key map collisions). 注意命令开头的'i'(noremap对于避免键映射冲突很有用)。 The corollary is 'n' for 'normal' mode. “正常”模式的推论是'n'。 You can surmise what vim thinks is 'normal' ;) 你可以推测vim认为'正常';)

HOWEVER, you really want to navigate around in text using 'normal' mode. 但是,您真的想要使用“普通”模式在文本中导航。 Vim is super at this kind of thing and all that power is available from normal mode. Vim在这种情况下非常出色,所有功能都可以从普通模式中获得。 Vim already provides easy ways to get from normal mode to insert mode (eg, i, I, a, A, o, O). Vim已经提供了从普通模式到插入模式的简单方法(例如,i,I,a,A,o,O)。 The trick is to make it easy to get into normal mode. 诀窍是让它很容易进入正常模式。 The way to do that is to remap escape to a more convient key. 这样做的方法是将转义重新映射到更方便的密钥。 But you need one that won't conflict with your regular typing. 但是你需要一个不会与你的常规打字冲突的。 I use: 我用:

inoremap jj <Esc>

Since jj (that's 2 j's typed one after the other quickly) doesn't seem to appear in my vocabulary. 因为jj(那是2 j的一个接一个地快速输入)似乎没有出现在我的词汇表中。 Other's will remap to where it's comfortable. 其他的将重新映射到舒适的地方。

The other essential change I make is to switch the CAPSLOCK and CONTROL keys on my keyboard (using the host computer's keyboard configuration) since I almost never use CAPSLOCK and it has that big, beautiful button right where I want it. 我做的另一个重要的改变是切换键盘上的CAPSLOCK和CONTROL键(使用主机的键盘配置),因为我几乎从不使用CAPSLOCK,并且它在我想要的地方有那么大,漂亮的按钮。 (This is common for Emacs users. The downside is when you find yourself on an 'unfixed' keyboard! Aaarggh!) (这对于Emacs用户来说很常见。缺点是当你发现自己处于'不固定'键盘时!Aaarggh!)

Once you remap CAPSLOCK, you can comfortably use the following insert mode remappings: 重新映射CAPSLOCK后,您可以轻松使用以下插入模式重映射:

Keeping in mind that some keys are already mapped in insert mode (backwards-kill-word is Cw (Control-w) by default, you might already have the bindings you want. That said, I prefer Ch so in my .vimrc I have: 请记住,某些键已经在插入模式下映射(默认情况下向后杀死单词是Cw(Control-w),您可能已经拥有了所需的绑定。也就是说,我更喜欢Ch所以在我的.vimrc中我有:

inoremap <C-h> <C-w>

BUT, you probably want the same muscle memory spasm in normal mode, so I also map Ch as: 但是,你可能想要在正常模式下相同的肌肉记忆痉挛,所以我也将Ch映射为:

nnoremap <C-h> db

(d)elete (b)ackwards accomplishes the same thing with the same key chord. (d)elete(b)ackwards使用相同的和弦完成同样的事情。 This kind of quick edit is one that I find useful in practice for typos. 这种快速编辑是我在拼写错误的实践中发现的一种。 But stick to normal mode for moving around in text and anything more than killing the previous word. 但坚持正常模式在文本中移动,而不是杀死前一个单词。 Once you get into the habit of changing modes (using a remap of course), it will be much more efficient than remapping insert mode. 一旦你养成改变模式的习惯(当然使用重映射),它将比重新映射插入模式更有效。


#4楼

While in insert mode , use Ctrl O to go to normal mode for just one command: 插入模式下 ,使用Ctrl O进入正常模式只需一个命令:

CTRL-O h  move cursor left
CTRL-O l  move cursor right
CTRL-O j  move cursor down
CTRL-O k  move cursor up

which is probably the simplest way to do what you want and is easy to remember. 这可能是做你想做的事情最容易记住的最简单方法。

Other very useful control keys in insert mode: 插入模式中其他非常有用的控制键:

CTRL-W    delete word to the left of cursor
CTRL-O D  delete everything to the right of cursor
CTRL-U    delete everything to the left of cursor
CTRL-H    backspace/delete
CTRL-J    insert newline (easier than reaching for the return key)
CTRL-T    indent current line
CTRL-D    un-indent current line

these will eliminate many wasteful switches back to normal mode. 这些将消除许多浪费的开关回到正常模式。


#5楼

Many people in the Vim community argue that you should not navigate in Insert mode, that it is not the Vim way. Vim社区中的许多人认为你不应该在插入模式下导航,它不是Vim方式。 I think this is an incorrect sentiment learned when transitioning from standard editors to Vim. 我认为从标准编辑器转换到Vim时,这是一种不正确的情绪。

Vim is most powerful when you use its tools to create atomic, repeatable actions or finds. 当您使用其工具创建原子,可重复的动作或查找时,Vim是最强大的。

It is ok to navigate while in Insert mode if you are fixing a mistake you made in the same Insert session. 如果要修复在同一个插入会话中所犯的错误,可以在“插入”模式下导航 You should not navigate outside of the range of text you modified. 您不应在您修改的文本范围之外导航。

If you make a mistake while entering text and escape out of Insert mode to fix it you will not be able to repeat the intended action, . 如果您在输入文本时出错并退出插入模式以修复它,您将无法重复预期的操作, . will repeat the correction. 将重复更正。

Vim does support many Insert mode navigation keys. Vim确实支持许多插入模式导航键。 Obviously there are the arrow keys, Home, and End, but there are also many other shortcuts. 显然有箭头键,Home和End,但也有许多其他快捷方式。 See :h ins-special-keys . 请参阅:h ins-special-keys


#6楼

我相信Home和End (以及PageUp / PageDn )在插入模式下也能正常工作,但除此之外,我不相信为文本遍历定义了任何其他标准键。

在“插入”模式下遍历文本相关推荐

  1. vi的插入模式下退格和方向键不能使用的解决方法

    vi的插入模式下退格和方向键不能使用的解决方法 安装vim full 版本: $sudo apt-get remove vim-common $sudo apt-get install vim

  2. vi插入模式下的backspace键和方向键“不正常”使用解决方法

    在新装的ubuntu系统使用vi编辑器编辑文本时,会出现退格键(backspace)和上下左右方向键不好用情况,例如退格键不能删除前面的字母,方向键不能移动光标(在命令模式下可以用h.j. k. l键 ...

  3. 在editor模式下遍历unity3d builtsetting中的场景

    foreach (UnityEditor.EditorBuildSettingsScene S in UnityEditor.EditorBuildSettings.scenes) { //在buil ...

  4. Vim实用技巧_2.普通模式和插入模式

    下面介绍vim的几种常用模式的技巧 vim有4种模式:普通模式,插入模式,可视模式,命令模式 为什么要分这么多模式? 想一想我们平时常用的编辑工具word,应该是将上面4种模式融合在一起的:这种做法的 ...

  5. vim可视模式下复制粘贴文本

    [操作步骤] vim编辑器有两种操作模式:普通模式.插入模式.当打开要编辑的文件时,vim编辑器会进入普通模式.在普通模式下按 i 键进入插入模式,在插入模式下按 Esc 键返回普通模式. 在普通模式 ...

  6. vim 粘贴文本_Vim:在粘贴模式下按Vim粘贴文本

    vim 粘贴文本 Pasting code from another application to Vim is a nightmare. The autoindent features of Vim ...

  7. vim插入模式小技巧

    插入模式下删除字符 当在vim的插入模式下是,想要删除字符一般是使用Backspace键或者进入普通模式来进行操 作,实际上还可以使用Ctrl-w来删除光标的前一个单词,使用Ctrl+u可以一直删除到 ...

  8. springboot在restcontroller下返回文本类型

    最近本人做一个接口,接口需要用post application/x-www-form-urlencoded发送请求,返回类型是text/plain,刚开始的思路毫无思路,于是在网上找到thymelea ...

  9. Linux中vim的三种命令格式,及命令模式下常见的操作

    目录 什么是vim 三种命令模式,以及相互转换 命令模式下的文本操作 什么是vim Vim是一个类似于Vi的著名的功能强大.高度可定制的文本编辑器,在Vi的基础上改进和增加了很多特性 三种命令模式,以 ...

最新文章

  1. python setdefault,Python笔记setdefault用法
  2. Shell脚本基本命令4
  3. 安装软件要求输入服务器配置信息,信息技术考试软件配置安装与操作规范(管理服务端与客户端)(30页)-原创力文档...
  4. RunJs使用评测(IE9)
  5. 做人:失信是最大的破产!
  6. 吴裕雄--天生自然 JAVASCRIPT开发学习: 表单验证
  7. [CentOS7] parted用于磁盘分区(同时支持GPT和MBR分区表)
  8. mod_rewrite模块的使用
  9. 大话转岗 PHP 开发小结
  10. .NET 中的 GAC
  11. 计算机硬件的组成、python的开发层面及语法介绍
  12. 什么是单点故障与应对措施
  13. flutter显示图标_flutter 引入第三方 Icon 图标(以阿里图标库为例)
  14. 2021学前端真的没前途了吗?
  15. folx是什么软件?Mac上免费的网络下载管理器
  16. 倒数三天 | Study Jam 即将截止,你完成了吗?
  17. 设计模式系列-Builder模式(高效构建参数)
  18. 银行存1000万,可以享受什么待遇?银行职员一不小心说了真相
  19. 2.1.5-3 循环冗余校验(CRC)码
  20. 6.3 图解BERT模型:从零开始构建BERT

热门文章

  1. 百度云下载速度慢解决方案(仅供参考,大神请指导)
  2. 中国医学史(二--医药的起源)
  3. 关于xcode5 下调试 ios7 系统 界面上移20像素 解决
  4. 如何把未压缩的.avi文件批量地转为.yuv文件(yuv420)?
  5. 遨博机器人AUBO C语言的SDK接口说明(1)
  6. 河南省计算机单招试题,2020年河南单招考试测试题
  7. 开关电源环路稳定性分析(03)-开环电源
  8. 51单片机——独立按键实验,小白讲解,相互学习
  9. 单片机拟真电路图软件_基于MSP430单片机设计的高效数控直流电源及其测试方法与流程...
  10. 不用 PLC与变频器通讯程序台达DOP触摸屏MODBUS RTU直接与台达VFD-S1变频器通讯程序