Skip to content

Commit

Permalink
Added marks to vimrc
Browse files Browse the repository at this point in the history
Reorganized vimrc by adding markers and setting up folding options.
  • Loading branch information
zanshin committed Aug 1, 2014
1 parent cdd86f8 commit 82ee505
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 91 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -10,3 +10,6 @@ Session.vim

# Ignore vim/bundles
vim/bundle

# Ignore vim/tmp
vim/tmp
207 changes: 116 additions & 91 deletions vim/vimrc
@@ -1,23 +1,17 @@
" .vimrc
" Maintained by: Mark Nichols
" mark@zanshin.net
" http;//zanshin.net
" Author: Mark Nichols <mark@zanshin.net>
" Source: http://github.com/zanshin/dotfiles/vim/vimrc
"
" -------------------------------------------------------------------
" Preface ---------------------------------------------------------------- {{{
" Forget compatibility with vi. Who cares.
" -------------------------------------------------------------------
set nocompatible

" -------------------------------------------------------------------
" Get SID prefix of vimrc (see :h <SID>)
" -------------------------------------------------------------------
function! s:SID_PREFIX()
return matchstr(expand('<sfile>'), '<SNR>\d\+_')
endfunction

" -------------------------------------------------------------------
" setup Vundle to manage plugins
" -------------------------------------------------------------------
" turn filetype on so that we can turn if off without generating an exit code
" of 1 when quiting vim.
filetype on " best to have it on before turning it off
Expand Down Expand Up @@ -53,32 +47,23 @@ if has('syntax') && !exists('g:syntax_on')
syntax on
endif

" -------------------------------------------------------------------
" }}}
" Basic options ---------------------------------------------------------- {{{

" change map <leader> from \ to ,
" ------------------------------------------------------------------
:let mapleader = ","

" -------------------------------------------------------------------
" Allow saving of files as sudo when I forgot to start vim using sudo.
" -------------------------------------------------------------------
cmap w!! w !sudo tee > /dev/null %
" -------------------------------------------------------------------
" time out mappings after 1 second (1000)
" and key codes after 1/2 a second (500)
" -------------------------------------------------------------------
" time out mappings after 1 second (1000) and key codes after 1/2 second (500)
set timeout timeoutlen=1000 ttimeoutlen=500

" -------------------------------------------------------------------
" Trying to break a very old habit...
" ex mode commands made easy
" -------------------------------------------------------------------
nnoremap ; :
nnoremap Q <nop>
" -------------------------------------------------------------------
" basic options
" -------------------------------------------------------------------
set laststatus=2 " always show the status line
set cmdheight=2 " and use a two-line tall status line
set showcmd " show the command
Expand All @@ -103,6 +88,15 @@ set foldenable " enable code folding
set history=1000
set ffs=unix,mac,dos " default file types
set autoread " automatically update file when editted outside of vim
set cryptmethod=blowfish " Strong encryption is good

" Folding settings
set foldcolumn=3 " room for fold markers
set foldmethod=marker " use the standard 3 curly braces as markers

" Encoding anyone?
set termencoding=utf-8 " we like utf-8
set encoding=utf-8

" Setup automatic text formatting/wrapping (previously: grn1 )
set formatoptions=
Expand All @@ -114,34 +108,22 @@ set formatoptions+=q " allow formating of comments with 'gq'
set formatoptions+=n " recognize numbered lists
set formatoptions+=l " don't break long lines that were already there

" -------------------------------------------------------------------
" Navigation and movement
" -------------------------------------------------------------------
" disable arrow keys
" Get off my lawn
" }}}
" Navaigation and movement ----------------------------------------------- {{{

" disable arrow keys and make semi-snarky comment. Get off my lawn
nnoremap <Left> :echoe "Use h"<CR>
nnoremap <Right> :echoe "Use l"<CR>
nnoremap <Up> :echoe "Use k"<CR>
nnoremap <Down> :echoe "Use j"<CR>
" map <up> <nop>
" map <down> <nop>
" map <left> <nop>
" map <right> <nop>
" imap <up> <nop>
" imap <down> <nop>
" imap <left> <nop>
" imap <right> <nop>

