Advertisement
strict-flower

init.vim

Mar 3rd, 2019
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 1.72 KB | None | 0 0
  1. set number
  2. syntax on
  3. set autoindent
  4. set smartindent
  5. set mouse=a
  6. set background=dark
  7.  
  8. set noswapfile
  9. set noundofile
  10. set nobackup
  11.  
  12. nnoremap <silent> > :call Indent()<CR>
  13. nnoremap <silent> < :call UnIndent()<CR>
  14.  
  15. let g:indent = 2
  16. let g:tabchar = " "
  17.  
  18. colorscheme hybrid
  19.  
  20. augroup mygroup
  21.   autocmd!
  22.   autocmd BufWritePre * call DeleteBlanklineIndent()
  23. augroup END
  24.  
  25. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  26. "  setup / factory functions                                                             "
  27. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  28.  
  29. let &shiftwidth=g:indent
  30. let &softtabstop=g:indent
  31. let &tabstop=g:indent
  32.  
  33. if g:tabchar == " "
  34.   set expandtab
  35. endif
  36.  
  37. function! GenIndent()
  38.   call assert_equal(strlen(g:tabchar), 1)
  39.   let res = ""
  40.   let i = 0
  41.   while i < g:indent
  42.     let res = res . g:tabchar
  43.     let i = i + 1
  44.   endwhile
  45.   return res
  46. endfunction
  47.  
  48. function! Indent()
  49.   let indent_str = GenIndent()
  50.   let cur_line_no = line(".")
  51.   let cur_line = getline(cur_line_no)
  52.   call setline(cur_line_no, indent_str . cur_line)
  53. endfunction
  54.  
  55. function! UnIndent()
  56.   let cur_line_no = line(".")
  57.   let cur_line = getline(cur_line_no)
  58. let start_str = cur_line[0:(g:indent - 1)]
  59.   let i = 0
  60.   while i < g:indent
  61.     if start_str[0] =~ '\s'
  62.       let start_str = start_str[1:]
  63.     endif
  64.     let i = i + 1
  65.   endwhile
  66. call setline(cur_line_no, start_str . cur_line[(g:indent):])
  67. endfunction
  68.  
  69. function! DeleteBlanklineIndent()
  70.   let lastlineno = line("$")
  71.   let i = 0
  72.   while i < lastlineno
  73.     let i = i + 1
  74.     if getline(i) =~ "^\\s\\+$"
  75.       call setline(i, "")
  76.     endif
  77.   endwhile
  78. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement