Skip to content

Instantly share code, notes, and snippets.

@kurioscreative
Forked from snuggs/.vimrc
Created April 16, 2011 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurioscreative/923488 to your computer and use it in GitHub Desktop.
Save kurioscreative/923488 to your computer and use it in GitHub Desktop.
" ********************************************************************************
" Settings
" ********************************************************************************
filetype off
filetype plugin indent on
syntax enable
syntax on " turns syntax highlighting on
if has("gui_running")
set guioptions=egmrt " remove ugly toolbar :-)
endif
" set t_Co=256 enable 256 colors
set pastetoggle=<F2> " Allow toggle of code indention
set cursorline " highlight current cursor line
set nocompatible " (cp) use Vim defaults (much better)
set showcmd " (sc) display an incomplete command in the lower right
set mouse=a
set wrap
set nocompatible
" set backupdir=~/.tmp
" set directory=~/.tmp
set wildmenu
set ruler
set number
set smarttab
set expandtab "turn tabs into whitespace
set tabstop=2 "set tab character to 2 characters
set showtabline=2
set autoindent
set smartindent
set fileformats=unix,dos " sets <LF> (unix) first, then tries <CR><LF> (dos) next
set path=$PWD/**
set backspace=2 " allows deletion of characters prior to insertion mode
" backspace will delete CRLF at beginning of line
" space key will wrap to next line at end of line
" left and right arrow will wrap to previous and next lines at end of line
" (in normal mode & insertion mode)
set whichwrap=b,s,<,>,[,]
"Have 3 lines of offset (or buffer) when scrolling
set scrolloff=3
set so=0 " allows buffer to scroll before reaching border
set sidescroll=10 " amount buffer is scrolled to when on a word outside of viewing range
"Enable indent folding
set foldenable
" set foldindent=4
set shiftwidth=2 "indent width for autoindents
set foldmethod=indent
set list " allows you to view hidden characters
set listchars=tab:>>,trail:- " tab will show as >- and whitespace will show as -
set listchars+=precedes:< " (lcs) when 'nowrap', character to indicate that line continues off the page
set listchars+=extends:>
" Specky plugin (Rspec)
"let g:speckyBannerKey = "<C-S>b"
"let g:speckyQuoteSwitcherKey = "<C-S>'"
"let g:speckyRunRdocKey = "<C-S>r"
"let g:speckySpecSwitcherKey = "<C-S>x"
"let g:speckyRunSpecKey = "<C-S>s"
"let g:speckyRunRdocCmd = "fri -L -f plain"
"let g:speckyWindowType = 2autocmd BufEnter * lcd %:p:h
" ********************************************************************************
" COLORS & HIGHLIGHTS *********************************************************
" ********************************************************************************
colorscheme jellybeans
" http://vim.wikia.com/wiki/Xterm256_color_names_for_console_Vim
" http://www.bjornenki.com/blog/gvim-colorscheme/bjornenki-colorscheme.vim
" * can use hexidecimal values for gui (e.g. guibg=#000000)
"
" (defaults) - todo, error
"
" The following are the preferred 16 colors for your terminal
" Colors Bright Colors
" Black #4E4E4E #7C7C7C
" Red #FF6C60 #FFB6B0
" Green #254bb8 #CEFFAB
" Yellow #000000 #FFFFCB
" Blue #00ff00 #FFFFCB
" Magenta #FF73FD #FF9CFE
" Cyan #FFFFFF #DFDFFE
" White #EEEEEE #FFFFFF
" gui / cterm display modes (none,(i)talic,(b)old,(s)tandout, (u)nderline, under(c)url)
"hi Example guifg=NONE guibg=#ff0000 gui=NONE ctermfg=NONE ctermbg=NONE cterm=NONE
highlight NonText ctermfg=7 guifg=gray
highlight StatusFileName ctermbg=black guibg=black ctermfg=gray guifg=gray
highlight Cursor guifg=black ctermfg=black guibg=white ctermbg=white
highlight iCursor guifg=white ctermfg=black guibg=steelblue ctermbg=white
" ********************************************************************************
" Cursor
" ********************************************************************************
" set cursor configuration
"set guicursor=n-v-c:block-Cursor
"set guicursor+=i:ver100-iCursor
"set guicursor+=n-v-c:blinkwait10
"set guicursor+=i:blinkwait90
set guicursor=n-v-c:block-Cursor
set guicursor+=i:ver100-iCursor
set guicursor+=n-v-c:blinkwait10
set guicursor+=i:blinkwait90
" ********************************************************************************
" Status Message
" ********************************************************************************
set laststatus=2 " Always show status line
set statusline = " clear out status line
set statusline+=%#StatusFileName# " 'todo' colorscheme
set statusline+=[%Y] " file type
set statusline+=%r\ " read only mode
set statusline+=%-10F " full file name
set statusline+=%* " default colorscheme
set statusline+=%= " right justify everything after this line
set statusline+=[%3c,%-3l\ " cursor column position
set statusline+=of\ %L\ lines\ " cursor line, total lines
set statusline+=(%p%%)]\ \ \ " percentage
set statusline+=[%{g:colors_name}\ ->\ " colorscheme
set statusline+=(%{&term})\ " terminal color setting name
set statusline+=%{&t_Co}\ Color\ Scheme] " color count
" ********************************************************************************
" Mappings
" ********************************************************************************
map <C-b> :tabp<CR>
map <C-n> :tabn<CR>
map <C-t> :tabnew
map <C-m> :NERDTreeToggle<CR>
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
map ; :
map , :ZoomWin<CR>
imap <C-n> <C-x><C-u>
nmap <C-G> :call BOLEOL()<cr>
"Set space to toggle a fold
nnoremap <space> za
" ********************************************************************************
" Functions
" ********************************************************************************
" --------------------------------------------------------------------------------
" Toggle placing cursor to (soft) beginning / (soft) ending of line
" --------------------------------------------------------------------------------
let s:BOLEOL=1
function! BOLEOL()
if (s:BOLEOL == 1)
:norm $
let s:BOLEOL = 0
else
:norm 0
let s:BOLEOL = 1
endif
endfun
" --------------------------------------------------------------------------------
" Toggle status line color
" --------------------------------------------------------------------------------
function! InsertStatuslineColor(mode)
if a:mode == 'i'
highlight statusline guibg=green ctermbg=green
elseif a:mode == 'r'
highlight statusline guibg=white ctermbg=white
else
highlight statusline guibg=red ctermbg=red
endif
endfunction
au InsertEnter * call InsertStatuslineColor(v:insertmode)
au InsertLeave * hi statusline guibg=gray ctermbg=gray
" default the statusline to green when entering Vim
highlight statusline guibg=gray ctermbg=gray
" --------------------------------------------------------------------------------
" Toggle status line color
" --------------------------------------------------------------------------------
function! InsertStatuslineColor(mode)
if a:mode == 'i'
highlight statusline guibg=green ctermbg=green
elseif a:mode == 'r'
highlight statusline guibg=white ctermbg=white
else
highlight statusline guibg=red ctermbg=red
endif
endfunction
au InsertEnter * call InsertStatuslineColor(v:insertmode)
au InsertLeave * hi statusline guibg=gray ctermbg=gray
" default the statusline to green when entering Vim
highlight statusline guibg=gray ctermbg=gray
:NERDTree, :NERDTreeClose, and :NERDTreeToggle
map <F2> :NERDTreeToggle<CR> # maps :NERDTreeToggle to <F2> within .vimrc
All other keyboard shortcuts can be found by pressing ?. It will open a special help screen with the shortcut listings. Press ? again to get back to file tree.
* Use <C>+w to switch context between file and nerdtree
* Use the natural vim navigation keys hjkl to navigate the files.
* Press o to open the file in a new buffer or open/close directory.
* Press t to open the file in a new tab.
* Press i to open the file in a new horizontal split.
* Press s to open the file in a new vertical split.
* Press p to go to parent directory.
* Press r to refresh the current directory.
NerdTree - http://www.vim.org/scripts/script.php?script_id=1658
Surround.vim - http://www.vim.org/scripts/script.php?script_id=1697
Rails.vim - http://www.vim.org/scripts/script.php?script_id=1567
ZoomWin.vim - http://www.vim.org/scripts/script.php?script_id=508
endwise.vim - http://www.vim.org/scripts/script.php?script_id=2386
CucumberVim - http://www.vim.org/scripts/script.php?script_id=2973
Specky.vim - http://www.vim.org/scripts/script.php?script_id=2286
endwise.vim - http://www.vim.org/scripts/script.php?script_id=2286
" colorschemes
:echo g:colors_name
" ---------------------
Molakai.vim (colorscheme) - http://www.vim.org/scripts/script.php?script_id=2340
vividchalk.vim (colorscheme) - http://www.vim.org/scripts/script.php?script_id=1891
"+y[movement] " copy to clipboard buffer (including double quote)
" Similarly, to paste from clipboard, "+p
vim -p [file1 file2 file3 fileN] # vim opens file collection in tabs
vim -o [file1 file2 file3 fileN] # vim opens file collection in split buffers
* k – navigate upwards
* j – navigate downwards
* l – navigate right side
* h – navigate left side
go down by 10 lines, then type “10j”.
:n Jump to line number n. For example, to jump to line 42, you'd type :42
0 – go to the starting of the current line.
^ – go to the first non blank character of the line.
$ – go to the end of the current line.
g_ – go to the last non blank character of the line.
H – Go to the first line of current screen.
M – Go to the middle line of current screen.
L – Go to the last line of current screen.
* ctrl+f – Jump forward one full screen.
* ctrl+b – Jump backwards one full screen
* ctrl+d – Jump forward (down) a half screen
* ctrl+u – Jump back (up) one half screen
% – Go to the matching braces, or parenthesis inside code.
N% – Go to the Nth percentage line of the file.
NG – Go to the Nth line of the file.
G – Go to the end of the file.
” – Go to the position where you were in NORMAL MODE while last closing the file.
^ – Go to the position where you were in INSERT MODE while last closing the file.
g – Go to the beginning of the file.
e – go to the end of the current word.
E – go to the end of the current WORD.
b – go to the previous (before) word.
B – go to the previous (before) WORD.
w – go to the next word.
W – go to the next WORD.
zt - move current cursor placement to top
zb - move current cursor placement to bottom
zz - move current cursor placement to center screen
WORD – WORD consists of a sequence of non-blank characters, separated with white space.
word – word consists of a sequence of letters, digits and underscores.
Example to show the difference between WORD and word
* 192.168.1.1 – single WORD
* 192.168.1.1 – seven words.
# Vim Paragraph Navigation
* { – Go to the beginning of the current paragraph. By pressing { again and again move to the previous paragraph beginnings.
* } – Go to the end of the current paragraph. By pressing } again and again move to the next paragraph end, and again.
Editing blocks of text
Note: the Vim commands marked with (V) work in visual mode, when you've selected some text. The other commands work in the command mode, when you haven't selected any text.
Vim command Action
~ Change the case of characters. This works both in visual and command mode.
In visual mode, change the case of highlighted characters.
In command mode, change the case of the character uder cursor.
> (V) Shift right (indent).
< (V) Shift left (de-indent).
c (V) Change the highlighted text.
y (V) Yank the highlighted text. In Windows terms, "copy the selected text to clipboard."
yy or :y or Y Yank the current line. You don't need to highlight it first.
d (V) Delete the highlighted text. In Windows terms, "cut the selected text to clipboard."
x Delete characters under the cursor.
X Delete characters before the cursor.
dd or :d Delete the current line. Again, you don't need to highlight it first. Deleting text
p Put the text you yanked or deleted. In Windows terms, "paste the contents of the clipboard".
Put characters after the cursor. Put lines below the current line.
P Put characters before the cursor. Put lines above the current line.
u Undo the last action.
U Undo all the latest changes that were made to the current line.
Ctrl + r Redo.
v Start highlighting characters. Use the normal movement keys and commands
to select text for highlighting.
V Start highlighting lines.
:%! nl -ba # Line Numbers
Finding Files
---------------------
:pwd # print working directory
:cd # change directory
:find # file name (within path)
Search
---------------------
* /i – Search for a pattern which will you take you to the next occurrence of it.
* ?i – Search for a pattern which will you take you to the previous occurrence of it.
* * - Go to the next occurrence of the current word under the cursor.
* # - Go to the previous occurrence of the current word under the cursor.
re-apply - The . command repeats the last change. A change, in this context, is inserting, deleting or replacing text. Being able to repeat this is a very powerful mechanism. If you organise your editing around it, many changes will become a matter of hitting just that . key. Watch out for making other changes in between, because it will replace the change that you were repeating. Instead you might want to mark the location with the m command, continue your repeated change and come back there later.
registers - When you are typing a phrase or sentence multiple times, there is an even quicker approach. Vim has a mechanism to record a macro. You type qa to start recording into register 'a'. Then you type your commands as usual and finally hit q again to stop recording. When you want to repeat the recorded commands you type @a. There are 26 registers available for this.
:tabnew [filename] # and Vim will load the file in the new tab (or defaults to empty buffer)
:tabs # displays all tabs
:tabn and :tabp switch between tabs, or you can use gt while you're in normal mode.
If you have a lot of tabs open, you can use :tabfirst, or just :tabfir, to jump to the first tab, and :tablast to jump to the last tab that's open.
if you don't like the existing shortcuts for the tab commands, you can add your own. For instance, if you want to make it easy to open a new tab, you might insert this into your .vimrc:
- Rearranging tabs
If you're really meticulous and want to position tabs just so in Vim, you can move the tabs to a specific spot in the tab order using :tabm n , where n is the position number that you want to use. If you don't give the :tabm command an argument, then the current tab will be moved to the last spot.
Vim starts tab numbering from 0, so if you have six tabs open, you'll have tab 0 through tab 5. So, if you're in the first tab and want to move it to the fourth position, you'd run :tab 3.
map <leader>tn :tabnew %<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove
:split [file] # Splits the window horizontally.
:vsplit [file] # Splits the window vertically.
<Ctrl>-w # (mnemonic: control window) To move between windows you use <Ctrl>-w (mnemonic: control window).
# To move in a specific direction, add the relevant movement key. So, to move upwards: <Ctrl>-w+k.
# To close the active window use :q, just as you would to close a window normally.
<Ctrl>-w [HJKL] # to actually move buffer (i.e. K will move current buffer to top. * notice caps*)
:only # if split buffers, close all buffers except current one.
You can reduce/enlarge the size of the current window with <Ctrl>-w+- and <Ctrl>-w++, respectively. To specify the size of a window when you open it, prefix the :split command with the desired height/width in lines. For example, to show README in a window of 5 lines high: :5 :split README.
When splitting a window you can prepend a modifier command to tell where the
window is to appear:
:leftabove {cmd} left or above the current window
:aboveleft {cmd} idem
:rightbelow {cmd} right or below the current window
:belowright {cmd} idem
:topleft {cmd} at the top or left of the Vim window
:botright {cmd} at the bottom or right of the Vim window
CTRL-W x
CTRL-W CTRL-X Without count: Exchange current window with next one. If there
is no next window, exchange with previous window.
With count: Exchange current window with Nth window (first
window is 1). The cursor is put in the other window.
Replace
Vim command Action
:rs/foo/bar/a Substitute foo with bar. r determines the range and a determines the arguments.
The range (r) can be
nothing Work on current line only.
number Work on the line whose number you give.
% The whole file.
Arguments (a) can be
g Replace all occurrences in the line. Without this, Vim replaces only the first occurrences in each line.
i Ignore case for the search pattern.
I Don't ignore case.
c Confirm each substitution. You can type y to substitute this match, n to skip this match, a to substitute this and all the remaining matches ("Yes to all"), and q to quit substitution.
Examples
:452s/foo/bar/ Replace the first occurrence of the word foo with bar on line number 452.
:s/foo/bar/g Replace every occurrence of the word foo with bar on current line.
:%s/foo/bar/g Replace every occurrence of the word foo with bar in the whole file.
:%s/foo/bar/gi The same as above, but ignore the case of the pattern you want to substitute. This replaces foo, FOO, Foo, and so on.
:%s/foo/bar/gc Confirm every substitution.
:%s/foo/bar/c For each line on the file, replace the first occurrence of foo with bar and confirm every substitution.
# Sessions
--------------------------
:mksession my_session.vim # creates session with current layout info
:source my_session.vim # restore session from file (or :~>vim -S my_session.vim)
BUFFERS
--------------------
:bn[ext] # Next buffer
:bp[revious] # Previous Buffer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment