nubilfi

vim-as-an-ide-part-1

Nov 2nd, 2019
7
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. " BASIC SETUP:
  2. " the <leader> is (comma)
  3. " ***************************************************************************
  4.  
  5. set autoread                                                                " Set to auto read when a file is changed from the outside
  6. set backspace=indent,eol,start                                              " more powerful backspacing
  7. set clipboard=unnamed                                                       " access your system clipboard
  8. set cmdheight=2                                                             " Height of the command bar
  9. syntax enable                                                               " enable syntax highlighting and plugin (for netrw)
  10. set encoding=utf8                                                           " Set utf8 as standard encoding and en_US as the standard language
  11. set expandtab                                                               " convert tabs into spaces
  12. set ffs=unix,dos,mac                                                        " Use Unix as the standard file type
  13. set foldmethod=indent                                                       " Code folding
  14. set foldlevel=99
  15. set history=500                                                             " Sets how many lines of history VIM has to remember
  16. set incsearch                                                               " incremental search
  17. set laststatus=2                                                            " Always show the status line
  18. set list                                                                    " Show trailing white space
  19. set listchars=tab:>·,trail:~,extends:>,precedes:<,space:.                   " eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:.
  20. set mouse=nicr
  21. set magic                                                                   " For regular expressions turn magic on
  22. set nocompatible                                                            " enter the current millenium
  23. set number                                                                  " always show line numbers
  24. set hidden
  25. set ruler                                                                   " Always show current position
  26. set scrolloff=3                                                             " when scrolling, keep cursor 3 lines away from screen border
  27. set shiftwidth=2                                                            " amount of block indenting
  28. set smarttab                                                                " uses the shiftwidth instead of tabstop to delete indented line
  29. set synmaxcol=200                                                           " performance ???
  30. set tabstop=2                                                               " press tab, 2 spaces forward, 1 tab == 2 spaces
  31. set wrap                                                                    " Wrap lines
  32.  
  33. filetype plugin indent on              " required
  34.  
  35. " OTHER BASIC SETUP (TWEAKS)
  36. " ***************************************************************************
  37. let mapleader = ","
  38. let maplocalleader = ","
  39. set termguicolors
  40. nnoremap <leader>N :setlocal number!<cr>            " Toggle line numbers
  41.  
  42. " 1 comma+s to save
  43. " 2 comma+q to quit (does not save, watch out!)
  44. " 3 quit all without saving
  45. nnoremap <leader>ss :w<cr>
  46. nnoremap <leader>q :q!<cr>
  47. nnoremap <leader>qa :qa!<cr>
  48.  
  49. let $MYVIMRC="/home/you_username/.vimrc"
  50. " Reload vimrc
  51. nnoremap <leader>rv :source<Space>$MYVIMRC<cr>
  52. " Edit vimrc
  53. nnoremap <leader>ev :tabnew $MYVIMRC<cr>
  54.  
  55. " Copy & paste to clipboard
  56. noremap <Leader>Y "+y
  57. noremap <Leader>P "+p
  58.  
  59. " change Escape key behaviour
  60. " :imap ii <Esc>
  61. imap <leader>q <Esc>
  62. inoremap jj <Esc>
  63.  
  64. " Enable folding with the z
  65. nnoremap <leader> z
  66.  
  67. " Buffer key mappings
  68. nnoremap <leader>l :bn<cr>
  69. nnoremap <leader>h :bp<cr>
  70. nnoremap <leader>0 :bf<cr>
  71. nnoremap <leader>9 :bl<cr>
  72. nnoremap <leader>dd :bd<cr>
  73.  
  74. " Managing tabs
  75. nnoremap tn :tabnew<Space>
  76. nnoremap tk :tabnext<CR>
  77. nnoremap tj :tabprev<CR>
  78. nnoremap th :tabfirst<CR>
  79. nnoremap tl :tablast<CR>
  80. nnoremap tc :tabclose<CR>
  81.  
  82. " :W sudo saves the file
  83. " (useful for handling the permission-denied error)
  84. command W w !sudo tee % > /dev/null
  85.  
  86. " navigate split screens easily
  87. nmap <silent> <c-k> :wincmd k<CR>
  88. nmap <silent> <c-j> :wincmd j<CR>
  89. nmap <silent> <c-h> :wincmd h<CR>
  90. nmap <silent> <c-l> :wincmd l<CR>
  91.  
  92. " Stay in visual mode when indenting. You will never have to run gv after
  93. " performing an indentation.
  94. " Pressing Shift-< or Shift-> will let you indent/unident selected lines,
  95. " allow it to occur multiple times in visual mode
  96. vnoremap < <gv
  97. vnoremap > >gv
  98.  
  99. " Commenting
  100. " comma-1 insert "!" commenting
  101. nnoremap <leader>1 :norm i!<cr>
  102. vnoremap <leader>1 :norm i!<cr>
  103.  
  104. " comma-' insert """ commenting
  105. nnoremap <leader>' :norm i"<cr>
  106. vnoremap <leader>' :norm i"<cr>
  107.  
  108. " comma-3 insert "#" commenting
  109. nnoremap <leader>3 :norm i#<cr>
  110. vnoremap <leader>3 :norm i#<cr>
  111.  
  112. " comma-- insert "--" commenting
  113. nnoremap <leader>- :norm i--<cr>
  114. vnoremap <leader>- :norm i--<cr>
  115.  
  116. " comma-6 uncomment
  117. nnoremap <leader>6 :norm ^x<cr>
  118. vnoremap <leader>6 :norm ^x<cr>
  119.  
  120. " Ignore compiled files
  121. set wildignore=*.o,*~,*.pyc
  122. if has("win16") || has("win32")
  123.     set wildignore+=.git\*,.hg\*,.svn\*
  124. else
  125.     set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
  126. endif
  127.  
  128. " Make Y yank everything from the cursor to the end of the line. This makes Y
  129. " act more like C or D because by default, Y yanks the current line (i.e. the
  130. " same as yy).
  131. noremap Y y$
  132.  
  133. " autocompletion of files and commands behaves like shell
  134. " (complete only the common part, list the options that match)
  135. set wildmode=list:longest
  136.  
  137. " FINDING FILES: **********************************************************
  138. " search down into subfolders
  139. " provides tab-completion for all file-related tasks
  140. set path+=**
  141.  
  142. " display all matching files when we tab complete
  143.  set wildmenu
  144.  set wildmode=list:longest,full
  145.  set lazyredraw
  146.  
  147. " NOW WE CAN:
  148. " - hit tab to :find by partial match
  149. " - use * to make it fuzzy
  150. " THINGS TO CONSIDER:
  151. " - :b lets you autocomplete any open buffer
  152. " END FINDING FILES: **********************************************************
  153.  
  154. " FILE BROWSING: *********************************************************
  155. " tweaks for browsing
  156.  let g:netrw_banner=0                                    " disable annoying banner
  157.  let g:netrw_browse_split=4                              " open in prior window
  158.  let g:netrw_altv=1                                      " open splits to the right
  159.  let g:netrw_liststyle=3                                 " tree view
  160.  let g:netrw_list_hide=netrw_gitignore#Hide()
  161.  let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+'
  162.  
  163. " NOW WE CAN:
  164. " - :edit a folder to open a file browser
  165. " - <CR>/v/t to open in an h-split/v-split/tab
  166. " - check |netrw-browse-maps| for more mappings
  167. " END FILE BROWSING: *********************************************************
  168.  
  169. " Enable 256 colors palette in Gnome Terminal
  170. if $COLORTERM == 'gnome-terminal'
  171.     set t_Co=256
  172. endif
  173.  
  174. set background=dark
  175.  
  176. " Set extra options when running in GUI mode
  177. if has("gui_running")
  178.     set guioptions-=T
  179.     set guioptions-=e
  180.     set t_Co=256
  181.     set guitablabel=%M\ %t
  182.     set cursorcolumn!
  183.  
  184.     " Set up the gui cursor to look nice
  185.     set guicursor=n-v-c:block-Cursor-blinkon0
  186.     set guicursor+=ve:ver35-Cursor
  187.     set guicursor+=o:hor50-Cursor
  188.     set guicursor+=i-ci:ver25-Cursor
  189.     set guicursor+=r-cr:hor20-Cursor
  190.     set guicursor+=sm:block-Cursor-blinkwait175-blinkoff150-blinkon175
  191. endif
  192.  
  193. " better backup, swap and undos storage
  194. set directory=~/.vim/dirs/tmp     " directory to place swap files in
  195. set backup                        " make backup files
  196. set backupdir=~/.vim/dirs/backups " where to put backup files
  197. set undofile                      " persistent undos - undo after you re-open the file
  198. set undodir=~/.vim/dirs/undos
  199. set viminfo+=n~/.vim/dirs/viminfo
  200. " store yankring history file there too
  201. let g:yankring_history_dir = '~/.vim/dirs/'
  202.  
  203. " create needed directories if they don't exist
  204. if !isdirectory(&backupdir)
  205.     call mkdir(&backupdir, "p")
  206. endif
  207. if !isdirectory(&directory)
  208.     call mkdir(&directory, "p")
  209. endif
  210. if !isdirectory(&undodir)
  211.     call mkdir(&undodir, "p")
  212. endif
RAW Paste Data