7

这是我的清单

不像我——我这样做是为了说明目的——不要粘贴太多。

最重要的是,提供一个解释

命令不应该是通用的,但与 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!
4

7 回答 7

4

我过度使用的如下:

  • :AV垂直分割当前窗口并打开与相应源/头文件关联的头/源文件(如果尚未打开,否则我们跳转到其窗口)
  • :GSp:GVSp拆分当前窗口并打开请求的文件(在 &path 中的某个位置),或者如果文件已经打开,则跳转到该文件
  • <m-x>切换当前行的注释
  • :Make在后台编译当前项目 -- 注意:需要设置一个标志才能这样做
  • <c-x>be加入.begin(), /container_name/.end()_whatever(container_name<curoser_here>)
  • #i这将扩展到#include
  • :DOX这将为当前函数原型添加一个 doxygen 注释——参数 const-/ref-ness、throw spec、return type 被考虑在内
  • :GOTOIMPL这将从当前函数声明创建一个默认主体(或尽可能跳转到已经存在的主体)
  • <c-w><m-down>:另一种导航标签库的方法
  • for/if/...: 在插入模式下展开到相关的代码片段(字符串/注释上下文之外)
  • ,for/,if/.. and ,,for/,,if/...用相关的代码片段包围当前选择,选择将进入控制语句体(一,)或其条件(二,)
  • tpl扩展到template <<cursor>><+placeholder+>
  • di,/vi,/...作用于当前参数的所有带有 =, d, c, ... + 的文本对象运动
  • <c-x>v,<c-x>t提取选定的变量/类型(重构)
  • 所有括号开始字符 +<m-del>保持括号平衡

当我在 C++ 中开发时,我还使用了许多其他命令,但不经常使用 - 只需浏览我提供的链接即可。

于 2009-09-24T16:09:30.470 回答
4

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

于 2009-09-24T14:46:56.940 回答
3

这些可能对编程有用

= - 打算文本。缩进所有文件 g CTRL+VG =

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

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

CTRL-X+f 补全文件名

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

% - 转到相应的开/关括号

minibufexpl是一个很好的插件,可以同时处理多个文件

于 2009-09-24T14:47:41.553 回答
3

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

于 2009-09-24T14:56:09.383 回答
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 ^]
于 2009-09-24T16:05:33.343 回答
1

你应该看看SnippetsEmu。一个很棒的插件,可以为您节省大量 C 语言中经常输入的单词。

注意:您询问的是命令而不是插件,但无论如何只想提及这一点。

于 2009-09-24T14:43:39.923 回答
1

我用过的最好的方法是结合运行 makeQuickfix。我按 F6 进行编译,然后按 F7 向后移动通过错误和 F8 通过使用 gcc 警告/错误输出中的行号向前移动。比 alt-tab 更快,向上按。

于 2009-09-24T16:17:29.877 回答