" use <C>hjkl to switch between splits
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" -------------------------------------------------------------------
" Move line(s) up or down via C-j and C-k respectively
" -------------------------------------------------------------------
" Normal mode
nnoremap <C-j> :m .+1<CR>==
nnoremap <C-k> :m .-2<CR>==
Expand All @@ -154,59 +136,59 @@ inoremap <C-k> <ESC>:m .-2<CR>==gi
vnoremap <C-j> :m '>+1<CR>gv=gv
vnoremap <C-k> :m '<-2<CR>gv=gv
" -------------------------------------------------------------------
" Encoding anyone?
" -------------------------------------------------------------------
set termencoding=utf-8 " we like utf-8
set encoding=utf-8

" -------------------------------------------------------------------
" Encryption settings
" -------------------------------------------------------------------
set cryptmethod=blowfish " Strong encryption is good
" }}}
" File focus ------------------------------------------------------------- {{{

" -------------------------------------------------------------------
" What to do with files and focus
" -------------------------------------------------------------------
set autowrite " write out old file when switching between files
set autoread " reload files changed on disk, i.e. via `git checkout`
au FocusLost * :wa " save file when Vim loses focus
set hidden " switch beteen buffers without saving

" -------------------------------------------------------------------
" With Git who needs backup files?
" -------------------------------------------------------------------
set nobackup
set noswapfile
" }}}
" Backups ---------------------------------------------------------------- {{{

set backup " emable backups
set noswapfile " It's the 21st century already

set undodir=~/.vim/tmp/undo// " undo files
set backupdir=~/.vim/tmp/backup// " backups
set directory=~/.vim/tmp/swap " swap files

" -------------------------------------------------------------------
" Set the color scheme
" -------------------------------------------------------------------
" make these folders automatically if they don't already exist
if !isdirectory(expand(&undodir))
call mkdir(expand(&undodir), "p")
endif
if !isdirectory(expand(&backupdir))
call mkdir(expand(&backupdir), "p")
endif
if !isdirectory(expand(&directory))
call mkdir(expand(&directory), "p")
endif

" }}}
" Set the color scheme --------------------------------------------------- {{{
set background=dark
" silent! colorscheme Tomorrow-Night
" silent! colorscheme badwolf
" Make the gutters darker than the background.
" let g:badwolf_darkgutter = 1
silent! colorscheme landscape

" -------------------------------------------------------------------
" Set tab stuff
" -------------------------------------------------------------------
" }}}
" Set tab stuff ---------------------------------------------------------- {{{
set tabstop=2 " 2 spaces for a tab
set shiftwidth=2 " 2 spaces for autoindenting
set softtabstop=2 " when <BS>, pretend a tab is removed even if spaces
set expandtab " expand tabs to spaces (overloadable by file type)

" -------------------------------------------------------------------
" Scrolling
" -------------------------------------------------------------------
" }}}
" Scrolling -------------------------------------------------------------- {{{
set scrolloff=5 " show context above/below cursor line
set sidescrolloff=10 " number of cols from horizontal edge to start scrolling
set sidescroll=1 " number of cols to scroll at a time

" -------------------------------------------------------------------
" Miscellaneous
" -------------------------------------------------------------------
" }}}
" Miscellaneous ---------------------------------------------------------- {{{
" Sudo to write
cmap w!! w !sudo tee % >/dev/null
Expand Down Expand Up @@ -251,9 +233,9 @@ autocmd InsertEnter * match TechWordsToAvoid /\cobviously\|basically\|simply\|of
autocmd InsertLeave * match TechWordsToAvoid /\cobviously\|basically\|simply\|of\scourse\|clearly\|just\|everyone\sknows\|however,\|so,\|easy/
autocmd BufWinLeave * call clearmatches()

" -------------------------------------------------------------------
" Searching
" -------------------------------------------------------------------
" }}}
" Searching -------------------------------------------------------------- {{{

