vi

Replacing alternate line in vi text file with a particular string

隐身守侯 提交于 2019-12-24 16:19:06
问题 I have text file which consists of 5 columns , if i want to replace every alternate line in second column with particular string ,how can do this in vi text editor? eg: 1 CG 54 76 76 2 CG 45 78 78 3 CG 48 76 89 4 CG 49 50 52 if i want to replace 2 nd and 4 th line (2nd column) with CA how can i do this in vi text editor? 回答1: If you're using vim, this is a simple macro. If you're not sure if you're using vim, then in command mode, type qq and check that you see recording in the status line at

How to comment out/in a paragraph of haml in vi?

这一生的挚爱 提交于 2019-12-24 13:04:21
问题 I just started diving into vi and so far learned only basic moving around/editing commands. While I am going through the book, is there a fast way to comment out a paragraph with -# in the same column with the cursor position (indenting the lines accordingly)? Let's say I have a piece of code: %table - unless paginate(@clients).nil? %tr %th =t('index.name') %th =t('index.address') %th =t('index.phone') =render :partial => 'client', :collection => @clients and I want to comment out lines

数据结构之图

谁说我不能喝 提交于 2019-12-24 07:44:07
北航软件工程专业考研991数据结构总结: 六、图 1.图的基本概念、名词术语; 2.图的邻接矩阵存储方法和邻接表(含逆邻接表)存储方法的构造原理及特点; 3.图的深度优先搜索与广度优先搜索; 4.最小(代价)生成树、最短路径、AOV网与拓扑排序的基本概念。 1.图的基本概念、名词术语; 基本概念: 定义:图是非空有穷顶点的集合 + 顶点之间的关系 构成 G(V,E),V是顶点的集合,E是边或弧的集合 分类: 无向图:(vi, vj)属于E,必有(vj,vi)属于E,顶点的前后顺序无关 有向图:<vi, vj>不同于<vj, vi> 网络:与边有关的数据称为权,边上带权的图叫做网络 名词术语: 顶点的度:依附于顶点vi的边数称为度 TD(vi) 有向图: 入度:以顶点vi作为终止点的边数称为入度ID(vi) 出度:以顶点vi作为起始点的边数称为出度OD(vi) 结论: ①、边数E = 各个顶点的度的总和/2 ②、具有n个顶点的无向图最多有 n(n-1)/2 条边 每个顶点可以向其他n-1个顶点发出一条边,n个顶点总边数 n(n-1),根据相互性,除以2 ③、具有n个顶点的有向图最多有 n(n-1) 条边 完全图:边数达到最大 稠密图:边数达到或者接近最大边数的图 稀疏图:否则。。。 路径:顶点vx到vy之间有路径P(vx, vy)的充分必要条件为:存在顶点序列 vx, vi1,

Identifying Identical Blocks of Code

痴心易碎 提交于 2019-12-24 07:16:04
问题 Say I have multiple blocks of the following code in a file (spaces is irrelavent): sdgfsdg dfg dfgdfgf ddfg dfgdfgdfg dfgfdg How do you find/highlight all the occurrences? What I ideally want to do is to visually select the code block and then press search to find all occurrences. 回答1: The text being searched for is stored in the / register. You can't yank or delete directly into this register, but you can assign to it using `let'. Try this: Use visual mode to highlight the code you want to

What does pipe character do in vim command mode? (for example, :vimgrep /pattern/ file | another_cmd)

穿精又带淫゛_ 提交于 2019-12-24 05:05:08
问题 What does pipe character do in vim command mode? For example, :vimgrep /pattern/ file | copen Does it act like a pipe in Linux Command Line? Contents of vimgrep gets piped to copen ? Or does it separate commands like ; in Command Line? 回答1: | is used to execute more than one command at a time. In your example: :vimgrep /pattern/ file | copen This finds for the pattern in the specified file and then opens a window to show current list of occurrence of pattern . The second command (and

How to replace finding words with the different in each occurrence in VI/VIM editor ?

和自甴很熟 提交于 2019-12-24 00:52:54
问题 For example, I have a text , 10 3 4 2 10 , 4 ,10 .... No I want to change each 10 with different words I know %s/10/replace-words/gc but it only let me replace interactively like yes/no but I want to change each occurrence of 10 with different words like replace1, 3, 4 , 2 , replace2, 4, replace3 .... 回答1: Replaces each occurence of 10 with replace{index_of_match} : :let @a=1 | %s/10/\='replace'.(@a+setreg('a',@a+1))/g Replaces each occurence of 10 with a word from a predefined array: :let b

vim与程序员

荒凉一梦 提交于 2019-12-23 15:52:41
vim与程序员 所有的 Unix Like 系统都会内建 vi 文书编辑器,其他的文书编辑器则不一定会存在。 但是目前我们使用比较多的是 vim 编辑器。 vim 具有程序编辑的能力,可以主动的以字体颜色辨别语法的正确性,方便程序设计。 什么是 vim? Vim是从 vi 发展出来的一个文本编辑器。代码补完、编译及错误跳转等方便编程的功能特别丰富,在程序员中被广泛使用。 简单的来说, vi 是老式的字处理器,不过功能已经很齐全了,但是还是有可以进步的地方。 vim 则可以说是程序开发者的一项很好用的工具。 vi/vim 的使用 基本上 vi/vim 共分为三种模式,分别是 命令模式(Command mode) , 输入模式(Insert mode) 和 底线命令模式(Last line mode) 。 这三种模式的作用分别是: 命令模式: 用户刚刚启动 vi/vim,便进入了命令模式。 此状态下敲击键盘动作会被Vim识别为命令,而非输入字符。比如我们此时按下i,并不会输入一个字符,i被当作了一个命令 移动光标 w(e)  移动光标到下一个单词b    移动到光标上一个单词数字0  移动到本行开头$    移动光标到本行结尾H    移动光标到屏幕首行M    移动到光标到屏幕的中间一行L    移动光标到屏幕的尾行gg    移动光标到文档的首行G    移动光标到文档尾行ctrl

what's the syntax for telling VI to read/write a source file with soft-tabs and a specified indentation?

[亡魂溺海] 提交于 2019-12-23 14:53:28
问题 Someplace I saw a snippet of code which told vi to use soft tabs and set the size of a tab. If you put this snippet at the bottom of a source file, then vi would magically use those settings for that file. What is the syntax and rules for including that snippet in a source file? Can emacs be made to use these settings as well? 回答1: You can put this in a comment in your source file: ex: set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: The comment syntax depends on the type of the source

what's the syntax for telling VI to read/write a source file with soft-tabs and a specified indentation?

為{幸葍}努か 提交于 2019-12-23 14:51:43
问题 Someplace I saw a snippet of code which told vi to use soft tabs and set the size of a tab. If you put this snippet at the bottom of a source file, then vi would magically use those settings for that file. What is the syntax and rules for including that snippet in a source file? Can emacs be made to use these settings as well? 回答1: You can put this in a comment in your source file: ex: set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: The comment syntax depends on the type of the source

.vimrc configuration file does not load when editing with 'sudo'

▼魔方 西西 提交于 2019-12-23 13:47:42
问题 I have problem with .vimrc file, the problem is that it sometimes get loaded, and sometimes not. 1 set number 2 syntax on 3 set autoindent 4 map <F2> :!g++ % -Wall -time -O<CR> 5 echo "it works!" I've added echo to check if it's loaded, and when I type e.g. vim .vimrc , it gets loaded and shows me "it works" in terminal, but when I type e.g. sudo vim test.cpp it doesn't get loaded, the message doesn't show up. I'm using debian. 回答1: When you use sudo , Vim gets launched under a different user