spf13 – vim keys – my own cheatsheet
#####################################

NOTE: sections are seperated out with the yellow highlights and underlines

Lots of these work without spf13 plugins. I assume basic knowledge of vim keys and vim in general. Also I assume you have spf13 installed (if not check out article below).

To install SPF3 on your box check this out: ram.kossboss.com/spf13i

MORE KEYS:
https://bitbucket.org/jgartman/spf13-vim
http://vim.spf13.com/

INFO

<leader> key is comma: ,
The key to the right of the M key (without holding shift or anything)
Other sites mention the leader key as being the backslash key \
COLORS

:colorscheme peaksea – good color scheme doesnt hide much even when shell is running low on colors (like putty & screen or tmux at same time)
:colorscheme TAB TAB – to see other colors

 

NERDTREE

,e – open NERDTREE fileexplorer

q – close NERDTREE fileexplorer
BUFFERS AND TABS

:badd <filename> – add buffer/tab (doesnt switch to it)
:b# – switch to new tab
:bd – buffer delete
:bn – buffer next
:bp – buffer prev
SEARCHING

/searchword – followed by enter to look and highlight every occurance of the word “searchword” (then n or N to look for highlighted word)

?searchword  – same as above, except searches in reverse (n and N work backwards)

:nohl – remove highlights (just for that search session, they come back on next search)
MOVING CODE LEFT OR RIGHT TABS AT A TIME

v – visual mode (now use arrows to select code with a selector)
select with keys
< or > – to tab selected text left or right
COMMENTING CODE

CONTROL-v – blocky visual mode
Select first column with keys (down) – note can select the whole text – note right before this first column is where comment will go
CONTROL-I (then press the comment key #) – at this point it will only comment the first selected line
Then press escape – give it a second and all of the lines will be commented

Example1:
CONTROL-v
down
CONTROL-I #
ESCAPE
COMMENTING CODE

Or with NERDCOMMENTER: comments code with correct character based on filetype i assume
Select code with VISUAL or NORMAL MODE
<leader>c<space>
,c

Example1: comment 1 line
go to line
,c<space>

Example2: select multiple lines with
v
up a few times
,c<space>

SELECTING ALL SIMILAR WORDS – this is like find

In Normal mode. Hover over a word with the cursor (using arrows or hjkl), then press # (in other words SHIFT-3). Then all identical words (same casing) will be highlighted. You can move between them with n or N (shift-n)

A word is any character streams seperated by space or newline. So this is a word HELLO, and this is a word hello, and this is a word 123, and this is a word ####, and this is 3 words hi there ###.

LIVING WITH  (), , [], etc AUTOCOMPLETE

So when you type a single, , or [, or, {. It automatically writes the closing character next to it. And any text following that will be wrapped inside the brackets or parenthesis of your choice.

So if you type hello or [hello

On the screen you will see hello or [hello]

Now what if you really needed to type hello and not hello`, or (12+53 instead of (12+53)

What if you dont want it to write the closing character?

Type the Opening character, then the closing character (usually the same unless your using parenthisis, brackets, or curly brackets), then press backspace.

Example1: Typing “”<backspace>hello. I will see on the screen “hello

Example2: Typing {}<backspace>hello. I will see on the screen {hello

Example3: Typing ()<backspace>12+53. I will see on the screen (12+53

SELECTION SURROUND WITH BRACKET/PARENTHESIS/WHATEVER

Use v to select, then press S, then press the surround character

Example1:

v then select with arrow keys (or hjkl)
Then type S then type (

Let say you selected the text: blash+789+3

Then typed S followed by (

The outcome will be: ( blash+789+3 )

Example2:

v then select with arrow keys (or hjkl)
Then type S then type

Let say you selected the text: textbutton

Then typed S followed by

The outcome will be: ‘textbutton’

SELECTION SEARCH AND REPLACE

http://vim.wikia.com/wiki/Search_and_replace_in_a_visual_selection

Use v to select text, then press :
Then type s/original_text_to_replace/new_text/g and Enter to do the replacement of all occurences of “original_text_to_replace” to “new_text”
You will see that it actually types
:'<,’>s/original_text_to_replace/new_text/g

Note: when you type : with a selection, its as if you types :'<,’> which basically tells the vim sed interpreter that you want to work with the selection and not the whole document (or not any other subset of the document)

Note: the g replaces all of the occurances of original_text_to_replace on every line, within the selection. without the g, it would only replace 1 occurance of it per line. So if you had that twice or three time or more on a line, it would only replace the first one and then move on to the next one.

Example1:

You have some text where you want to change a part of it that says “red” in a few places to say “green”

Use v, select all the text in the section you want to apply the search and replace algorithm (even words that dont say “red” or “green”) with arrows (or hjlk), then press :
then type s/red/green/g
Enter

In return its as if you selected the text and hit ESCAPE and typed: ‘<,’>s/red/green/g

Leave a Reply

Your email address will not be published. Required fields are marked *