You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

387 lines
9.2 KiB

6 years ago
  1. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  2. " Maintainer:
  3. " Amir Salihefendic — @amix3k
  4. "
  5. " Awesome_version:
  6. " Get this config, nice color schemes and lots of plugins!
  7. "
  8. " Install the awesome version from:
  9. "
  10. " https://github.com/amix/vimrc
  11. "
  12. " Sections:
  13. " -> General
  14. " -> VIM user interface
  15. " -> Colors and Fonts
  16. " -> Files and backups
  17. " -> Text, tab and indent related
  18. " -> Visual mode related
  19. " -> Moving around, tabs and buffers
  20. " -> Status line
  21. " -> Editing mappings
  22. " -> vimgrep searching and cope displaying
  23. " -> Spell checking
  24. " -> Misc
  25. " -> Helper functions
  26. "
  27. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  28. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  29. " => General
  30. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  31. " Sets how many lines of history VIM has to remember
  32. set history=500
  33. set nocompatible
  34. " Enable filetype plugins
  35. filetype plugin on
  36. filetype indent on
  37. " Set to auto read when a file is changed from the outside
  38. set autoread
  39. " With a map leader it's possible to do extra key combinations
  40. " like <leader>w saves the current file
  41. let mapleader = ","
  42. " Fast saving
  43. nmap <leader>w :w!<cr>
  44. " :W sudo saves the file
  45. " (useful for handling the permission-denied error)
  46. command W w !sudo tee % > /dev/null
  47. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  48. " => VIM user interface
  49. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  50. " Set 7 lines to the cursor - when moving vertically using j/k
  51. set so=7
  52. " Avoid garbled characters in Chinese language windows OS
  53. let $LANG='en'
  54. set langmenu=en
  55. source $VIMRUNTIME/delmenu.vim
  56. source $VIMRUNTIME/menu.vim
  57. " Turn on the Wild menu
  58. set wildmenu
  59. " Ignore compiled files
  60. set wildignore=*.o,*~,*.pyc
  61. if has("win16") || has("win32")
  62. set wildignore+=.git\*,.hg\*,.svn\*
  63. else
  64. set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
  65. endif
  66. "Always show current position
  67. set ruler
  68. " Height of the command bar
  69. set cmdheight=2
  70. " A buffer becomes hidden when it is abandoned
  71. set hid
  72. " Configure backspace so it acts as it should act
  73. " set,indent
  74. "set backspace=i
  75. set backspace=indent,eol,start
  76. fixdel
  77. set whichwrap+=<,>,h,l
  78. " Ignore case when searching
  79. set ignorecase
  80. " When searching try to be smart about cases
  81. set smartcase
  82. " Highlight search results
  83. set hlsearch
  84. " Makes search act like search in modern browsers
  85. set incsearch
  86. " Don't redraw while executing macros (good performance config)
  87. set lazyredraw
  88. " For regular expressions turn magic on
  89. set magic
  90. " Show matching brackets when text indicator is over them
  91. set showmatch
  92. " How many tenths of a second to blink when matching brackets
  93. set mat=2
  94. " No annoying sound on errors
  95. set noerrorbells
  96. set novisualbell
  97. set t_vb=
  98. set tm=500
  99. " Properly disable sound on errors on MacVim
  100. if has("gui_macvim")
  101. autocmd GUIEnter * set vb t_vb=
  102. endif
  103. " Add a bit extra margin to the left
  104. set foldcolumn=1
  105. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  106. " => Colors and Fonts
  107. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  108. " Enable syntax highlighting
  109. syntax enable
  110. " Enable 256 colors palette in Gnome Terminal
  111. if $COLORTERM == 'gnome-terminal'
  112. set t_Co=256
  113. endif
  114. try
  115. colorscheme desert
  116. catch
  117. endtry
  118. set background=dark
  119. " Set extra options when running in GUI mode
  120. if has("gui_running")
  121. set guioptions-=T
  122. set guioptions-=e
  123. set t_Co=256
  124. set guitablabel=%M\ %t
  125. endif
  126. " Set utf8 as standard encoding and en_US as the standard language
  127. set encoding=utf8
  128. " Use Unix as the standard file type
  129. set ffs=unix,dos,mac
  130. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  131. " => Files, backups and undo
  132. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  133. " Turn backup off, since most stuff is in SVN, git et.c anyway...
  134. set nobackup
  135. set nowb
  136. set noswapfile
  137. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  138. " => Text, tab and indent related
  139. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  140. " Use spaces instead of tabs
  141. set expandtab
  142. " Be smart when using tabs ;)
  143. set smarttab
  144. " 1 tab == 4 spaces
  145. set shiftwidth=4
  146. set tabstop=4
  147. " Linebreak on 500 characters
  148. set lbr
  149. set tw=500
  150. set ai "Auto indent
  151. set si "Smart indent
  152. set wrap "Wrap lines
  153. """"""""""""""""""""""""""""""
  154. " => Visual mode related
  155. """"""""""""""""""""""""""""""
  156. " Visual mode pressing * or # searches for the current selection
  157. " Super useful! From an idea by Michael Naumann
  158. vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
  159. vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
  160. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  161. " => Moving around, tabs, windows and buffers
  162. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  163. " Map <Space> to / (search) and Ctrl-<Space> to ? (backwards search)
  164. map <space> /
  165. map <c-space> ?
  166. " Disable highlight when <leader><cr> is pressed
  167. map <silent> <leader><cr> :noh<cr>
  168. " Smart way to move between windows
  169. map <C-j> <C-W>j
  170. map <C-k> <C-W>k
  171. map <C-h> <C-W>h
  172. map <C-l> <C-W>l
  173. " Close the current buffer
  174. map <leader>bd :Bclose<cr>:tabclose<cr>gT
  175. " Close all the buffers
  176. map <leader>ba :bufdo bd<cr>
  177. map <leader>l :bnext<cr>
  178. map <leader>h :bprevious<cr>
  179. " Useful mappings for managing tabs
  180. map <leader>tn :tabnew<cr>
  181. map <leader>to :tabonly<cr>
  182. map <leader>tc :tabclose<cr>
  183. map <leader>tm :tabmove
  184. map <leader>t<leader> :tabnext
  185. " Let 'tl' toggle between this and the last accessed tab
  186. let g:lasttab = 1
  187. nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
  188. au TabLeave * let g:lasttab = tabpagenr()
  189. " Opens a new tab with the current buffer's path
  190. " Super useful when editing files in the same directory
  191. map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
  192. " Switch CWD to the directory of the open buffer
  193. map <leader>cd :cd %:p:h<cr>:pwd<cr>
  194. " Specify the behavior when switching between buffers
  195. try
  196. set switchbuf=useopen,usetab,newtab
  197. set stal=2
  198. catch
  199. endtry
  200. " Return to last edit position when opening files (You want this!)
  201. au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
  202. """"""""""""""""""""""""""""""
  203. " => Status line
  204. """"""""""""""""""""""""""""""
  205. " Always show the status line
  206. set laststatus=2
  207. " Format the status line
  208. set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c
  209. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  210. " => Editing mappings
  211. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  212. " Remap VIM 0 to first non-blank character
  213. map 0 ^
  214. " Move a line of text using ALT+[jk] or Command+[jk] on mac
  215. nmap <M-j> mz:m+<cr>`z
  216. nmap <M-k> mz:m-2<cr>`z
  217. vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
  218. vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
  219. if has("mac") || has("macunix")
  220. nmap <D-j> <M-j>
  221. nmap <D-k> <M-k>
  222. vmap <D-j> <M-j>
  223. vmap <D-k> <M-k>
  224. endif
  225. " Delete trailing white space on save, useful for some filetypes ;)
  226. fun! CleanExtraSpaces()
  227. let save_cursor = getpos(".")
  228. let old_query = getreg('/')
  229. silent! %s/\s\+$//e
  230. call setpos('.', save_cursor)
  231. call setreg('/', old_query)
  232. endfun
  233. if has("autocmd")
  234. autocmd BufWritePre *.txt,*.js,*.py,*.wiki,*.sh,*.coffee :call CleanExtraSpaces()
  235. endif
  236. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  237. " => Spell checking
  238. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  239. " Pressing ,ss will toggle and untoggle spell checking
  240. map <leader>ss :setlocal spell!<cr>
  241. " Shortcuts using <leader>
  242. map <leader>sn ]s
  243. map <leader>sp [s
  244. map <leader>sa zg
  245. map <leader>s? z=
  246. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  247. " => Misc
  248. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  249. " Remove the Windows ^M - when the encodings gets messed up
  250. noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
  251. " Quickly open a buffer for scribble
  252. map <leader>q :e ~/buffer<cr>
  253. " Quickly open a markdown buffer for scribble
  254. map <leader>x :e ~/buffer.md<cr>
  255. " Toggle paste mode on and off
  256. map <leader>pp :setlocal paste!<cr>
  257. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  258. " => Helper functions
  259. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  260. " Returns true if paste mode is enabled
  261. function! HasPaste()
  262. if &paste
  263. return 'PASTE MODE '
  264. endif
  265. return ''
  266. endfunction
  267. " Don't close window, when deleting a buffer
  268. command! Bclose call <SID>BufcloseCloseIt()
  269. function! <SID>BufcloseCloseIt()
  270. let l:currentBufNum = bufnr("%")
  271. let l:alternateBufNum = bufnr("#")
  272. if buflisted(l:alternateBufNum)
  273. buffer #
  274. else
  275. bnext
  276. endif
  277. if bufnr("%") == l:currentBufNum
  278. new
  279. endif
  280. if buflisted(l:currentBufNum)
  281. execute("bdelete! ".l:currentBufNum)
  282. endif
  283. endfunction
  284. function! CmdLine(str)
  285. call feedkeys(":" . a:str)
  286. endfunction
  287. function! VisualSelection(direction, extra_filter) range
  288. let l:saved_reg = @"
  289. execute "normal! vgvy"
  290. let l:pattern = escape(@", "\\/.*'$^~[]")
  291. let l:pattern = substitute(l:pattern, "\n$", "", "")
  292. if a:direction == 'gv'
  293. call CmdLine("Ack '" . l:pattern . "' " )
  294. elseif a:direction == 'replace'
  295. call CmdLine("%s" . '/'. l:pattern . '/')
  296. endif
  297. let @/ = l:pattern
  298. let @" = l:saved_reg
  299. endfunction