Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- " File favorites
- " Handy command: let @"=expand("%:p")
- " In normal mode: %p ; just remember to screen spaces
- cnoreabbrev _prj tab drop C:\path\to\file\ with\ spaces.txt
- " Configuration
- set nocp " No compatibility
- set enc=utf-8
- set guifont=Consolas:h11
- set fillchars+=vert:│ " u2502 vertical line separator
- set linespace=0
- let $LANG = 'en_gb'
- set langmenu=en_gb
- " Unneeded keys
- nnoremap <F1> <nop>
- nnoremap Q <nop>
- nnoremap K <nop>
- " colorscheme codeschool
- " let g:colors_name = 'codeschool'
- set background=light
- colorscheme bandit
- " history
- set history=100
- set undolevels=1000
- " Exclamations
- set noerrorbells
- set visualbell
- set t_vb= " Visual bell switches from audible bell to visual bell. Here in fact visual bell is disabled.
- " Syntax
- syntax on
- set modeline
- set modelines=2
- set nolist " Because it affects text wrap by words
- set listchars=eol:$,tab:»\ ,trail:. " Make these markers visible - by differen colors
- set wrapmargin=0 " (When textwidth!=0) Do not wrap basing on window size
- set textwidth=0 " Do not hard-wrap basing on certain width
- set wrap " Dynamic word wrap
- set linebreak " Do not brak words
- "set showbreak=… " What to show in the beginning of broken line
- set showbreak=└\ " What to show in the beginning of broken line
- set tabstop=4 " Good for texts, not for programming
- set shiftwidth=4 " When using >>, << ; shall match with tabstop
- set softtabstop=0 " For insert mode
- set noexpandtab " Do not convert tabs to spaces
- set backspace=indent,eol,start " Make backspace go to prev. line if en the ^
- set autoindent " Make indent same as previous line
- set splitbelow " Good for preview window: to make it below
- " Open file under cursor
- set isfname+=32 " When open files with gf, consider space as part of filename
- nnoremap gf :tab drop <cfile><CR> " Open new file only if it is not open in other tab; otherwise switch to that tab
- " Reset autocommands
- au! InsertLeave *
- au! FocusLost *
- au! FocusGained *
- au! InsertEnter *
- au! InsertLeave *
- " Line numbers
- set number " show line numbers
- set norelativenumber " Relative numbers affect performance for long files with long lines an syntax highlight
- "au FocusLost * :set norelativenumber
- "au FocusGained * :set relativenumber
- "au InsertEnter * :set norelativenumber
- "au InsertLeave * :set relativenumber
- " Performance affecting
- " relativenumber
- " cursorli
- " cursorcolumn
- set nolazyredraw " Default. Makes more smooth. If performace affected, set this to yes; the result - lower FPS, but higher speed.
- " folding
- set foldcolumn=1
- " If using gvim, let use Alt combinations (disable invoking menu with Alt keys)
- set winaltkeys=no
- " Working with buffers, tabs, windows
- set showtabline=2 " Always, even if there is only one tab
- set hidden " When editing a new or unsaved file, premit switching to another buffer (else will say that "Not saved")
- " Handy keybindings
- nmap <A-Left> :tabprev<CR>
- nmap <A-Right> :tabnext<CR>
- nmap <A-Up> :bprev<CR>
- nmap <A-Down> :bnext<CR>
- " After using :vimgrep or :make - switch results:
- map <C-j> :cn<CR>
- map <C-k> :cp<CR>
- " plugin: foldsearch
- " toggle search folding with z/
- nmap z/ :if (exists("w:foldsearch_viewfile")) \| :execute ":Fe" \| else \| :execute ":Fs" \| endif<CR>
- " plugin: vm-session
- " Note: exceptionse like MiniBufExplorer add to function s:state_filter(line)
- let g:session_autosave_periodic=3 " Auto-save session every 3 minutes
- let g:session_autosave='yes' " Do not prompt if I want to save autosession
- let g:session_persist_colors = 0 " Do not save colors
- " plugin: netrw (embedded) - invoked by :E command
- let g:netrw_browse_split=0 " Open file in the same window
- " plugin: hashnotes
- nmap <F3> :call HashNotesAssignIndex()<CR>
- " plugin: MiniBufExplorer
- nmap <F4> :MBEToggle<CR>
- let g:miniBufExplVSplit=33 " Exactly filename of new file
- let g:miniBufExplUseSingleClick=1 " Single mouse click opens the file
- " plugin: diffchar
- " Improves diff: make by char/word etc
- " Warning 1: makes it slow
- " Warning 2: re-binds some keys. Prevent it.
- let g:DiffUnit="Word1"
- " ============ When exiting Insert mode, do not move cursor back
- " Aternative: http://compsci.ca/v3/viewtopic.php?t=34055
- function! s:CorrectPosition()
- if !exists("b:tmpNormalMode")
- let l:newCol = getpos('.')[2]
- if ( l:newCol != 1 )
- let l:newCol+=1
- endif
- call cursor(getpos('.')[1], l:newCol)
- else
- unlet b:tmpNormalMode
- endif
- endfunction
- au! InsertLeave * call <SID>CorrectPosition()
- inoremap <buffer> <silent> <C-o> <Esc>:let b:tmpNormalMode=1<CR>gi<C-o>
- " au InsertLeave * exec "let newCol = getpos('.')[2] | if ( newCol != 1 ) | let newCol+=1 | endif | call cursor(getpos('.')[1], newCol)"
- " inoremap <buffer> <silent> <Esc> <C-o>:stopinsert<CR> " Makes modeline does not update! A bug
- " ========== Make up/down movement by visible line, not by physical line:
- " Note: using imap to apply cursor position correction
- imap <buffer> <silent> <Up> <C-o>gk
- imap <buffer> <silent> <Down> <C-o>gj
- imap <buffer> <silent> <Home> <C-o>g<Home>
- imap <buffer> <silent> <End> <C-o>g<End>
- " ========== Search
- " TODO: find n-th occurence of match; 5th occurence of 'e': \(\(e\).\{-}\)\{4\}\zs\2 ; use buttons to increase, decrease, return to original
- " Search as you type
- set incsearch
- " Higlight all search results
- " Actually it is on. Functions will be responsible for setting this variable
- set nohlsearch
- " Remove search highlight on cursor move
- function! s:HlSearchOff()
- if ( exists ("b:last_search") && b:last_search==@/ )
- " need to clear
- if ( exists("b:search_cleared") && b:search_cleared==1 )
- " Do nothing
- else
- " nohlsearch " Does not work in autocmd and functions - see help
- " redraw
- set nohlsearch
- let b:search_cleared=1
- endif
- else
- let b:search_cleared=0
- set hlsearch
- endif
- let b:last_search=@/
- endfunction
- function! s:HlSearchOn()
- let b:search_cleared=0
- set hlsearch
- endfunction
- autocmd! CursorMoved * call <SID>HlSearchOff()
- nnoremap <silent> n n:call <SID>HlSearchOn()<CR>
- nnoremap <silent> N N:call <SID>HlSearchOn()<CR>
- " Note: re-definition of /, ? etc currupts sequeces like d/x (delete till 'x')
- " Bug: /<CR> and ?<CR> (not chnging the pattern will not highlight search results. Search results will be highlighted only if new pattern differs from previous.
- " ========== Scroll
- set scrolloff=1 " Always show these amount of lines above and below cursor
- " Keep cursor on-screen position when PgUp, PgDown
- function! s:ScrollSave()
- " Affects cursor position
- let l:view=winsaveview()
- normal! H
- let l:view['Hline']=line('.')
- normal! L
- let l:view['Lline']=line('.')
- return l:view
- endfunction
- function! s:ScrollCorrect(view)
- " Works ok unless passing end of file
- normal! H
- let l:view=<SID>ScrollSave()
- let l:view['curswant']=a:view['curswant']
- let l:down=a:view['lnum']-a:view['Hline']
- if ( l:view['Hline']+l:down > l:view['Lline'] )
- let l:down=l:view['Lline']-l:view['Hline']
- endif
- call winrestview(l:view)
- if (l:down>0)
- exec "normal! " . l:down . "j"
- else
- normal! jk " To apply curswant.
- endif
- endfunction
- nnoremap <silent> <PageUp> :<C-u>let w:scroll_view=<SID>ScrollSave() \| exec "normal! <C-v><C-b>" \| call <SID>ScrollCorrect(w:scroll_view)<CR>
- nnoremap <silent> <C-b> :<C-u>let w:scroll_view=<SID>ScrollSave() \| exec "normal! <C-v><C-b>" \| call <SID>ScrollCorrect(w:scroll_view)<CR>
- nnoremap <silent> <PageDown> :<C-u>let w:scroll_view=<SID>ScrollSave() \| exec "normal! <C-v><C-f>" \| call <SID>ScrollCorrect(w:scroll_view)<CR>
- nnoremap <silent> <C-f> :<C-u>let w:scroll_view=<SID>ScrollSave() \| exec "normal! <C-v><C-f>" \| call <SID>ScrollCorrect(w:scroll_view)<CR>
- " ========== For programming
- " autocmd FileType cpp :set makeprg=g++\ -std=c++14\ -ggdb\ -o\ %:r\ %
- " autocmd FileType c :set makeprg=gcc\ -ggdb\ -o\ %:r\ %
- " nnoremap <F4> :write<CR>:make<CR>
- " nnoremap <F5> :!./%:r 2>%:r.log<CR>
- "
- " " Reengineering tool involving foldsearch. Rename word (function name, variable etc)
- " nmap <F2> :let winview=winsaveview()<CR>yiw*N:Fs<CR>:call winrestview(winview)<CR>
- "
- " " Better folding
- " " Set a nicer foldtext function
- " set foldtext=MyFoldText()
- " function! MyFoldText()
- " let line = getline(v:foldstart)
- " if match( line, '^[ \t]*\(\/\*\|\/\/\)[*/\\]*[ \t]*$' ) == 0
- " let initial = substitute( line, '^\([ \t]\)*\(\/\*\|\/\/\)\(.*\)', '\1\2', '' )
- " let linenum = v:foldstart + 1
- " while linenum < v:foldend
- " let line = getline( linenum )
- " let comment_content = substitute( line, '^\([ \t\/\*]*\)\(.*\)$', '\2', 'g' )
- " if comment_content != ''
- " break
- " endif
- " let linenum = linenum + 1
- " endwhile
- " let sub = initial . ' ' . comment_content
- " else
- " let sub = line
- " let startbrace = substitute( line, '^.*{[ \t]*$', '{', 'g')
- " if startbrace == '{'
- " let line = getline(v:foldend)
- " let endbrace = substitute( line, '^[ \t]*}\(.*\)$', '}', 'g')
- " if endbrace == '}'
- " let sub = sub.substitute( line, '^[ \t]*}\(.*\)$', '...}\1', 'g')
- " endif
- " endif
- " endif
- " let n = v:foldend - v:foldstart + 1
- " let info = " " . n . " lines"
- " let sub = sub . " "
- " let num_w = getwinvar( 0, '&number' ) * getwinvar( 0, '&numberwidth' )
- " let fold_w = getwinvar( 0, '&foldcolumn' )
- " let sub = strpart( sub, 0, winwidth(0) - strlen( info ) - num_w - fold_w - 1 )
- " return sub . info
- " endfunction
Advertisement
Add Comment
Please, Sign In to add comment