Prashant Mhatre

Make Money, Programming, Bollywood, Marathi

  • You are here: 
  • Home
  • VIM Shortcuts for Programmers

VIM Shortcuts for Programmers

Posted on February 9th, 2008


-- Sponsored Links --



-- Sponsored Links --


 

 

Some of the most frequently VIM shortcuts I use. This is just a copy paste from my notes – so forget grammar and consistency.
Computer


 

yyp

 

duplicate line

 

ddp

 

swap lines

 

^G

 

Current line Number

 

guu

 

change line to lowercase

 

gUU

 

change line to uppercase

 

u

 

unlimited Undos

 

ctrl+r

 

unlimited Re-Do’s

 

‘.

 

(single quote and dot) similar to shift + F5 in MS-Word) Jump to Last modified line

 

`.

 

(back quote and dot) Jump to the exact point where we did last modification

 

*

 

Serach Forward

 

#

 

Search Reverse

Use ‘map’ to map important shortcuts:


While working on source code, sometimes I prefer to see code with line numbers, sometimes I don’t.

:map #1 :set nu^M

:map #2 :set nonu^M

Note: (^M characters are created by typing the key sequence [CTRL-V][CTRL-M]. This key sequence represents the carriage return)

Now You can Hit the following keys to toggle between source code with and without line numbers.

F1 Shows source code with line numbers

F2 Shows source code without line numbers

‘map’ is used like a ‘macro’ in MS Word /Excel. Read stuff on ‘map’ to know the magics . Read how can you put the maps in .vimrc file.

Some more programming specific shortcuts.


 

Programming Specific:

 

%

 

match brackets {}[]()

 

ga

 

Displays ascii, hex and octal value of a character under cursor

 

gf

 

Open file name under cursor, I prefer to spilt window before doing this

 

Ctrl+n /Ctrl+p

 

Word completion in insert mode

 

[I

 

list lines containing the word under cursor

 

:sp pnm.cpp

 

Opens pnm.cpp file in a split window

 

gD

 

To highlight all functions/Jump to function

 

#

 

Jump to function/subroutine

 

ctrl+w ctrl+w

 

Toggle within split windows

 

If you are at the beiginning of ‘/prashant/narayan/mhatrep/ok’, pressing dw will just delete ‘/’. Hit dW, It will delete complete ‘/prashant/narayan/mhatrep/ok’ word.

( beginning of previous sentence

) beginning of next sentence

{ beginning of previous paragraph

} beginning of next paragraph

 

20G or :20 move to line 20

G End of the file

J Join two lines (position cursor anywhere on the line)

:set ts=4 set tabstop = 4

When auto-indent is enabled (:set ai), we can use ‘ctrl+d’ to move one ident level to the left and ‘ctrl+t’ to move one ident level to the right.

Filed under Programming |

Comments are closed.