mdelatorre

.vimrc config file for macosx

Sep 30th, 2020 (edited)
918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 8.77 KB | None | 0 0
  1. "+-----------------------------------------------------------+
  2. "|                   ViM Configuration file                  |
  3. "+ ----------------------------------------------------------+
  4.  
  5. " ------------------------------------------------------------
  6. " GENERAL OPTIONS
  7. " ------------------------------------------------------------
  8.  
  9. "Sets number lines
  10. set number
  11.  
  12. " Sets how many lines of history VIM has to remember
  13. set history=500
  14.  
  15. " Enable filetype plugins
  16. filetype plugin on
  17. filetype indent on
  18.  
  19. " Set to auto read when a file is changed from the outside
  20. set autoread
  21. au FocusGained,BufEnter * checktime
  22.  
  23. " With a map leader it's possible to do extra key combinations
  24. " like <leader>w saves the current file
  25. let mapleader = ","
  26.  
  27. " Fast saving
  28. nmap <leader>w :w!<cr>
  29.  
  30. " :W uses sudo to save the file
  31. " (useful for handling the permission-denied error)
  32. command! W execute 'w !sudo tee % > /dev/null' <bar> edit!
  33.  
  34. " ------------------------------------------------------------
  35. " USER INTERFACE
  36. " ------------------------------------------------------------
  37.  
  38. " Set 5 lines offset to the cursor - when moving vertically using j/k
  39. set so=5
  40.  
  41. " Turn on the Wild menui to enable a menu at the botton of the windows
  42. " in command line mode
  43. set wildmenu
  44.  
  45. " Enable full mouse support in the console
  46. set mouse=a
  47.  
  48. " Ignore compiled files
  49. set wildignore=*.o,*~,*.pyc
  50. if has("win16") || has("win32")
  51.     set wildignore+=.git\*,.hg\*,.svn\*
  52. else
  53.     set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
  54. endif
  55.  
  56. "Always show current position
  57. set ruler
  58.  
  59. " Height of the command bar
  60. set cmdheight=1
  61.  
  62. " A buffer becomes hidden when it is abandoned
  63. set hid
  64.  
  65. " Ignore case when searching
  66. set ignorecase
  67.  
  68. " When searching try to be smart about cases
  69. set smartcase
  70.  
  71. " Highlight search results
  72. set hlsearch
  73.  
  74. " Makes search act like search in modern browsers
  75. set incsearch
  76.  
  77. " Don't redraw while executing macros (good performance config)
  78. set lazyredraw
  79.  
  80. " For regular expressions turn magic on
  81. set magic
  82.  
  83. " Show matching brackets when text indicator is over them
  84. set showmatch
  85. " How many tenths of a second to blink when matching brackets
  86. set mat=2
  87.  
  88. " No annoying sound on errors
  89. set noerrorbells
  90. set novisualbell
  91. set t_vb=
  92. set tm=500
  93.  
  94. " Properly disable sound on errors on MacVim
  95. if has("gui_macvim")
  96.     autocmd GUIEnter * set vb t_vb=
  97. endif
  98.  
  99. " Add a bit extra margin to the left
  100. set foldcolumn=1
  101.  
  102. " COLORS AND FONTS
  103.  
  104. " Enable syntax highlighting
  105. syntax enable
  106.  
  107. " Enable 256 colors palette in Gnome Terminal
  108. if $COLORTERM == 'gnome-terminal'
  109.     set t_Co=256
  110. endif
  111.  
  112. try
  113.     colorscheme desert
  114. catch
  115. endtry
  116.  
  117. set background=dark
  118.  
  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.  
  127. " Set utf8 as standard encoding and en_US as the standard language
  128. set encoding=utf8
  129.  
  130. " Use Unix as the standard file type
  131. set ffs=unix,dos,mac
  132.  
  133. " ------------------------------------------------------------
  134. " FILES, BACKUPS & UNDO
  135. " ------------------------------------------------------------
  136. " Turn backup off, since most stuff is in SVN, git etc. anyway...
  137. set nobackup
  138. set nowb
  139. set noswapfile
  140. " ------------------------------------------------------------
  141. " TEXT, TAB AND INDENT RELATED
  142. " ------------------------------------------------------------
  143. " Use spaces instead of tabs
  144. set expandtab
  145.  
  146. set smarttab
  147.  
  148. " 1 tab == 4 spaces
  149. set shiftwidth=4
  150. set tabstop=4
  151.  
  152. " Linebreak on 500 characters
  153. set lbr
  154. set tw=500
  155.  
  156. set ai "Auto indent
  157. set si "Smart indent
  158. set wrap "Wrap lines longer than the width of the window anywhere
  159. set linebreak "Wrap long lines not inserting EOL. Its word bound oriented.
  160. set textwidth=0 "Disables inserting EOL line breaks
  161. set wrapmargin=0 "Disables inserting EOL when wraping
  162. " ------------------------------------------------------------
  163. " VISUAL MODE RELATED
  164. " ------------------------------------------------------------
  165.  
  166. " Visual mode pressing * or # searches for the current selection
  167. vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
  168. vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
  169.  
  170. " Disable highlight when <leader><cr> is pressed
  171. map <silent> <leader><cr> :noh<cr>
  172.  
  173. " Smart way to move between windows
  174. map <C-j> <C-W>j
  175. map <C-k> <C-W>k
  176. map <C-h> <C-W>h
  177. map <C-l> <C-W>l
  178.  
  179. " Close the current buffer
  180. map <leader>bd :Bclose<cr>:tabclose<cr>gT
  181.  
  182. " Close all the buffers
  183. map <leader>ba :bufdo bd<cr>
  184.  
  185. map <leader>l :bnext<cr>
  186. map <leader>h :bprevious<cr>
  187.  
  188. " Useful mappings for managing tabs
  189. map <leader>tn :tabnew<cr>
  190. map <leader>to :tabonly<cr>
  191. map <leader>tc :tabclose<cr>
  192. map <leader>tm :tabmove
  193. map <leader>t<leader> :tabnext
  194.  
  195. " Let 'tl' toggle between this and the last accessed tab
  196. let g:lasttab = 1
  197. nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
  198. au TabLeave * let g:lasttab = tabpagenr()
  199.  
  200. " Opens a new tab with the current buffer's path
  201. " Super useful when editing files in the same directory
  202. map <leader>te :tabedit <C-r>=expand("%:p:h")<cr>/
  203.  
  204. " Switch CWD to the directory of the open buffer
  205. map <leader>cd :cd %:p:h<cr>:pwd<cr>
  206.  
  207. " Specify the behavior when switching between buffers
  208. try
  209.   set switchbuf=useopen,usetab,newtab
  210.   set stal=2
  211. catch
  212. endtry
  213.  
  214. " Return to last edit position when opening files (You want this!)
  215. au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
  216.  
  217. " ------------------------------------------------------------
  218. " STATUS LINE RELATED
  219. " ------------------------------------------------------------
  220.  
  221. " Always show the status line
  222. set laststatus=2
  223.  
  224. " Format the status line
  225. set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c
  226.  
  227. " ------------------------------------------------------------
  228. " EDITING MAPPINGS RELATED
  229. " -------------------------------------------------------------
  230.  
  231. " Remap VIM 0 to first non-blank character
  232. map 0 ^
  233.  
  234. " Move a line of text using ALT+[jk] or Command+[jk] on mac
  235. nmap <M-j> mz:m+<cr>`z
  236. nmap <M-k> mz:m-2<cr>`z
  237. vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
  238. vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
  239.  
  240. if has("mac") || has("macunix")
  241.   nmap <D-j> <M-j>
  242.   nmap <D-k> <M-k>
  243.   vmap <D-j> <M-j>
  244.   vmap <D-k> <M-k>
  245. endif
  246.  
  247. " Delete trailing white space on save, useful for some filetypes ;)
  248. fun! CleanExtraSpaces()
  249.     let save_cursor = getpos(".")
  250.     let old_query = getreg('/')
  251.     silent! %s/\s\+$//e
  252.     call setpos('.', save_cursor)
  253.     call setreg('/', old_query)
  254. endfun
  255.  
  256. if has("autocmd")
  257.     autocmd BufWritePre *.txt,*.js,*.py,*.wiki,*.sh,*.coffee :call CleanExtraSpaces()
  258. endif
  259.  
  260. " -------------------------------------------------------------
  261. " SPELLI CHECKING RELATED
  262. " -------------------------------------------------------------
  263.  
  264. " Pressing ,ss will toggle and untoggle spell checking
  265. map <leader>ss :setlocal spell!<cr>
  266.  
  267. " Shortcuts using <leader>
  268. map <leader>sn ]s
  269. map <leader>sp [s
  270. map <leader>sa zg
  271. map <leader>s? z=
  272.  
  273. " -------------------------------------------------------------
  274. " MISCELANEOUS
  275. "-------------------------------------------------------------
  276.  
  277. " Remove the Windows ^M - when the encodings gets messed up
  278. noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
  279.  
  280. " Quickly open a buffer for scribble
  281. map <leader>q :e ~/buffer<cr>
  282.  
  283. " Quickly open a markdown buffer for scribble
  284. map <leader>x :e ~/buffer.md<cr>
  285.  
  286. " Toggle paste mode on and off
  287. map <leader>pp :setlocal paste!<cr>
  288.  
  289. " -------------------------------------------------------------
  290. " HELPER FUNCTIONS  
  291. " -------------------------------------------------------------
  292.  
  293. " Returns true if paste mode is enabled
  294. function! HasPaste()
  295.     if &paste
  296.         return 'PASTE MODE  '
  297.     endif
  298.     return ''
  299. endfunction
  300.  
  301. " Don't close window, when deleting a buffer
  302. command! Bclose call <SID>BufcloseCloseIt()
  303. function! <SID>BufcloseCloseIt()
  304.     let l:currentBufNum = bufnr("%")
  305.     let l:alternateBufNum = bufnr("#")
  306.  
  307.     if buflisted(l:alternateBufNum)
  308.         buffer #
  309.     else
  310.         bnext
  311.     endif
  312.  
  313.     if bufnr("%") == l:currentBufNum
  314.         new
  315.     endif
  316.  
  317.     if buflisted(l:currentBufNum)
  318.         execute("bdelete! ".l:currentBufNum)
  319.     endif
  320. endfunction
  321.  
  322. function! CmdLine(str)
  323.     call feedkeys(":" . a:str)
  324. endfunction
  325.  
  326. function! VisualSelection(direction, extra_filter) range
  327.     let l:saved_reg = @"
  328.     execute "normal! vgvy"
  329.  
  330.     let l:pattern = escape(@", "\\/.*'$^~[]")
  331.    let l:pattern = substitute(l:pattern, "\n$", "", "")
  332.  
  333.    if a:direction == 'gv'
  334.        call CmdLine("Ack '" . l:pattern . "' " )
  335.    elseif a:direction == 'replace'
  336.        call CmdLine("%s" . '/'. l:pattern . '/')
  337.    endif
  338.  
  339.    let @/ = l:pattern
  340.    let @" = l:saved_reg
  341. endfunction
  342.  
Add Comment
Please, Sign In to add comment