MIAOU-BASH is a collection of settings and helpers for leveraging BASH. Developer-friendly, it may be used as solo package with or without the miaou project.
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.

388 lines
9.2 KiB

9 months 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. set paste
  154. """"""""""""""""""""""""""""""
  155. " => Visual mode related
  156. """"""""""""""""""""""""""""""
  157. " Visual mode pressing * or # searches for the current selection
  158. " Super useful! From an idea by Michael Naumann
  159. vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
  160. vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
  161. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  162. " => Moving around, tabs, windows and buffers
  163. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  164. " Map <Space> to / (search) and Ctrl-<Space> to ? (backwards search)
  165. map <space> /
  166. map <c-space> ?
  167. " Disable highlight when <leader><cr> is pressed
  168. map <silent> <leader><cr> :noh<cr>
  169. " Smart way to move between windows
  170. map <C-j> <C-W>j
  171. map <C-k> <C-W>k
  172. map <C-h> <C-W>h
  173. map <C-l> <C-W>l
  174. " Close the current buffer
  175. map <leader>bd :Bclose<cr>:tabclose<cr>gT
  176. " Close all the buffers
  177. map <leader>ba :bufdo bd<cr>
  178. map <leader>l :bnext<cr>
  179. map <leader>h :bprevious<cr>
  180. " Useful mappings for managing tabs
  181. map <leader>tn :tabnew<cr>
  182. map <leader>to :tabonly<cr>
  183. map <leader>tc :tabclose<cr>
  184. map <leader>tm :tabmove
  185. map <leader>t<leader> :tabnext
  186. " Let 'tl' toggle between this and the last accessed tab
  187. let g:lasttab = 1
  188. nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
  189. au TabLeave * let g:lasttab = tabpagenr()
  190. " Opens a new tab with the current buffer's path
  191. " Super useful when editing files in the same directory
  192. map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
  193. " Switch CWD to the directory of the open buffer
  194. map <leader>cd :cd %:p:h<cr>:pwd<cr>
  195. " Specify the behavior when switching between buffers
  196. try
  197. set switchbuf=useopen,usetab,newtab
  198. set stal=2
  199. catch
  200. endtry
  201. " Return to last edit position when opening files (You want this!)
  202. au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
  203. """"""""""""""""""""""""""""""
  204. " => Status line
  205. """"""""""""""""""""""""""""""
  206. " Always show the status line
  207. set laststatus=2
  208. " Format the status line
  209. set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c
  210. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  211. " => Editing mappings
  212. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  213. " Remap VIM 0 to first non-blank character
  214. map 0 ^
  215. " Move a line of text using ALT+[jk] or Command+[jk] on mac
  216. nmap <M-j> mz:m+<cr>`z
  217. nmap <M-k> mz:m-2<cr>`z
  218. vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
  219. vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
  220. if has("mac") || has("macunix")
  221. nmap <D-j> <M-j>
  222. nmap <D-k> <M-k>
  223. vmap <D-j> <M-j>
  224. vmap <D-k> <M-k>
  225. endif
  226. " Delete trailing white space on save, useful for some filetypes ;)
  227. fun! CleanExtraSpaces()
  228. let save_cursor = getpos(".")
  229. let old_query = getreg('/')
  230. silent! %s/\s\+$//e
  231. call setpos('.', save_cursor)
  232. call setreg('/', old_query)
  233. endfun
  234. if has("autocmd")
  235. autocmd BufWritePre *.txt,*.js,*.py,*.wiki,*.sh,*.coffee :call CleanExtraSpaces()
  236. endif
  237. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  238. " => Spell checking
  239. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  240. " Pressing ,ss will toggle and untoggle spell checking
  241. map <leader>ss :setlocal spell!<cr>
  242. " Shortcuts using <leader>
  243. map <leader>sn ]s
  244. map <leader>sp [s
  245. map <leader>sa zg
  246. map <leader>s? z=
  247. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  248. " => Misc
  249. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  250. " Remove the Windows ^M - when the encodings gets messed up
  251. noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
  252. " Quickly open a buffer for scribble
  253. map <leader>q :e ~/buffer<cr>
  254. " Quickly open a markdown buffer for scribble
  255. map <leader>x :e ~/buffer.md<cr>
  256. " Toggle paste mode on and off
  257. map <leader>pp :setlocal paste!<cr>
  258. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  259. " => Helper functions
  260. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  261. " Returns true if paste mode is enabled
  262. function! HasPaste()
  263. if &paste
  264. return 'PASTE MODE '
  265. endif
  266. return ''
  267. endfunction
  268. " Don't close window, when deleting a buffer
  269. command! Bclose call <SID>BufcloseCloseIt()
  270. function! <SID>BufcloseCloseIt()
  271. let l:currentBufNum = bufnr("%")
  272. let l:alternateBufNum = bufnr("#")
  273. if buflisted(l:alternateBufNum)
  274. buffer #
  275. else
  276. bnext
  277. endif
  278. if bufnr("%") == l:currentBufNum
  279. new
  280. endif
  281. if buflisted(l:currentBufNum)
  282. execute("bdelete! ".l:currentBufNum)
  283. endif
  284. endfunction
  285. function! CmdLine(str)
  286. call feedkeys(":" . a:str)
  287. endfunction
  288. function! VisualSelection(direction, extra_filter) range
  289. let l:saved_reg = @"
  290. execute "normal! vgvy"
  291. let l:pattern = escape(@", "\\/.*'$^~[]")
  292. let l:pattern = substitute(l:pattern, "\n$", "", "")
  293. if a:direction == 'gv'
  294. call CmdLine("Ack '" . l:pattern . "' " )
  295. elseif a:direction == 'replace'
  296. call CmdLine("%s" . '/'. l:pattern . '/')
  297. endif
  298. let @/ = l:pattern
  299. let @" = l:saved_reg
  300. endfunction