2009-09-24 10 views
7

Oto lista kopalniJakie są najbardziej użyteczne/używane polecenia vim w C/C++ dev środowiska

przeciwieństwie do mnie - jak ja go dla celów poglądowych - nie wklejać zbyt wiele.

A co najważniejsze, przedstawić wyjaśnienie

Polecenia nie powinny mieć charakter ogólny, ale istotne dla środowiska C++/C. ctags & zakres są mile widziane zbyt

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. 

Aktualności:

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

Zawsze możesz przejrzeć http://stackoverflow.com/questions/69871/vim-vi-survival-guide pytanie, które pyta "Jakie są podstawowe polecenia vim?" – amischiefr

+2

Cóż, te są ogólne, jestem szczególnie zainteresowany tymi, którzy używają vima dla środowiska programistycznego C++. – vehomzzz

+0

A więc wszystkie twoje przykłady. Nie ma żadnych konstruktów tylko C++ (o których mi wiadomo) w vi/vim. – amischiefr

Odpowiedz

1

Należy przyjrzeć SnippetsEmu. Świetna wtyczka, która pozwoli Ci zaoszczędzić sporo regularnie wpisywanych słów w C.

Uwaga: Pytasz o polecenia, a nie o wtyczki, ale mimo to chciałem o tym wspomnieć.

+0

IMO, wtyczki są istotne: vim samo w sobie jest dość ubogie do opracowania w C++ lub nawet w C. –

3

Jednym z użytecznych poleceń, które uważam za użyteczne, jest [[,]], [],] [. Poruszają się przez nawiasy klamrowe w pierwszej kolumnie, dzięki czemu efektywnie pozwalają przejść przez funkcje, jeśli używasz odpowiedniego wcięcia.

3

te mogą być przydatne do programowania

= - zamierzają tekst. Wcięcia wszystkich plików gCTRL + Vg =

Ctrl-P/Ctrl-O - zakończeniu tekst

} r - do pasty blok i INDENT prawidłowo w nowym miejscu. Na przykład blok kodu w schowku ma 2 poziomy wcięcia i powinien być wklejony w kodzie, gdzie będzie w 3 poziomowym wcięciu.

CTRL-X + f do pełna nazwa pliku

>>/< < - zwiększenie/zmniejszenie wcięcia

% - jedziesz, tym odpowiadająca otwarty/zamknięty nawias

minibufexpl to dobra wtyczka do pracy od razu na kilku plikach

3

>aB wcięcie bloku. Nie jest to często używany , ale klejnot.

+0

czy potrzebujesz najpierw wizualnie wybrać blok? – vehomzzz

+0

Nie, po prostu umieść kursor wewnątrz bloku, który ma zostać wcięty. :) –

+1

@Andrei - ": help text-objects" da ci lepszy pomysł na wszystkie polecenia o podobnej strukturze. W tym przypadku "B" może również oznaczać "{" lub "}" o tym samym znaczeniu (uważam, że jest to łatwiejsze do zapamiętania). Możesz zastosować dowolny operator (np. D dla usunięcia lub v dla wyboru), a także liczbę przed tą, aby zastosować do bloku. –

2

Korzystanie z różnych widoków jest przydatne przy porównywaniu kodów.
Uwaga: każdy widok utworzony przez podział może zawierać osobny plik.

Aby podzielić pogląd poziomo

:split 

Aby podzielić pogląd pionowo

:vsplit 

Do poruszania się między Splitem poglądów

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

Po skonfigurowaniu pliku Tagi:

^]    (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 Ponieważ moje sesje vima są podzielonymi piekłami - nawet jeśli nie używam bezpośrednio: sp i: vsp, aby to zrobić. –

4

Te, nadużywanie są następujące:

  • :AV pionowo podzielić bieżące okno i otwórz plik nagłówka/źródło powiązanych z odpowiednim pliku source/nagłówka (jeśli nie jest jeszcze otwarty, w przeciwnym razie przejść do jego okno zamiast)
  • :GSp and :GVSp podzielić bieżące okno i otwórz żądany plik (który jest gdzieś w & ścieżki), albo przejść do pliku, jeśli jest już otwarty
  • <m-x> aby przełączać komentarz na bieżącej linii
  • :Make skompilować bieżący projekt w tle - NB: flaga musi być ustawiony, aby zrobić
  • <c-x>be dodać .begin(), /container_name/.end() w whatever(container_name<curoser_here>)
  • #i które będą rozwijać się #include
  • :DOX który będzie dodać komentarz doxygen do bieżącego prototypu funkcji - parametry const-/ref-ness, throw spec, typ powrotu są brane pod uwagę
  • :GOTOIMPL, które utworzą domyślną treść z bieżącej deklaracji funkcji (lub przeskocz do już istniejącej ciało, gdy to możliwe le)
  • <c-w><m-down>: Innym sposobem na poruszanie się po bazę tagów
  • for/if/...: expand do odpowiedniego fragmentu kodu w trybie wstawiania (poza smyczkowy/comment kontekstu)
  • ,for/,if/.. and ,,for/,,if/... otoczyć bieżące zaznaczenie z odpowiedniego fragmentu kodu , wybór trafi do organizmu sterowania oświadczenie (jeden,), lub jego stanu (dwa,)
  • tpl rozwija się template <<cursor>><+placeholder+>
  • wszystkie ruchy tekst przedmiotami z =, D, C, ... + di,/vi,/..., który działa na bieżący parametr
  • <c-x>v, <c-x>t wyodrębnić wybranej zmiennej/typ (refaktoryzacji)
  • All the bracket opening characters + <m-del> do utrzymania wyważonych wsporniki

Istnieje wiele innych poleceń używam kiedy rozwijać w C++, ale rzadziej - wystarczy przeanalizować związki I Dano.

1

Najlepsze, jakie kiedykolwiek użyłem, to kiedy użyłem kombinacji łączenia running make i Quickfix. Nacisnąłem F6, aby skompilować, a następnie F7, aby przejść wstecz przez błędy, a F8, aby przejść do przodu, używając numerów linii na wyjściu ostrzeżenia/błędu gcc.Szybszy niż alt-tab, naciśnij w górę.

Powiązane problemy