2009-09-24 56 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更快,按下。