vi

How to repeatedly add text on both sides of a word in vim?

那年仲夏 提交于 2019-12-22 07:47:09
问题 I have a bunch of local variable references in a Python script that I want to pull from a dictionary instead. So, I need to essentially change foo , bar , and others into env['foo'] , env['bar'] and so on. Do I need to write a regular expression and match each variable name to transform, or is there a more direct approach that I could just repeat with the . command? 回答1: You can use a macro: type these commands in one go (with spacing just to insert comments) " first move to start of the

How to split text into multiple lines based on a pattern using Vim?

半城伤御伤魂 提交于 2019-12-22 03:24:14
问题 Suppose you have this text: name1 = "John"; age1 = 41; name2 = "Jane"; age2 = 32; name3 = "Mike"; age3 = 36; ... and you want to split each line into two lines to give a result like this: name1 = "John"; age1 = 41; name2 = "Jane"; age2 = 32; name3 = "Mike"; age3 = 36; ... How would you automate this operation? Some notes: I already tried the following method: (1) Select the text in virtual-vode, (2) Execute :'<,'>:norm ^3f r^M ***, but it doesn't work correctly; it splits only half of the

Opening a directory in vim

会有一股神秘感。 提交于 2019-12-22 01:27:43
问题 I'm a mac user giving vim a serious try. Most of the GUI editors I'm used to allow me to open a directory as a "project" by executing a command like: edit ~/www/example.com/ The vim equivalent vim ~/www/example.com/ will show me a list of files in the directory, and I can open them. But it does not set vim's working directory to that path, I have to run :cd . to set the working directory. Is there some way, perhaps with a shell script, to open vim and have it's working directory set to a

Vim编辑器

半腔热情 提交于 2019-12-22 00:15:51
vim编辑器: Linux使用文本文件来保存配置;文本编辑器用来编辑纯ASCII文件 Linux下常见的文本编辑器emacs、vi、nano vi(Visual Interface) 全屏文本编辑,模式化的编辑器(在不同的模式间转换) vim(vi improved) vi的增强版 vim的配置文件: 全局配置文件:/etc/vimrc、/etc/virc 用户配置文件:~/.vimrc、~/.virc 文件默认不存在可以自己手动创建 使用vim打开文件: vim File      打开或新建文件,并将光标置于第一行首 vim +N File     打开文件,并将光标置于第N行首 vim + File      打开文件,并将光标置于最后一行首 vim +/Pattern File 打开文件,并将光标置于第一个与"Pattern"匹配的字符串处 vim -r File     在上次正用vim编辑时发生系统崩溃,恢复"File"  vim -b File     二进制方式打开文件  vim -d File1 File2…比较多个文件(如果有不同的话会做出标注) vim File1 File2…  打开多个文件,依次编辑 vim -m File     只读打开文件,只能查看文件不能修改 打开多文件时文件间跳转 :n或:next 编辑下一个文件 :N或:prev 编辑上一个文件

vi-vim编辑器

六月ゝ 毕业季﹏ 提交于 2019-12-21 22:16:37
vim编辑器   系统管理员的重要工作就是得要修改与设定某些重要软件的配置文件,因此至少得要学会一种以上的文字接口的文件编辑器,在所有的Linux distributions 上头都会有的一套文书编辑器就是vi,而且很多软件默认也是使用是作为编辑器的接口,此外,Vim是进阶版的vi,vim不但可以用不同的颜色显示文字内容,还能够进行诸如shell script,Cprogram等程序编辑功能,你可以将Vin视为一种程序编辑器。 什么是vim?   Vim是从 vi 发展出来的一个文本编辑器。代码补完、编译及错误跳转等方便编程的功能特别丰富,在程序员中被广泛使用。 简单的来说, vi 是老式的字处理器,不过功能已经很齐全了,但是还是有可以进步的地方。 vim 则可以说是程序开发者的一项很好用的工具。 vi/vim的使用   在Linux环境中输入 vi/vim+文件名 进入vim编辑环境。   基本上 vi/vim 共分为三种模式,分别是 命令模式(Command mode) , 输入模式(Insert mode) 和 底线命令模式(Last line mode) 。 这三种模式的作用分别是: 命令模式: 用户刚刚启动 vi/vim,便进入了命令模式。 此状态下敲击键盘动作会被Vim识别为命令,而非输入字符。比如我们此时按下i,并不会输入一个字符,i被当作了一个命令。

Vim - delete line in insert mode

风流意气都作罢 提交于 2019-12-21 11:32:34
问题 Can I delete a line in insert mode? Because currently I have to press <ESC>dd to be able to that, and I would like a quicker way to delete a line in insert mode 回答1: If the cursor is at the end of the line, you can press <C-U> twice. The first one will clear the text before the cursor, the second one will remove the now empty line (and put the cursor at the end of the previous line). That said, I would not use this often. Insert mode is for inserting ; for all other edits, it's better to exit

Vim - delete line in insert mode

柔情痞子 提交于 2019-12-21 11:32:10
问题 Can I delete a line in insert mode? Because currently I have to press <ESC>dd to be able to that, and I would like a quicker way to delete a line in insert mode 回答1: If the cursor is at the end of the line, you can press <C-U> twice. The first one will clear the text before the cursor, the second one will remove the now empty line (and put the cursor at the end of the previous line). That said, I would not use this often. Insert mode is for inserting ; for all other edits, it's better to exit

How do you quit the Vi editor with single keypress?

送分小仙女□ 提交于 2019-12-21 09:27:36
问题 Because honestly :wq! is just too much to type. Please note that the question is about original Vi (say Vi which comes with FreeBSD) not Vim. 回答1: This seems to work on solaris' old version of vi: Version SVR4.0, Solaris 2.5.0 $ vi -c "map g ZZ" test edit : Also, this seems to work: $ vi -c 'map g :q!^M' test Where ^M is actually, ^V (ctl-v) then ^M (ctl-m) 回答2: Hold down the shift key and bang on Z twice. ZZ is (mostly) equivalent to :wq! . If you really want a single-keystroke solution,

Vim: Align continous lines with spaces

天大地大妈咪最大 提交于 2019-12-21 06:36:10
问题 I would like to indent everything in vim with tabs, except a particular case. For example I have this c++ code(where <tab> is a tab character series and <s> is a space character series): <tab>if(true && <tab><s>true) <tab>{ <tab><tab>//code here <tab>} I would like after writing '&&' and press 'o' to jump on the next line and start writing to make vim put a tab and the number of spaces till '(' from the line before. Is it possible to define this coding style in vim? Thanks! 回答1: I think what

Is it possible to achieve the so-called “distraction free mode” in Vim?

雨燕双飞 提交于 2019-12-21 04:42:20
问题 Just curious, kinda like the "distraction free mode" of editors like sublime text, is it possible to centroid all the text to the middle of view field? It's always annoying to stare at the left-most end of the vim terminal in fullscreen mode with a widescreen monitor. 回答1: You could take a look at VimRoom: http://projects.mikewest.org/vimroom/ Alternatively, you could set Vim up to have two or more vertical windows on your widescreen and have the same buffer automatically "snake" between them