Guest User

vimrc

a guest
Jan 17th, 2016
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.52 KB | None | 0 0
  1. " File favorites
  2. " Handy command: let @"=expand("%:p")
  3. " In normal mode: %p ; just remember to screen spaces
  4. cnoreabbrev _prj tab drop C:\path\to\file\ with\ spaces.txt
  5.  
  6. " Configuration
  7. set nocp " No compatibility
  8.  
  9. set enc=utf-8
  10. set guifont=Consolas:h11
  11. set fillchars+=vert:│ " u2502 vertical line separator
  12. set linespace=0
  13.  
  14. let $LANG = 'en_gb'
  15.  
  16. set langmenu=en_gb
  17.  
  18. " Unneeded keys
  19. nnoremap <F1> <nop>
  20. nnoremap Q <nop>
  21. nnoremap K <nop>
  22.  
  23. " colorscheme codeschool
  24. " let g:colors_name = 'codeschool'
  25. set background=light
  26. colorscheme bandit
  27.  
  28. " history
  29. set history=100
  30. set undolevels=1000
  31.  
  32. " Exclamations
  33. set noerrorbells
  34. set visualbell
  35. set t_vb= " Visual bell switches from audible bell to visual bell. Here in fact visual bell is disabled.
  36.  
  37. " Syntax
  38. syntax on
  39.  
  40. set modeline
  41. set modelines=2
  42.  
  43. set nolist " Because it affects text wrap by words
  44. set listchars=eol:$,tab:»\ ,trail:. " Make these markers visible - by differen colors
  45.  
  46. set wrapmargin=0 " (When textwidth!=0) Do not wrap basing on window size
  47.  
  48. set textwidth=0 " Do not hard-wrap basing on certain width
  49.  
  50. set wrap " Dynamic word wrap
  51. set linebreak " Do not brak words
  52. "set showbreak=… " What to show in the beginning of broken line
  53. set showbreak=└\ " What to show in the beginning of broken line
  54.  
  55. set tabstop=4 " Good for texts, not for programming
  56. set shiftwidth=4 " When using >>, << ; shall match with tabstop
  57. set softtabstop=0 " For insert mode
  58. set noexpandtab " Do not convert tabs to spaces
  59.  
  60. set backspace=indent,eol,start " Make backspace go to prev. line if en the ^
  61. set autoindent " Make indent same as previous line
  62.  
  63. set splitbelow " Good for preview window: to make it below
  64.  
  65. " Open file under cursor
  66. set isfname+=32 " When open files with gf, consider space as part of filename
  67. nnoremap gf :tab drop <cfile><CR> " Open new file only if it is not open in other tab; otherwise switch to that tab
  68.  
  69. " Reset autocommands
  70. au! InsertLeave *
  71. au! FocusLost *
  72. au! FocusGained *
  73. au! InsertEnter *
  74. au! InsertLeave *
  75.  
  76. " Line numbers
  77. set number " show line numbers
  78. set norelativenumber " Relative numbers affect performance for long files with long lines an syntax highlight
  79. "au FocusLost * :set norelativenumber
  80. "au FocusGained * :set relativenumber
  81. "au InsertEnter * :set norelativenumber
  82. "au InsertLeave * :set relativenumber
  83.  
  84. " Performance affecting
  85. " relativenumber
  86. " cursorli
  87. " cursorcolumn
  88. set nolazyredraw " Default. Makes more smooth. If performace affected, set this to yes; the result - lower FPS, but higher speed.
  89.  
  90. " folding
  91. set foldcolumn=1
  92.  
  93. " If using gvim, let use Alt combinations (disable invoking menu with Alt keys)
  94. set winaltkeys=no
  95.  
  96. " Working with buffers, tabs, windows
  97. set showtabline=2 " Always, even if there is only one tab
  98. set hidden " When editing a new or unsaved file, premit switching to another buffer (else will say that "Not saved")
  99.  
  100. " Handy keybindings
  101. nmap <A-Left> :tabprev<CR>
  102. nmap <A-Right> :tabnext<CR>
  103. nmap <A-Up> :bprev<CR>
  104. nmap <A-Down> :bnext<CR>
  105.  
  106. " After using :vimgrep or :make - switch results:
  107. map <C-j> :cn<CR>
  108. map <C-k> :cp<CR>
  109.  
  110.  
  111. " plugin: foldsearch
  112. " toggle search folding with z/
  113. nmap z/ :if (exists("w:foldsearch_viewfile")) \| :execute ":Fe" \| else \| :execute ":Fs" \| endif<CR>
  114.  
  115. " plugin: vm-session
  116. " Note: exceptionse like MiniBufExplorer add to function s:state_filter(line)
  117. let g:session_autosave_periodic=3 " Auto-save session every 3 minutes
  118. let g:session_autosave='yes' " Do not prompt if I want to save autosession
  119. let g:session_persist_colors = 0 " Do not save colors
  120.  
  121. " plugin: netrw (embedded) - invoked by :E command
  122. let g:netrw_browse_split=0 " Open file in the same window
  123.  
  124. " plugin: hashnotes
  125. nmap <F3> :call HashNotesAssignIndex()<CR>
  126.  
  127. " plugin: MiniBufExplorer
  128. nmap <F4> :MBEToggle<CR>
  129. let g:miniBufExplVSplit=33 " Exactly filename of new file
  130. let g:miniBufExplUseSingleClick=1 " Single mouse click opens the file
  131.  
  132. " plugin: diffchar
  133. " Improves diff: make by char/word etc
  134. " Warning 1: makes it slow
  135. " Warning 2: re-binds some keys. Prevent it.
  136. let g:DiffUnit="Word1"
  137.  
  138.  
  139. " ============ When exiting Insert mode, do not move cursor back
  140. " Aternative: http://compsci.ca/v3/viewtopic.php?t=34055
  141. function! s:CorrectPosition()
  142. if !exists("b:tmpNormalMode")
  143. let l:newCol = getpos('.')[2]
  144. if ( l:newCol != 1 )
  145. let l:newCol+=1
  146. endif
  147. call cursor(getpos('.')[1], l:newCol)
  148. else
  149. unlet b:tmpNormalMode
  150. endif
  151. endfunction
  152. au! InsertLeave * call <SID>CorrectPosition()
  153. inoremap <buffer> <silent> <C-o> <Esc>:let b:tmpNormalMode=1<CR>gi<C-o>
  154.  
  155. " au InsertLeave * exec "let newCol = getpos('.')[2] | if ( newCol != 1 ) | let newCol+=1 | endif | call cursor(getpos('.')[1], newCol)"
  156. " inoremap <buffer> <silent> <Esc> <C-o>:stopinsert<CR> " Makes modeline does not update! A bug
  157.  
  158. " ========== Make up/down movement by visible line, not by physical line:
  159. " Note: using imap to apply cursor position correction
  160. imap <buffer> <silent> <Up> <C-o>gk
  161. imap <buffer> <silent> <Down> <C-o>gj
  162. imap <buffer> <silent> <Home> <C-o>g<Home>
  163. imap <buffer> <silent> <End> <C-o>g<End>
  164.  
  165. " ========== Search
  166. " TODO: find n-th occurence of match; 5th occurence of 'e': \(\(e\).\{-}\)\{4\}\zs\2 ; use buttons to increase, decrease, return to original
  167. " Search as you type
  168. set incsearch
  169. " Higlight all search results
  170. " Actually it is on. Functions will be responsible for setting this variable
  171. set nohlsearch
  172.  
  173. " Remove search highlight on cursor move
  174. function! s:HlSearchOff()
  175. if ( exists ("b:last_search") && b:last_search==@/ )
  176. " need to clear
  177. if ( exists("b:search_cleared") && b:search_cleared==1 )
  178. " Do nothing
  179. else
  180. " nohlsearch " Does not work in autocmd and functions - see help
  181. " redraw
  182. set nohlsearch
  183. let b:search_cleared=1
  184. endif
  185. else
  186. let b:search_cleared=0
  187. set hlsearch
  188. endif
  189.  
  190. let b:last_search=@/
  191. endfunction
  192.  
  193. function! s:HlSearchOn()
  194. let b:search_cleared=0
  195. set hlsearch
  196. endfunction
  197.  
  198. autocmd! CursorMoved * call <SID>HlSearchOff()
  199.  
  200. nnoremap <silent> n n:call <SID>HlSearchOn()<CR>
  201. nnoremap <silent> N N:call <SID>HlSearchOn()<CR>
  202.  
  203. " Note: re-definition of /, ? etc currupts sequeces like d/x (delete till 'x')
  204. " 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.
  205.  
  206. " ========== Scroll
  207. set scrolloff=1 " Always show these amount of lines above and below cursor
  208.  
  209. " Keep cursor on-screen position when PgUp, PgDown
  210.  
  211. function! s:ScrollSave()
  212. " Affects cursor position
  213. let l:view=winsaveview()
  214. normal! H
  215. let l:view['Hline']=line('.')
  216. normal! L
  217. let l:view['Lline']=line('.')
  218. return l:view
  219. endfunction
  220. function! s:ScrollCorrect(view)
  221. " Works ok unless passing end of file
  222. normal! H
  223. let l:view=<SID>ScrollSave()
  224.  
  225. let l:view['curswant']=a:view['curswant']
  226.  
  227. let l:down=a:view['lnum']-a:view['Hline']
  228. if ( l:view['Hline']+l:down > l:view['Lline'] )
  229. let l:down=l:view['Lline']-l:view['Hline']
  230. endif
  231.  
  232. call winrestview(l:view)
  233.  
  234. if (l:down>0)
  235. exec "normal! " . l:down . "j"
  236. else
  237. normal! jk " To apply curswant.
  238. endif
  239. endfunction
  240.  
  241. nnoremap <silent> <PageUp> :<C-u>let w:scroll_view=<SID>ScrollSave() \| exec "normal! <C-v><C-b>" \| call <SID>ScrollCorrect(w:scroll_view)<CR>
  242. 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>
  243. nnoremap <silent> <PageDown> :<C-u>let w:scroll_view=<SID>ScrollSave() \| exec "normal! <C-v><C-f>" \| call <SID>ScrollCorrect(w:scroll_view)<CR>
  244. 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>
  245.  
  246. " ========== For programming
  247. " autocmd FileType cpp :set makeprg=g++\ -std=c++14\ -ggdb\ -o\ %:r\ %
  248. " autocmd FileType c :set makeprg=gcc\ -ggdb\ -o\ %:r\ %
  249. " nnoremap <F4> :write<CR>:make<CR>
  250. " nnoremap <F5> :!./%:r 2>%:r.log<CR>
  251. "
  252. " " Reengineering tool involving foldsearch. Rename word (function name, variable etc)
  253. " nmap <F2> :let winview=winsaveview()<CR>yiw*N:Fs<CR>:call winrestview(winview)<CR>
  254. "
  255. " " Better folding
  256. " " Set a nicer foldtext function
  257. " set foldtext=MyFoldText()
  258. " function! MyFoldText()
  259. " let line = getline(v:foldstart)
  260. " if match( line, '^[ \t]*\(\/\*\|\/\/\)[*/\\]*[ \t]*$' ) == 0
  261. " let initial = substitute( line, '^\([ \t]\)*\(\/\*\|\/\/\)\(.*\)', '\1\2', '' )
  262. " let linenum = v:foldstart + 1
  263. " while linenum < v:foldend
  264. " let line = getline( linenum )
  265. " let comment_content = substitute( line, '^\([ \t\/\*]*\)\(.*\)$', '\2', 'g' )
  266. " if comment_content != ''
  267. " break
  268. " endif
  269. " let linenum = linenum + 1
  270. " endwhile
  271. " let sub = initial . ' ' . comment_content
  272. " else
  273. " let sub = line
  274. " let startbrace = substitute( line, '^.*{[ \t]*$', '{', 'g')
  275. " if startbrace == '{'
  276. " let line = getline(v:foldend)
  277. " let endbrace = substitute( line, '^[ \t]*}\(.*\)$', '}', 'g')
  278. " if endbrace == '}'
  279. " let sub = sub.substitute( line, '^[ \t]*}\(.*\)$', '...}\1', 'g')
  280. " endif
  281. " endif
  282. " endif
  283. " let n = v:foldend - v:foldstart + 1
  284. " let info = " " . n . " lines"
  285. " let sub = sub . " "
  286. " let num_w = getwinvar( 0, '&number' ) * getwinvar( 0, '&numberwidth' )
  287. " let fold_w = getwinvar( 0, '&foldcolumn' )
  288. " let sub = strpart( sub, 0, winwidth(0) - strlen( info ) - num_w - fold_w - 1 )
  289. " return sub . info
  290. " endfunction
Advertisement
Add Comment
Please, Sign In to add comment