2009-09-24 8 views
7

Ecco l'elenco dei mieiQuali sono più utili/comandi di Vim usate in C/C++ ambiente dev

A differenza di me - come ho fatto a scopo illustrativo - non incollare troppi.

E, soprattutto, fornire una spiegazione

I comandi non dovrebbero essere generico, ma rilevanti per l'ambiente C++/C. ctags & ambito sono i benvenuti troppo

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. 

Notizie:

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

Si può sempre guardare http://stackoverflow.com/questions/69871/vim-vi-survival-guida di domanda che chiede "Quali sono i comandi Vim essenziali?" – amischiefr

+2

beh quelli sono generali, sono particolarmente interessato a coloro che usano vim per l'ambiente di sviluppo C++. – vehomzzz

+0

Quindi sono tutti i tuoi esempi. Non ci sono costrutti solo in C++ (che io sappia) in vi/vim. – amischiefr

risposta

1

si dovrebbe dare un'occhiata a SnippetsEmu. Un ottimo plugin che vi farà risparmiare un sacco di parole digitate regolarmente in C.

Nota: Stai chiedendo di comandi e non plugin, ma volevo solo parlare di questo uno comunque.

+0

IMO, i plugin sono rilevanti: Vim è di per sé abbastanza scarso da sviluppare in C++ o anche in C. –

3

Un insieme di comandi che ritengo utili è [[,]], [],] [. Navigano tra parentesi graffe sulla prima colonna, in modo che consentano effettivamente di attraversare le funzioni se si utilizza il rientro corretto.

3

Quelli possono essere utile per la programmazione

= - di intendere il testo. Per far rientrare tutti i file g CTRL + V G =

CTRL-P/CTRL-O - per completare il testo

} y - per incollare blocco e rientro correttamente in una nuova posizione. Per esempio il blocco di codice negli appunti è a 2 livelli e dovrebbe essere incollato nel codice, dove sarà in rientri a 3 livelli.

CTRL-X + f per completare il nome del file

>>/< < - aumento/diminuzione indentazione

% - andare il corrispondente/chiudere la parentesi aperta

minibufexpl è un buon plug-in per lavorare contemporaneamente su diversi file

3

>aB per indentare un blocco. Non frequentemente usato, ma comunque un gioiello.

+0

devi selezionare visivamente il blocco prima? – vehomzzz

+0

No, basta che il cursore si trovi all'interno del blocco che si vuole far rientrare. :) –

+1

@Andrei - ": help text-objects" ti darà un'idea migliore di tutti i comandi con una struttura simile. In questo caso "B" potrebbe anche essere "{" o "}" con lo stesso significato (lo trovo più facile da ricordare). È possibile applicare qualsiasi operatore (ad esempio d per eliminare o v per la selezione) e un conteggio prima di applicarlo al blocco. –

2

L'utilizzo di viste diverse è utile per il confronto di codici affiancati.
Nota ogni vista creata da una divisione può contenere un file separato.

Per dividere la vista orizzontale

:split 

di dividere la visualizzazione in verticale

:vsplit 

per spostarsi tra la vista divisa

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

Dopo aver impostato il file tags:

^]    (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 Perché le mie sessioni vim sono split hells - anche se non uso direttamente: sp e: vsp per farlo. –

4

Quelle che un uso eccessivo sono i seguenti:

  • :AV verticalmente dividere la finestra corrente e aprire il file di intestazione/sorgente associato al rispettivo file sorgente/intestazione (se non ancora aperto, altrimenti saltiamo a la sua finestra invece)
  • :GSp and :GVSp per dividere la finestra corrente e aprire il file richiesto (che è da qualche parte in & percorso), o passare al file se si è già aperto
  • <m-x> per attivare commento sulla riga corrente
  • :Make Per compilare il progetto corrente in background - NB: una bandiera deve essere impostata in modo da farlo
  • <c-x>be aggiungere .begin(), /container_name/.end() in whatever(container_name<curoser_here>)
  • #i che si espanderà in #include
  • :DOX che sarà aggiungi un commento doxygen al prototipo della funzione corrente - parametri const-/refness, throw spec, tipo restituito sono presi in considerazione
  • :GOTOIMPL che creerà un corpo predefinito dalla dichiarazione della funzione corrente (o salterà al già esistente corpo quando possibile le)
  • <c-w><m-down>: un'altra modalità di navigazione base tag
  • for/if/...: espandersi nel frammento di codice corrispondente nella modalità di inserimento (fuori della stringa di commento contesto /)
  • ,for/,if/.. and ,,for/,,if/... per circondare la selezione corrente con il frammento di codice corrispondente , la selezione passerà nel corpo di controllo economico (uno,), o la sua condizione (due)
  • tpl espande in template <<cursor>><+placeholder+>
  • tutti i movimenti oggetto testo con =, d, C, ... + di,/vi,/... che agisce sul parametro corrente
  • <c-x>v, <c-x>t per estrarre il selezionato variabili/tipo (refactoring)
  • All the bracket opening characters + <m-del> per mantenere parentesi bilanciate

Ci sono molti altri comandi che uso quando sviluppo in C++, ma meno spesso - semplicemente esplorare i link I dato.

1

Il migliore che abbia mai usato è quando ho usato una combinazione di combinazione di running make e Quickfix. Ho premuto F6 per compilare, quindi F7 per spostarmi indietro tra gli errori e F8 per spostarmi in avanti utilizzando i numeri di riga nell'output di avviso/errore di gcc.Più veloce della tabulazione alt, premi verso l'alto.

Problemi correlati