vi

Linux vim 常用方法

懵懂的女人 提交于 2019-11-26 16:39:24
转载至: https://www.runoob.com/linux/linux-vim.html Linux vi/vim 所有的 Unix Like 系统都会内建 vi 文书编辑器,其他的文书编辑器则不一定会存在。 但是目前我们使用比较多的是 vim 编辑器。 vim 具有程序编辑的能力,可以主动的以字体颜色辨别语法的正确性,方便程序设计。 相关文章: https://www.runoob.com/w3cnote/all-vim-cheatsheat.html 什么是 vim? Vim是从 vi 发展出来的一个文本编辑器。代码补完、编译及错误跳转等方便编程的功能特别丰富,在程序员中被广泛使用。 简单的来说, vi 是老式的字处理器,不过功能已经很齐全了,但是还是有可以进步的地方。 vim 则可以说是程序开发者的一项很好用的工具。 连 vim 的官方网站 ( http://www.vim.org ) 自己也说 vim 是一个程序开发工具而不是文字处理软件。 vim 键盘图: vi/vim 的使用 基本上 vi/vim 共分为三种模式,分别是命令模式(Command mode),输入模式(Insert mode)和底线命令模式(Last line mode)。 这三种模式的作用分别是: 命令模式: 用户刚刚启动 vi/vim,便进入了命令模式。

使用VIM/VI给文件加密和解密

笑着哭i 提交于 2019-11-26 16:06:46
在写代码或者编辑文件的时候,总会有一些文件不想被人看到或者轻易看到(嘻嘻嘻。。。),如果去专门进行加密又显得有点过头,那么,使用VIM进行文件的加密无疑是最为稳妥最为便捷最为神不知鬼不觉的加密的方式,下面简单的说一下加密解密的方式。 一、加密文件 用vim建立文件或者打开文件 vi test.txt 或者 vim test.txt 文件编辑完成后,在命令行输入 :X //注意是大写的X,然后回车 然后会提示输入两次密码 ​ 此时,文件已经加密完成了,但是还缺少最后重要的一步,就是再次在命令行输入保存或者保存退出命令。 :w 或者 :wq 到此为止,文件加密完成,可以将文件打开测试一下。 ​ 当然输入密码可以正常打开,如果不输入密码或者输错密码,则: ​ 使用其他的命令查看文件也是如此,甚至, 将文件copy到其他的电脑上打开也是需要输入正确的密码的 。 所以,如果忘记密码,那么这个文件就是天王老子也打不开了! 在win10,使用bash用vi或者vim编辑文件并加密和linux下右同样的效果。 二、解密文件 解密文件的前提是需要能够用vi或者vim正确的打开文件,然后在命令行输入 :set key= 然后: :wq 或者,输入命令 :X 或者 :wq! 此时,文件已经正常解密了,下一次将打开文件。 来源: https://www.cnblogs.com/songshuaiStudy

【正确使用vim编辑器的姿势】 -- 2019-08-09 10:20:03

梦想与她 提交于 2019-11-26 16:03:42
原文: http://106.13.73.98/__/87/ vi:可视化接口 (Visual Interface) vim:是vi的增强版 (vi iMprove) vi 编辑器是所有Unix及Linux系统下标准的编辑器,他就相当于windows系统中的记事本一样,它的强大不逊色于任何最新的文本编辑器。它是我们使用Linux系统不能缺少的工具。Unix及linux系统的任何版本下的vi编辑器是完全相同的,学会它后,您将在Linux的世界里畅行无阻。 vim 可以说的vi的升级版本,它可以用多种颜色的方式来显示一些特殊的信息。 vim 具有程序编辑能力,可以以字体颜色辨别语法的正确性,方便程序设计。 vim 会依据文件扩展名或者是文件内的开头消息,来判断该文件的内容而自动的执行该程序的语法判断式,再以颜色来区分显示代码与注册信息。 vim 加入了很多额外的功能,例如支持正则表达式的搜索、多文件编辑、快复制等等。这帮助我们在进行一些配置文件的修改工作时提高了不少的效率。 vim 有三种工作模式,如下图: vim编辑器的配置文件:全局 /etc/vimrc 用户 ~/.vimrc 修改配置文件可使某项配置默认生效,比如在配置文件内加入一行: set nu ,那么打开文件后将默认显示行号。 打开文件 vim + file 打开文件并定位到最后一行 . vim +n file

Linux总结----VI文件编辑器

