2009-09-24 55 views
7

这里最有用/使用vim的命令是我什么是C/C++开发环境

不像我的名单 - 因为我这样做是为了说明的目的 - 不贴太多。

而且最重要的是,提供解释

命令不应该是通用的,但相关的C++/C的环境。 CTAGS &范围也欢迎

gi .....................init insert mode in last insertion position 

'0 .....................open last edited file 

gf .....................open file under cursor in same window 

Ctrl-w q ...............close current window 

:setlocal autoread .....Auto reloads the current buffer..especially useful while viewing log files 

for i in range(1,255) | .put='10.0.0.'.i | endfor.... insert range ip's 

g; and g, .......................to move (forward, backward) through the changelist 

fx Move the cursor forward to the next occurrence of the character x on the current line (obviously, x can be any character you like). This is an extremely useful command. You can type ; to repeat the last f command you gave. 

tx Same as above, but moves the cursor to right before the character, not all the way to it. (It's very useful, really.) 

Fx Move the cursor backward to the next occurrence of the character x on the current line. 
w Move the cursor forward by a word. 
b Move the cursor backward by a word. 
0 Move the cursor to the beginning of the current line. 
^ Move the cursor to the first character on the current line. 
$ Move the cursor to the end of the line 


Visual search ....... you can simply yank the selected text with y and go to search mode 
/, then you can paste the last yanked text with Ctrl+R 0 

ci" - cuts the text in current quotes 
ciw - cuts the current word. This works just like the previous one except that (is replaced with w. 
C - cut the rest of the line and switch to Insert mode. 
zz -- it scrolls the screen to make this line appear in the middle 
C - cut the rest of the line and switch to Insert mode. 
de - delete from cursor to the end of the word (you can also do dE to delete until the next space) 
df[space] -- delete up until and including the next space 
bye -- copies current word 
b and e move the cursor word-by-word 
capital D (take a deep breath) Deletes the rest of the line to the right 
cd %:h change to current directory 
:r! <command> pastes the output of an external command into the buffer. 
:%s/foo/bar(&)/g will look for foo, and surround the matched pattern with bar(). 
:s/.*/PREFIX & SUFFIX/ you want to add a prefix and a suffix simultaneously, you can do something like this: 

gd....... keystroke stands for Goto Declaration 
gD....... This takes you to the global declaration of the variable under the cursor 
------------------ 
:make error 
[make_error] 
On pressing RETURN, the cursor moves to line number 6 
Now, the command :cn will move the cursor to the line number 4. 
To move back to the previous error, one can use the command :cN and the cursor will move back to the line 6. 
After correcting the error on line 5 and adding "return 1;", one can run :make again and the output will be 


--------- 
:%!grep sdf | sort -n -k3 

1)select the whole content using '%' 
2) pipe it to an external command using '!' 
3) grep onyl the lines containing 'sdf' 
4) sort these lines numerically (-n) on the third field (-k3) 


d$ will delete from current position to end of line 
d^ will delete from current backward to first non-white-space character 
d0 will delete from current backward to beginning of line 
dw deletes current to end of current word (including trailing space) 
db deletes current to beginning of current word 

:%s/pattern//gn........... For counting the number of times some pattern occurs, use: 

CTRL-O Go to [count] Older cursor position in jump list 
CTRL-I Go to [count] newer cursor position in jump list 


zz - line that has a cursor is in the middle of the screen 
zt - line that has a cursor is in the top of the screen 
zb - line that has a cursor is in the buttom of the screen 

set printoptions=number:y ...set numbers in a hardcopy 
:hardcopy.... to print the file :w 

shift d ...... Deleting from current position to end of line 
vim -o ....... allows you to open two windows, split vertically horizontally 
vim -O ....... allows you to open two windows, split vertically 
CTRL+W CTRL-Q ......to close the current windows 
qall.........How do I quit all windows 

0 ...First position on line 
Ctrl g ...where am I 
:set wrapmargin=70 
printexpr=system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error 

Tab block of code ....select your block of code (with [V]isual line mode normally), then press > or <. 
If you want to tab more than once, 2> or 3> to repeat it. 

新闻:

Guys, let's REOPEN THIS QUESTION, and go WIKI-CRAZY! 
+0

您可以随时查看http://stackoverflow.com/questions/69871/vim-vi-survival-guide问题,询问“什么是基本的vim命令?” – amischiefr 2009-09-24 14:23:40

+2

那些是一般的,我特别感兴趣的是那些使用vim进行C++开发的环境。 – vehomzzz 2009-09-24 14:24:33

+0

所以你的例子都是。在vi/vim中没有任何C++构造(我知道)。 – amischiefr 2009-09-24 14:28:37

回答

1

你应该看看SnippetsEmu。一个很棒的插件,可以为你节省大量的定期输入的字词。

注意:你问的是命令而不是插件,但只是想提一提这个。

+0

国际海事组织,插件是相关的:vim只是本身是相当差的发展在C + +甚至在C. – 2009-09-24 16:14:10

3

我觉得有用的一组命令是[[,]],[],] [。他们通过第一列的花括号进行导航,因此如果使用正确的缩进,它们可以有效地让您遍历函数。

3

这些可能是有用的编程

= - 以打算文本。缩进所有文件克CTRL + V G =

CTRL-P/CTRL-O - 完成文本

- 粘贴块,并在新位置正确地缩进它。例如剪贴板中的代码块是2级缩进,应粘贴在代码中,它将在3级缩进中。

CTRL-X + F完成文件名

>>/< < - 增加/减少缩进

- 去相应的打开/关闭支架

minibufexpl是很好的插件,可以同时在多个文件上工作

3

>aB缩进块。不是经常使用,但仍是一颗宝石。

+0

你需要从视觉上选择块? – vehomzzz 2009-09-24 15:11:35

+0

不,只需要将光标放在要缩进的块内。 :) – 2009-09-24 15:17:57

+1

@Andrei - “:帮助文本对象”将给你一个更好的想法,所有的命令具有相似的结构。在这种情况下,“B”也可以是“{”或“}”,意思相同(我觉得这更容易记住)。您可以应用任何操作员(如d删除或v选择)以及此前的计数以应用于该块。 – 2009-09-24 16:37:37

2

使用不同视图对于并排代码比较是有用的。
注意由分割创建的每个视图都可以包含单独的文件。

要拆分视图水平

:split 

要拆分视图中垂直

:vsplit 

要拆分的观点

^W<arrow>  (Thats control W) (Arrow Key) 

一旦设置了标签文件之间移动:

^]    (Move over identifier you want to find: Hit Control ]) 
:tn   Next Tag 
:tp   Previous Tag 
:pop   Pop back to the place you where when you hit ^] 
+0

+1因为我的vim会话是分裂的 - 即使我不直接使用:sp和:vsp来这样做。 – 2009-09-24 16:12:36

4

我过度使用的有以下几点:

  • :AV垂直分割当前窗口并打开关联到相应源极/报头文件中的标题/源文件(如果尚未打开,否则我们跳到它的窗口,而不是)
  • :GSp and :GVSp分割当前窗口并打开请求的文件(这是在&路径某处),或者如果它已经打开了
  • <m-x>切换当前行注释跳转至文件
  • :Make编译在后台当前项目 - 注意:一个标志需要以设定这样做
  • <c-x>be添加.begin(), /container_name/.end()whatever(container_name<curoser_here>)
  • #i这将扩大到#include
  • :DOX这将将当前函数原型添加一个doxygen注释 - 参数const-/ref-ness,throw spec,返回类型被考虑到
  • :GOTOIMPL这将从当前函数声明中创建一个默认主体(或跳转到已经存在的身体何时可能LE)
  • <c-w><m-down>:另一种方式来浏览标签基地
  • for/if/...:扩展到插入模式相关的代码片段(串/评论内容以外)
  • ,for/,if/.. and ,,for/,,if/...围绕当前选择与相关的代码段,选择将进入控制语句体(一个),或它的条件(二)
  • tpl扩展到template <<cursor>><+placeholder+>
  • 所有文字对象的运动与=,d,C ... + di,/vi,/...,作用于当前参数
  • <c-x>v, <c-x>t以提取所选择的变量/类型(重构)
  • All the bracket opening characters + <m-del>保持平衡的括号

有当我用C开发我使用许多其他命令++,但往往更小 - 只是探索链接我已经给了。

1

我曾经使用过的最好的是当我使用组合running makeQuickfix。我按F6进行编译,然后F7向后移动错误,F8通过使用gcc警告/错误输出中的行号向前移动。比alt-tab更快,按下。