set gdefault " apply substitutions globally by default. add `g` for old behavior
set incsearch " use incremental search
set hlsearch " highlight search results
Expand All @@ -262,10 +244,10 @@ set smartcase " ignore case if search string is all lower case, case-s
" remove search highlighting with <F3>
nnoremap <silent> <leader>/ :nohlsearch<CR>
" -------------------------------------------------------------------
" Preserve function: saves search history and cursor position
" }}}
" Preserve function ------------------------------------------------------ {{{
" saves search history and cursor position
" call with some command, like removing all whitespace
" -------------------------------------------------------------------
function! Preserve(command)
" preparation: save last search, and cursor position
let _s=@/
Expand All @@ -284,15 +266,15 @@ nmap _$ :call Preserve("%s/\\s\\+$//e")<CR>
" reindent entire file
nmap _= :call Preserve("normal gg=G")<CR>
" -------------------------------------------------------------------
" Splits
" -------------------------------------------------------------------
" }}}
" Splits ----------------------------------------------------------------- {{{

nnoremap <leader>v <C-w>v<C-w>l " open a vertical split and switch to it (,v)
nnoremap <leader>h <C-w>s<C-w>j " open a horizontal split and switch to it (,h)
" -------------------------------------------------------------------
" vimrc shortcuts
" -------------------------------------------------------------------
" }}}
" Vimrc shortcuts -------------------------------------------------------- {{{

" open vimrc in new tab for editing
nmap <leader>ev :tabedit $MYVIMRC<cr>
Expand All @@ -304,15 +286,16 @@ endif
" reload .vimrc
map <silent> <leader>V :source ~/.vimrc<CR>:filetype detect<CR>:exe ":echo 'vimrc reloaded'"<CR>
" -------------------------------------------------------------------
" Command line completion
" -------------------------------------------------------------------
" }}}
" Command line completion ------------------------------------------------ {{{

"set wildmode " navigate <left> & <right> through completion lists
"set wildmode=list:longest " allows expansion of items

" -------------------------------------------------------------------
" }}}
" Filetype settings ------------------------------------------------------ {{{

" control whitespace preferences based on filetype
" -------------------------------------------------------------------
if has("autocmd")
" enable file type detection
filetype on
Expand Down Expand Up @@ -357,9 +340,49 @@ if has("autocmd")

endif

" -------------------------------------------------------------------
" Stuff for Bundles
" -------------------------------------------------------------------
" }}}
" Folding ---------------------------------------------------------------- {{{
"
"set foldlevelstart=0
"
" space to toggle folds
"nnoremap <Space> za
"vnoremap <Space> za
"
" make z0 recursively open whatever fold we're in, even if it's partially open
"nnoremap z0 zcz0
"
" "Focus" the current line.
"
" 1. Close all folds
" 2. Open the folds containing the current line
" 3. Move the line to a little bit (15 lines) above the center of the screen
" 4. Pulse the cursor line. My eyes are bad
"
" This mapping wipes out the z mark, which I never use
"
" I use :sus for the rare times I want to actually background Vim
"nnoremap <c-z> mzzMzvzz15<c-e>`z:Pulse<cr>
"
"function! MyFoldText() " {{{
" let line = getline(v:foldstart)
"
" let nucolwidth = &fdc + &number * &numberwidth
" let windowwidth - winwidth(0) - nucolwidth - 3
" let foldedlinecount = v:foldend - v:foldstart
"
" " expand tabs into spaces
" let onetab = strpart(' ', 0, &tabstop)
" let line = substitute(line, '\t', onetab, 'g')
"
" let line = strpart(line, 0, windowwidth - 2 - len(foldedlinecount))
" let fillchartcount = windowwidth - len(line) - len(foldedlinecount)
" return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' '
"endfunction " }}}
"set foldtext=MyFoldText()
"
" }}}
" Stuff for Bundles ------------------------------------------------------ {{{

" Command-t
nmap <leader>t :CommandT <CR>
Expand Down Expand Up @@ -415,6 +438,8 @@ nmap <leader>vd :call VimuxRunCommand("deploy")<CR>
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_working_path_mode = 'ra'
" -------------------------------------------------------------------
" finis
" -------------------------------------------------------------------

" }}}
" finis ----------------------------------------------------------------- {{{

" }}}

0 comments on commit 82ee505

Please sign in to comment.