Advertisement
kaenan

win-vimrc

Mar 27th, 2018
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 16.17 KB | None | 0 0
  1. " From:
  2. "       Amir Salihefendic
  3. "       http://amix.dk - amix@amix.dk
  4. "
  5. " Version:
  6. "       5.0 - 29/05/12 15:43:36
  7. "
  8. " Sections:
  9. "    -> General
  10. "    -> VIM user interface
  11. "    -> Colors and Fonts
  12. "    -> Files and backups
  13. "    -> Text, tab and indent related
  14. "    -> Visual mode related
  15. "    -> Moving around, tabs and buffers
  16. "    -> Status line
  17. "    -> Editing mappings
  18. "    -> vimgrep searching and cope displaying
  19. "    -> Spell checking
  20. "    -> Misc
  21. "    -> Helper functions
  22. "
  23. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  24.  
  25. "Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }
  26. "Plug 'w0rp/ale'
  27. "
  28.  
  29. let $MYVIMRC = split($VIM, "\\")[0] . "\\config\\nvim\\init.vim"
  30.  
  31. " Windows setup
  32. let $HOMEDRIVE = split($VIM, "\\")[0]
  33. let $HOMEPATH = "\\"
  34. let $HOME = $HOMEDRIVE . $HOMEPATH
  35. let $USERPROFILE = $HOME
  36. let $LOCALAPPDATA = $HOME . "config"
  37. let $PATH = $HOMEDRIVE . "\\emacs\\mingw64\\bin" . ";" . $HOMEDRIVE . "\\emacs\\bin" . ";" . $HOMEDRIVE . "\\cmder" . ";" . $HOMEDRIVE . "\\emacs\\Git\\bin" . ";" . "C:\\Windows\\System32" . ";" . "C:\\Windows"
  38.  
  39.  
  40. set nocompatible               " be improved, required
  41. filetype off                   " required
  42. " set the runtime path to include Vundle and initialize
  43. "if has('nvim')
  44. "    let s:editor_root=expand("~\AppData\Local\nvim")
  45. "else
  46. "    let s:editor_root=expand("~\.vim")
  47. "endif
  48.  
  49. set rtp+=~\config\nvim\bundle\Vundle.vim
  50. "let &rtp = &rtp . ',' . s:editor_root . '/bundle/vundle/'
  51. call vundle#begin()            " required
  52. Plugin 'VundleVim/Vundle.vim'  " required
  53.  
  54. " ===================
  55. " my plugins here
  56. " ===================
  57. Plugin 'tpope/vim-fugitive'
  58. Plugin 'scrooloose/nerdtree'
  59.  
  60. " Plugin 'dracula/vim'
  61.  
  62.  
  63. " ===================
  64. " end of plugins
  65. " ===================
  66. call vundle#end()               " required
  67. filetype plugin indent on       " required
  68.  
  69. set mat=1
  70. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  71. " => Turn persistent undo on
  72. "    means that you can undo even when you close a buffer/VIM
  73. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  74. try
  75.     set undodir=~/.vim-undo
  76.     set undofile
  77. catch
  78. endtry
  79.  
  80. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  81. " => Command mode related
  82. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  83. " Smart mappings on the command line
  84. cno $h e ~/
  85. cno $d e ~/Desktop/
  86. cno $j e ./
  87. cno $c e <C-\>eCurrentFileDir("e")<cr>
  88.  
  89. " $q is super useful when browsing on the command line
  90. " it deletes everything until the last slash
  91. cno $q <C-\>eDeleteTillSlash()<cr>
  92.  
  93. " Bash like keys for the command line
  94. cnoremap <C-A>          <Home>
  95. cnoremap <C-E>          <End>
  96. cnoremap <C-K>          <C-U>
  97.  
  98. cnoremap <C-P> <Up>
  99. cnoremap <C-N> <Down>
  100.  
  101.  
  102. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  103. " => Parenthesis/bracket
  104. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  105. vnoremap $1 <esc>`>a)<esc>`<i(<esc>
  106. vnoremap $2 <esc>`>a]<esc>`<i[<esc>
  107. vnoremap $3 <esc>`>a}<esc>`<i{<esc>
  108. vnoremap $$ <esc>`>a"<esc>`<i"<esc>
  109. vnoremap $q <esc>`>a'<esc>`<i'<esc>
  110. vnoremap $e <esc>`>a"<esc>`<i"<esc>
  111.  
  112. " Map auto complete of (, ", ', [
  113. inoremap $1 ()<esc>i
  114. inoremap $2 []<esc>i
  115. inoremap $3 {}<esc>i
  116. inoremap $4 {<esc>o}<esc>O
  117. inoremap $q ''<esc>i
  118. inoremap $e ""<esc>i
  119.  
  120.  
  121. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  122. " => General
  123. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  124. " Don't emulate vi
  125. set nocompatible
  126.  
  127. " Provides tab-completion for all file-related tasks
  128. set path+=**
  129.  
  130. " Display all matching files for tab completion
  131. set wildmenu
  132.  
  133. " TODO Create tags file
  134. " command! MakeTags !ctags -R . --pwd needs to be checked first
  135.  
  136. " File browsing
  137. " let g:netrw_banner=0        " disable annoying banner
  138. " let g:netrw_browse_split=4  " open in prior window
  139. " let g:netrw_altv=1          " open splits to the right
  140. " let g:netrw_liststyle=3     " tree view
  141. " let g:netrw_list_hide=netrw_gitignore#Hide()
  142. " let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+'
  143.  
  144. " Sets how many lines of history VIM has to remember
  145. set history=500
  146.  
  147. " Enable clipboard
  148. " set clipboard=unnamedplus
  149.  
  150. " Enable filetype plugins
  151. filetype plugin on
  152. filetype indent on
  153.  
  154. " Set to auto read when a file is changed from the outside
  155. set autoread
  156.  
  157. " With a map leader it's possible to do extra key combinations
  158. " like <leader>w saves the current file
  159. let mapleader = ","
  160. let g:mapleader = ","
  161.  
  162. " ..............................................................
  163. nnoremap ; :
  164. vnoremap ; :
  165.  
  166. " Fast saving
  167. nmap <leader>w :w!<cr>
  168.  
  169. " :W sudo saves the file
  170. " (useful for handling the permission-denied error)
  171. command W w !sudo tee % > /dev/null
  172.  
  173. " Key code delay
  174. if !has('nvim') && &ttimeoutlen == -1
  175.   set ttimeout
  176.   set ttimeoutlen=100
  177. endif
  178.  
  179. " Delete comment character when joining commented lines
  180. set formatoptions+=j
  181.  
  182. if has('path_extra')
  183.   setglobal tags-=./tags tags-=./tags; tags^=./tags;
  184. endif
  185.  
  186.  
  187. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  188. " => VIM user interface
  189. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  190. " Set 7 lines to the cursor - when moving vertically using j/k
  191. set so=2
  192.  
  193. " Avoid garbled characters in Chinese language windows OS
  194. let $LANG='en'
  195. set langmenu=en
  196. "source $VIMRUNTIME/delmenu.vim
  197. "source $VIMRUNTIME/menu.vim
  198.  
  199. " Turn on the WiLd menu
  200. set wildmenu
  201.  
  202. " Ignore compiled files
  203. set wildignore=*.o,*~,*.pyc
  204. if has("win16") || has("win32")
  205.     set wildignore+=.git\*,.hg\*,.svn\*
  206. else
  207.     set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
  208. endif
  209.  
  210. "Always show current position
  211. set ruler
  212.  
  213. " Enable numbers
  214. set relativenumber
  215. " Height of the command bar
  216. set cmdheight=2
  217.  
  218. " A buffer becomes hidden when it is abandoned
  219. set hid
  220.  
  221. " Configure backspace so it acts as it should act
  222. set backspace=eol,start,indent
  223. set whichwrap+=<,>,h,l
  224.  
  225. " Ignore case when searching
  226. set ignorecase
  227.  
  228. " When searching try to be smart about cases
  229. set smartcase
  230.  
  231. " Highlight search results
  232. set hlsearch
  233.  
  234. " Makes search act like search in modern browsers
  235. set incsearch
  236.  
  237. " Don't redraw while executing macros (good performance config)
  238. set lazyredraw
  239.  
  240. " For regular expressions turn magic on
  241. set magic
  242.  
  243. " Show matching brackets when text indicator is over them
  244. set showmatch
  245.  
  246. " How many tenths of a second to blink when matching brackets
  247. set mat=2
  248.  
  249. " No annoying sound on errors
  250. set noerrorbells
  251. set novisualbell
  252. set t_vb=
  253. set tm=500
  254.  
  255. " Properly disable sound on errors on MacVim
  256. if has("gui_macvim")
  257.     autocmd GUIEnter * set vb t_vb=
  258. endif
  259.  
  260. " Add a bit extra margin to the left
  261. set foldcolumn=1
  262.  
  263.  
  264. " Show extra space characters
  265. " set list listchars=tab:ยปยท,trail:ยท
  266. if &listchars ==# 'eol:$'
  267.   set listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+
  268. endif
  269.  
  270. " Highlight current line
  271. set cursorline
  272.  
  273. " @@@
  274. set display+=lastline
  275.  
  276. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  277. " => Colors and Fonts
  278. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  279. " Enable syntax highlighting
  280. syntax enable
  281.  
  282. set t_Co=256
  283.  
  284. source $VIM\theme.vim
  285.  
  286. " Set extra options when running in GUI mode
  287. if has("gui_running")
  288.     set guioptions-=T
  289.     set guioptions-=e
  290.     set guitablabel=%M\ %t
  291. endif
  292.  
  293. " Set utf8 as standard encoding and en_US as the standard language
  294. set encoding=utf8
  295.  
  296. " Use Unix as the standard file type
  297. set ffs=unix,dos,mac
  298.  
  299.  
  300. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  301. " => Files, backups and undo
  302. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  303. " Turn backup off, since most stuff is in SVN, git et.c anyway...
  304. set nobackup
  305. set wb
  306. set noswapfile
  307.  
  308.  
  309. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  310. " => Text, tab and indent related
  311. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  312. " Use spaces instead of tabs
  313. set expandtab
  314.  
  315. " Be smart when using tabs ;)
  316. set smarttab
  317.  
  318. " 1 tab == 4 spaces
  319. set shiftwidth=4
  320. set tabstop=4
  321.  
  322. " Linebreak on 500 characters
  323. set lbr
  324. set tw=500
  325.  
  326. set ai "Auto indent
  327. set si "Smart indent
  328. set wrap "Wrap lines
  329.  
  330.  
  331. """"""""""""""""""""""""""""""
  332. " => Visual mode related
  333. """"""""""""""""""""""""""""""
  334. " Visual mode pressing * or # searches for the current selection
  335. " Super useful! From an idea by Michael Naumann
  336. vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
  337. vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
  338.  
  339.  
  340. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  341. " => Moving around, tabs, windows and buffers
  342. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  343. " Map <Space> to / (search) and Ctrl-<Space> to ? (backwards search)
  344. map <space> <Nop>
  345. map <c-space> <Nop>
  346.  
  347. " Disable highlight when <leader><cr> is pressed
  348. " map <silent> <leader><cr> :noh<cr>
  349. if maparg('<leader><cr>', 'n') ==# ''
  350.   nnoremap <silent> <leader><cr> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
  351. endif
  352.  
  353. " Smart way to move between windows
  354. map <C-j> <C-W>j
  355. map <C-k> <C-W>k
  356. map <C-h> <C-W>h
  357. map <C-l> <C-W>l
  358.  
  359. " Close the current buffer
  360. map <leader>bd :Bclose<cr>:tabclose<cr>gT
  361.  
  362. " Close all the buffers
  363. map <leader>ba :bufdo bd<cr>
  364.  
  365. " Close all the buffers
  366. map <leader>bb :ls<cr>
  367.  
  368. " Navigate through buffers
  369. map <leader>, :bnext<cr>
  370. map <leader>. :bprevious<cr>
  371. map <leader>1 :b1<cr>
  372. map <leader>2 :b2<cr>
  373. map <leader>3 :b3<cr>
  374. map <leader>4 :b4<cr>
  375. map <leader>5 :b5<cr>
  376. map <leader>6 :b6<cr>
  377. map <leader>7 :b7<cr>
  378. map <leader>8 :b8<cr>
  379. map <leader>9 :b9<cr>
  380. map <leader>0 :b0<cr>
  381.  
  382. " Useful mappings for managing tabs
  383. map <leader>tn :tabnew<cr>
  384. map <leader>to :tabonly<cr>
  385. map <leader>tc :tabclose<cr>
  386. map <leader>tm :tabmove<cr>
  387. map <leader>t<leader> :tabnext<cr>
  388.  
  389. " Let 'tl' toggle between this and the last accessed tab
  390. let g:lasttab = 1
  391. nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
  392. au TabLeave * let g:lasttab = tabpagenr()
  393.  
  394.  
  395. " Opens a new tab with the current buffer's path
  396. " Super useful when editing files in the same directory
  397. map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
  398.  
  399. " Switch CWD to the directory of the open buffer
  400. map <leader>cd :cd %:p:h<cr>:pwd<cr>
  401.  
  402. " Specify the behavior when switching between buffers
  403. try
  404.   set switchbuf=useopen,usetab,newtab
  405.   set stal=2
  406. catch
  407. endtry
  408.  
  409. " Return to last edit position when opening files
  410. au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
  411.  
  412.  
  413. """"""""""""""""""""""""""""""
  414. " => Status line
  415. """"""""""""""""""""""""""""""
  416. " Always show the status line
  417. set laststatus=2
  418.  
  419. " Format the status line
  420. set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ f:%{&ff}\ \ i:\%03.3b,0x:\%02.2B\ \ (%03l,%03v)[%p%%]
  421.  
  422.  
  423. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  424. " => Editing mappings
  425. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  426. " Remap VIM 0 to first non-blank character
  427. map 0 ^
  428.  
  429. " Move a line of text using ALT+[jk] or Command+[jk] on mac
  430. nmap <M-j> mz:m+<cr>`z
  431. nmap <M-k> mz:m-2<cr>`z
  432. vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
  433. vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
  434. " TODO  fix keybindings
  435.  
  436. " Delete trailing white space on save, useful for Python and CoffeeScript ;)
  437. func! DeleteTrailingWS()
  438.   exe "normal mz"
  439.   %s/\s\+$//ge
  440.   exe "normal `z"
  441. endfunc
  442. autocmd BufWrite *.py :call DeleteTrailingWS()
  443. autocmd BufWrite *.coffee :call DeleteTrailingWS()
  444.  
  445. inoremap <C-U> <C-G>u<C-U>
  446.  
  447. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  448. " => Ag searching and cope displaying
  449. "    requires ag.vim - it's much better than vimgrep/grep
  450. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  451. " When you press gv you Ag after the selected text
  452. vnoremap <silent> gv :call VisualSelection('gv', '')<CR>
  453.  
  454. " Open Ag and put the cursor in the right position
  455. map <leader>g :Ag
  456.  
  457. " When you press <leader>r you can search and replace the selected text
  458. vnoremap <silent> <leader>r :call VisualSelection('replace', '')<CR>
  459.  
  460. " Do :help cope if you are unsure what cope is. It's super useful!
  461. "
  462. " When you search with Ag, display your results in cope by doing:
  463. "   <leader>cc
  464. "
  465. " To go to the next search result do:
  466. "   <leader>n
  467. "
  468. " To go to the previous search results do:
  469. "   <leader>p
  470. "
  471. map <leader>cc :botright cope<cr>
  472. map <leader>co ggVGy:tabnew<cr>:set syntax=qf<cr>pgg
  473. map <leader>n :cn<cr>
  474. map <leader>p :cp<cr>
  475.  
  476.  
  477. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  478. " => Spell checking
  479. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  480. " Pressing ,ss will toggle and untoggle spell checking
  481. map <leader>ss :setlocal spell!<cr>
  482.  
  483. " Shortcuts using <leader>
  484. map <leader>sn ]s
  485. map <leader>sp [s
  486. map <leader>sa zg
  487. map <leader>s? z=
  488.  
  489.  
  490. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  491. " => Misc
  492. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  493. " Remove the Windows ^M - when the encodings gets messed up
  494. noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
  495.  
  496. " Quickly open a buffer for scribble
  497. map <leader>q :e ~/buffer<cr>
  498.  
  499. " Quickly open a markdown buffer for scribble
  500. map <leader>x :e ~/buffer.md<cr>
  501.  
  502. " Toggle paste mode on and off
  503. map <leader>pp :setlocal paste!<cr>
  504.  
  505. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  506. " => Plug-ins related
  507. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  508. "
  509. " Plug-ins setup
  510. "
  511. " NERDTree
  512. autocmd BufEnter * lcd %:p:h
  513. " ale
  514. " let g:ale_echo_msg_error_str = 'E'
  515. " let g:ale_echo_msg_warning_str = 'W'
  516. " let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
  517.  
  518. " let g:ale_fixers = {
  519.             \ 'c': ['clang-format']}
  520. " TODO Figure out how to pass args to clang-format
  521. " let g:ale_c_clangformat_executable='-style=Mozilla'
  522.  
  523. "
  524. " Plug-ins keybindings
  525. "
  526. nnoremap - :NERDTreeToggle<cr>
  527. " nmap <silent> ]a <Plug>(ale_next_wrap)
  528. " nmap <silent> [a <Plug>(ale_previous_wrap)
  529. " nmap <leader>T :ALEToggle<cr>
  530.  
  531. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  532. " => Helper functions
  533. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  534. function! CmdLine(str)
  535.     exe "menu Foo.Bar :" . a:str
  536.     emenu Foo.Bar
  537.     unmenu Foo
  538. endfunction
  539.  
  540. function! VisualSelection(direction, extra_filter) range
  541.     let l:saved_reg = @"
  542.     execute "normal! vgvy"
  543.  
  544.     let l:pattern = escape(@", '\\/.*$^~[]')
  545.     let l:pattern = substitute(l:pattern, "\n$", "", "")
  546.  
  547.     if a:direction == 'gv'
  548.         call CmdLine("Ag \"" . l:pattern . "\" " )
  549.     elseif a:direction == 'replace'
  550.         call CmdLine("%s" . '/'. l:pattern . '/')
  551.     endif
  552.  
  553.     let @/ = l:pattern
  554.     let @" = l:saved_reg
  555. endfunction
  556.  
  557.  
  558. " Returns true if paste mode is enabled
  559. function! HasPaste()
  560.     if &paste
  561.         return 'PASTE MODE  '
  562.     endif
  563.     return ''
  564. endfunction
  565.  
  566. " Don't close window, when deleting a buffer
  567. command! Bclose call <SID>BufcloseCloseIt()
  568. function! <SID>BufcloseCloseIt()
  569.    let l:currentBufNum = bufnr("%")
  570.    let l:alternateBufNum = bufnr("#")
  571.  
  572.    if buflisted(l:alternateBufNum)
  573.      buffer #
  574.    else
  575.      bnext
  576.    endif
  577.  
  578.    if bufnr("%") == l:currentBufNum
  579.      new
  580.    endif
  581.  
  582.    if buflisted(l:currentBufNum)
  583.      execute("bdelete! ".l:currentBufNum)
  584.    endif
  585. endfunction
  586.  
  587.  
  588.  
  589. func! DeleteTillSlash()
  590.     let g:cmd = getcmdline()
  591.  
  592.     if has("win16") || has("win32")
  593.         let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\]\\).*", "\\1", "")
  594.     else
  595.         let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*", "\\1", "")
  596.     endif
  597.  
  598.     if g:cmd == g:cmd_edited
  599.         if has("win16") || has("win32")
  600.             let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\\]\\).*\[\\\\\]", "\\1", "")
  601.         else
  602.             let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*/", "\\1", "")
  603.         endif
  604.     endif
  605.  
  606.     return g:cmd_edited
  607. endfunc
  608.  
  609. func! CurrentFileDir(cmd)
  610.     return a:cmd . " " . expand("%:p:h") . "/"
  611. endfunc
  612.  
  613. " function! LinterStatus() abort
  614.     " let l:counts = ale#statusline#Count(bufnr(''))
  615. "
  616.     " let l:all_errors = l:counts.error + l:counts.style_error
  617.     " let l:all_non_errors = l:counts.total - l:all_errors
  618. "
  619.     " return l:counts.total == 0 ? 'OK' : printf(
  620.     " \   '%dW %dE',
  621.     " \   all_non_errors,
  622.     " \   all_errors
  623.     " \)
  624. " endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement