Skip to content

kidpollo/VimEnv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Setup
========
1) git clone git@github.com:actaneon/VimEnv.git ~/.vim
2) ln -s ~/.vim/vimrc ~/.vimrc
3) cd ~/.vim
4) git submodule init
5) git submodule update
6) Enjoy!


Vim Tips
========
:set all	List all the possible vim features
<C-n>     Text auto-completion

Exiting/Saving
:wa			write all.
:wq			Save changes and Exit.


Shell
:!pwd		Execute the pwd unix command, then returns to Vi
!!pwd		Execute the pwd unix command and insert output in file
:r!pwd		Run command and insert output on current line


File Browsing
:Ex			Ex(plorer) mode, re-read file from disk
gf			Open file under cursor

Moving
H			Move to top of screen
M			Move to middle of screen
L			Move to botton of screen
z 			z-carriage return makes the current line the top line on the page
z.			Makes the current line the middle line on the page
z-			Makes the current line the bottom line on the page


Multiple Windows
<C-w>, s		Split Horizontally, reopen the same file in the new window.
<C-w>, v		Split Vertically
<C-w>, n		Opens a Blank Window
<C-w>, c		Close active window
<C-w>, o		Close all windows except the active one.
<C-w>, f		Open file under cursor
<C-w>, r		Rotate windows
<C-w>, x		Swap window with next one
<C-w>, w 		Move between the windows, in order.
<C-w>, _		Maximise current window
<C-w>, =		Gives the same size to all windows
<C-w>, T		Turn split into a new tab
<C-w>, h/j/k/l	Move focus to corresponding window.
<C-w>, UP/DOWN/RIGHT/LEFT	Move focus to corresponding window.


Diff
do			Get changes from other window into the current window.
dp			Put the changes from current window into the other window.
]c			Jump to the next change.
[c			Jump to the previous change.
:diffupdate
:syntax off
:diffget 3		If you were in buffer 1, writing this command would obtain the difference in buffer 3
:diffput 1		Write this in buffer 3 and it will place the change in buffer 1


Folding
zf#j		Creates a fold from the cursor down # lines.
zf/string	Creates a fold from the cursor to string .
zj			Moves the cursor to the next fold.
zk			Moves the cursor to the previous fold.
zo			Opens a fold at the cursor.
zO			Opens all folds at the cursor.
zc			Close folded text
zm			Increases the foldlevel by one.
zM			Closes all open folds.
zr			Decreases the foldlevel by one.
zR			Decreases the foldlevel to zero -- all folds will be open.
zd			Deletes the fold at the cursor.
zE			Deletes all folds.
[z			Move to start of open fold.
]z			Move to end of open fold.

:set foldmethod=indent
:set foldmethod=marker
:set foldmarker=nnn,mmm


Marks
m<letter>		Bookmark named letter
`<letter>		Jumps to that bookmark
'<letter>		Jumps to line with the bookmark
:marks			Show current marks
``				Move between the last two locations


Match Pairs - %
% is used to match paired characters.
If the cursor is at a starting brace, pressing % will take cursor to the matching closing brace, and vice versa.
This works for () (parantheses), /**/ (block comments) etc.
This is handy, can be used extensively with other commands like d (cut), y (copy) etc.
If you need to delete an entire function block, place cursor at either one of the braces and d% will delete that full block.


Autocomplete
<C-n> or <C-p>		Searches current file as well as tags file if present. 


Tag Search
:tag start-of-tag-name_TAB	Go to tag with tab name completion (1st tab will show listing, 2nd will take first partial match and cycle through)
:tag /search-string			Search for string anywhere in tag
:tselect <function-name>	This will give you a listing of all matches where you can select the match to use.  

	First two allow wildcard matching using .* or *.
	For tselect, you must use a full declaration name or use / to search (with wildcards)


Tag Navigation
<C-]>		Follow tag
<C-t>		Go back a level
:tags 		Show tags stack
:tp			Previous Tag
:tn			Next Tag	
:tf			First Tag
:tl			Last Tag
(can prefix these with numbers)


Keyword Program
SHIFT + k - if pressed within a word, it will execute a command (which can be specified), and passes the word as argument. 
Default is man. So, if you press SHIFT + k on a function, it will directly go to its man page, very useful during programming.


Case
Vu		Lowercase line
VU		Uppercase line
vEU		Switch word to uppercase
vEu		Switch word to lowercase
vE~		Modify word case
ggguG	Set all text to lowercase


History
q: 	Show Command History in new window
q/	Show Search History in new window


Registers
@*		Clipboard
@: 		Last command
@/ 		Last search

":p		Paste the last command
"/p		Paste the last search
@: 		Repeat the last command

:reg		List all registers
<R-a>   Paste contents of named register <a> (useful for : or / command lines)


Search
# or *	Search for word under cursor
/word	Search word from top to bottom
?word	Search word from bottom to top
gd gD	local, global definition of symbol under cursor
:g/search_term/#	Search results summary with line numbers

Replace / Regex
:g/string/d				Delete all lines containing string
:v/string/d				Delete all lines which didn't contain string
:g/^$/ d				Delete all empty lines in a file
:g/^$/,/./-j			Reduce multiple blank lines to a single blank
:%s#<[^>]\+>##g			Delete HTML tags but keeps text
:%s/^\(.*\)\n\1$/\1/	Delete lines which appears twice

:%s//REPLACE/g			Replace last search
:%s/<c-r>//REPLACE/g	Replace by inserting last search register
:%s/<c-r> a//REPLACE/g	Replace by inserting last search from register a

:%s/Storage=".\{-}" //		Non-greedy replace
:%s/<!--\_.\{-}-->//		delete HTML comments, potentially spanning multiple lines

:%s/\<\(\w\)\(\w*\)>/\u\1\L\2/g     Capitalize each word

<c-a>		Increment number under the cursor
<c-x>		Decrement number under cursor


:vimgrep /pattern/gj ./**/*.rb		# Follow with :cw to list each match which can be selected
:vimdiff <file1> <file2>
:lcd %:p:h					Change local dir to that of current file

ci{ ? change text inside {} block (Or, di{, yi{, etc.)


Misc
:botright cwindow			make quickfix window span the entire bottom width

================
= Surround.Vim =
================

Normal mode
-----------
ds		Delete a surrounding
cs		Change a surrounding
ys		Add a surrounding
yS		Add a surrounding and place the surrounded text on a new line + indent it
yss		Add a surrounding to the whole line
ySs		Add a surrounding to the whole line, place it on a new line + indent it
ySS		Same as ySs

Visual mode
-----------
s		In visual mode, add a surrounding
S		In visual mode, add a surrounding but place text on new line + indent it

Insert mode
-----------
<C-s>			In insert mode, add a surrounding
<C-s><C-s>		In insert mode, add a new line + surrounding + indent
<C-g>s			Same as <C-s>
<C-g>S			Same as <C-s><C-s>

==================
= Unimparied.Vim =
==================
[Q    Go to first quickfix buffer
[q    Go to prev quickfix buffer
]q    Go to next quickfix buffer
]Q    Go to last quickfix buffer

About

Vim Environment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published