Advertisement
Guest User

Untitled

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