纵饮孤独 提交于 2019-11-26 15:42:00
vi 的三种命令模式 Command(命令)模式,用于输入命令; Insert(插入)模式,用于插入文本; Visual(可视)模式,用于视化的的高亮并选定正文 文件的保存和退出 Command 模式是vi或vim的默认模式,如果我们处于其它命令模式时,要通过ESC键切换过来。 当我们按ESC键后,接着再输入:号时,vi会在屏幕的最下方等待我们输入命令; :w 保存; :w filename 另存为filename; :wq! 保存退出; :wq! filename 注:以filename为文件名保存后退出; :q! 不保存退出;(退出帮助窗口) 恢复修改及恢复删除操作 u 撤消修改或删除操作 ; 按ESC键返回Command(命令)模式 ,然后按u键来撤消删除以前的删除或修改; 如果您想撤消多个以前的修改或删除操作,请按多按几次u。这和Word的撤消操作没有太大的区别 复制和粘帖的操作 其实删除也带有剪切的意思,当我们删除文字时,可以把光标移动到某处, 然后按shift p键就把内容贴在原处,然后再移动光标到某处,然后再按p或shift p又能贴上; p 在光标之后粘帖; shift p 在光标之前粘帖 查找 首先,我们要进入ESC键,进入命令模式; 我们输入/或?就进入查找模式了; /SEARCH 注:正向查找,按n键把光标移动到下一个符合条件的地方; ?SEARCH 注

Indent multiple lines quickly in vi

为君一笑 提交于 2019-11-26 15:33:59
Should be trivial, and it might even be in the help, but I can't figure out how to navigate it. How do I indent multiple lines quickly in vi? Greg Hewgill Use the > command. To indent 5 lines, 5 > > . To mark a block of lines and indent it, V j j > to indent 3 lines (vim only). To indent a curly-braces block, put your cursor on one of the curly braces and use > % or from anywhere inside block use > i B . If you’re copying blocks of text around and need to align the indent of a block in its new location, use ] p instead of just p . This aligns the pasted block with the surrounding text. Also,

Vim delete blank lines

时间秒杀一切 提交于 2019-11-26 14:57:18
问题 What command can I run to remove blank lines in Vim? 回答1: :g/^$/d :g will execute a command on lines which match a regex. The regex is 'blank line' and the command is :d (delete) 回答2: Found it, it's: g/^\s*$/d Source: Power of g at vim wikia Brief explanation of :g :[range]g/pattern/cmd This acts on the specified [range] (default whole file), by executing the Ex command cmd for each line matching pattern (an Ex command is one starting with a colon such as :d for delete). Before executing cmd

Traversing text in Insert mode

故事扮演 提交于 2019-11-26 14:57:14
问题 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? 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. The way I'm doing it at the moment is having to resort to Ctrl + [ ( Esc ) and traversing the text then; but obviously that is not productive. 回答1: You seem to misuse vim, but that's likely due to not being very familiar

how to copy codes in vi to clipboard

╄→尐↘猪︶ㄣ 提交于 2019-11-26 14:07:52
问题 I know how to copy in VI. but I failed to copy it into other application. That means I failed copy those into clipboard. How can I do this? P.S. In order to lean more. I also want to ask how to copy content from clipboard to vi. Edited: I am using MacOs. running Vim. It seems *yy doesn't work here. Any other ways? 回答1: You need to use the clipboard register, which is * , so to copy a line of text into clipboard: "*yy To paste a line of text from the clipboard: "*p 回答2: "+y or "*y works only

Best way to insert timestamp in Vim?

与世无争的帅哥 提交于 2019-11-26 12:51:15
问题 EditPad Lite has a nice feature ( CTRL - E , CTRL - I ) which inserts a time stamp e.g. \"2008-09-11 10:34:53\" into your code. What is the best way to get this functionality in Vim? (I am using Vim 6.1 on a Linux server via SSH. In the current situation a number of us share a login so I don\'t want to create abbreviations in the home directory if there is another built-in way to get a timestamp.) 回答1: http://kenno.wordpress.com/2006/08/03/vim-tip-insert-time-stamp/ Tried it out, it works on

How do I tidy up an HTML file's indentation in VI?

╄→尐↘猪︶ㄣ 提交于 2019-11-26 12:49:32
问题 How do I fix the indentation of his huge html files which was all messed up? I tried the usual \"gg=G command, which is what I use to fix the indentation of code files. However, it didn\'t seem to work right on HTML files. It simply removed all the formatting. I also tried setting :filetype = xml , to see if tricking it into thinking this was an XML file would help but it still didn\'t do it. 回答1: With filetype indent on inside my .vimrc , Vim indents HTML files quite nicely. Simple example