Advertisement
nubilfi

vim-as-an-ide-part-2

Nov 2nd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 18.25 KB | None | 0 0
  1. " BASIC SETUP:
  2. " the <leader> is (comma)
  3. " ***************************************************************************
  4. " to be able to use VIM key combos not only in the shell but also in the Python interpreter
  5. " and any other tool that uses GNU Readline, add the following line to ~/.inputrc
  6. " set editing-mode vi
  7. " ***************************************************************************
  8.  
  9. set autoread                                                                " Set to auto read when a file is changed from the outside
  10. set backspace=indent,eol,start                                              " more powerful backspacing
  11. set clipboard=unnamed                                                       " access your system clipboard
  12. set cmdheight=2                                                             " Height of the command bar
  13. syntax enable                                                               " enable syntax highlighting and plugin (for netrw)
  14. set encoding=utf8                                                           " Set utf8 as standard encoding and en_US as the standard language
  15. set expandtab                                                               " convert tabs into spaces
  16. set ffs=unix,dos,mac                                                        " Use Unix as the standard file type
  17. set foldmethod=indent                                                       " Code folding
  18. set foldlevel=99
  19. set history=500                                                             " Sets how many lines of history VIM has to remember
  20. set incsearch                                                               " incremental search
  21. set laststatus=2                                                            " Always show the status line
  22. set list                                                                    " Show trailing white space
  23. set listchars=tab:>·,trail:~,extends:>,precedes:<,space:.                   " eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:.
  24. set mouse=nicr
  25. set magic                                                                   " For regular expressions turn magic on
  26. set nocompatible                                                            " enter the current millenium
  27. set number                                                                  " always show line numbers
  28. set hidden
  29. set ruler                                                                   " Always show current position
  30. set scrolloff=3                                                             " when scrolling, keep cursor 3 lines away from screen border
  31. set shiftwidth=2                                                            " amount of block indenting
  32. set smarttab                                                                " uses the shiftwidth instead of tabstop to delete indented line
  33. set synmaxcol=200                                                           " performance ???
  34. set tabstop=2                                                               " press tab, 2 spaces forward, 1 tab == 2 spaces
  35. set wrap                                                                    " Wrap lines
  36.  
  37. " PLUGINS
  38. " ************************************************************************
  39. " set the runtime path to include VUndle and initialize
  40. set rtp+=~/.vim/bundle/Vundle.vim
  41. call vundle#begin()
  42.  
  43. " let Vundle manage Vundle, required
  44. Plugin 'VundleVim/Vundle.vim'
  45.  
  46. " Brief help
  47. " :PluginList       - lists configured plugins
  48. " :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
  49. " :PluginSearch foo - searches for foo; append `!` to refresh local cache
  50. " :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
  51.  
  52. Plugin 'flazz/vim-colorschemes'
  53. Plugin 'elzr/vim-json'
  54. Plugin 'plasticboy/vim-markdown'
  55. Plugin 'severin-lemaignan/vim-minimap'
  56. Plugin 'airblade/vim-gitgutter'
  57.  
  58. " Icon files
  59. Plugin 'tiagofumo/vim-nerdtree-syntax-highlight'
  60. Plugin 'ryanoasis/vim-devicons'
  61. " Airline
  62. Plugin 'vim-airline/vim-airline'
  63. Plugin 'vim-airline/vim-airline-themes'
  64.  
  65. Plugin 'neoclide/coc.nvim'                                                  " Intellisense engine
  66. Plugin 'scrooloose/nerdtree'                                                " Better file browser
  67. Plugin 'scrooloose/nerdcommenter'                                           " Code commenter
  68. Plugin 'majutsushi/tagbar'                                                  " Class/module browser
  69. Plugin 'ctrlpvim/ctrlp.vim'                                                 " Code and files fuzzy finder
  70. Plugin 'mattn/emmet-vim'                                                    " Zen coding, use emmet
  71. Plugin 'kien/tabman.vim'                                                    " Tab list panel
  72. Plugin 'Townk/vim-autoclose'                                                " Autoclose chars
  73. Plugin 'fisadev/dragvisuals.vim'                                            " Drag visual blocks arround (it is like Ctrl+d arrow up/down on sublime)
  74. Plugin 't9md/vim-choosewin'                                                 " Land on window like tmux's 'display-pane'
  75. Plugin 'tpope/vim-fugitive'                                                 " Git integration
  76. Plugin 'google/vim-searchindex'                                             " display number of search matches & index of a current match
  77. Plugin 'ap/vim-css-color'                                                   " Paint css colors with the real color
  78. Plugin 'tpope/vim-surround'                                                 " Surround
  79. Plugin 'vim-scripts/matchit.zip'                                            " XML/HTML tags navigation
  80. Plugin 'vim-scripts/YankRing.vim'                                           " Yank history navigation
  81. Plugin 'pangloss/vim-javascript'                                            " Javascript indentation and syntax support
  82. Plugin 'w0rp/ale'                                                           " Check syntax in Vim asynchronously and fix files
  83. Plugin 'MaxMEllon/vim-jsx-pretty'                                           " JSX syntax pretty highlighting
  84. Plugin 'styled-components/vim-styled-components'
  85.  
  86. " theme plugins
  87. Plugin 'nightsense/office'
  88. Plugin 'fatih/molokai'
  89. Plugin 'nightsense/cosmic_latte'
  90. Plugin 'ErichDonGubler/vim-sublime-monokai'
  91. Plugin 'Nequo/vim-allomancer'
  92.  
  93. " All of your Plugins must be added before the following line
  94. call vundle#end()                                                           " required
  95. filetype plugin indent on              " required
  96.  
  97. " OTHER BASIC SETUP (TWEAKS)
  98. " ***************************************************************************
  99. let mapleader = ","
  100. let maplocalleader = ","
  101. set termguicolors
  102. nnoremap <leader>N :setlocal number!<cr>            " Toggle line numbers
  103.  
  104. " 1 comma+s to save
  105. " 2 comma+q to quit (does not save, watch out!)
  106. " 3 quit all without saving
  107. nnoremap <leader>ss :w<cr>
  108. nnoremap <leader>q :q!<cr>
  109. nnoremap <leader>qa :qa!<cr>
  110.  
  111. let $MYVIMRC="/home/you_username/.vimrc"
  112. " Reload vimrc
  113. nnoremap <leader>rv :source<Space>$MYVIMRC<cr>
  114. " Edit vimrc
  115. nnoremap <leader>ev :tabnew $MYVIMRC<cr>
  116.  
  117. " Copy & paste to clipboard
  118. noremap <Leader>Y "+y
  119. noremap <Leader>P "+p
  120.  
  121. " change Escape key behaviour
  122. " :imap ii <Esc>
  123. imap <leader>q <Esc>
  124. inoremap jj <Esc>
  125.  
  126. " Enable folding with the z
  127. nnoremap <leader> z
  128.  
  129. " Buffer key mappings
  130. nnoremap <leader>l :bn<cr>
  131. nnoremap <leader>h :bp<cr>
  132. nnoremap <leader>0 :bf<cr>
  133. nnoremap <leader>9 :bl<cr>
  134. nnoremap <leader>dd :bd<cr>
  135.  
  136. " Managing tabs
  137. nnoremap tn :tabnew<Space>
  138. nnoremap tk :tabnext<CR>
  139. nnoremap tj :tabprev<CR>
  140. nnoremap th :tabfirst<CR>
  141. nnoremap tl :tablast<CR>
  142. nnoremap tc :tabclose<CR>
  143.  
  144. " :W sudo saves the file
  145. " (useful for handling the permission-denied error)
  146. command W w !sudo tee % > /dev/null
  147.  
  148. " navigate split screens easily
  149. nmap <silent> <c-k> :wincmd k<CR>
  150. nmap <silent> <c-j> :wincmd j<CR>
  151. nmap <silent> <c-h> :wincmd h<CR>
  152. nmap <silent> <c-l> :wincmd l<CR>
  153.  
  154. " Stay in visual mode when indenting. You will never have to run gv after
  155. " performing an indentation.
  156. " Pressing Shift-< or Shift-> will let you indent/unident selected lines,
  157. " allow it to occur multiple times in visual mode
  158. vnoremap < <gv
  159. vnoremap > >gv
  160.  
  161. " Commenting
  162. " comma-1 insert "!" commenting
  163. nnoremap <leader>1 :norm i!<cr>
  164. vnoremap <leader>1 :norm i!<cr>
  165.  
  166. " comma-' insert """ commenting
  167. nnoremap <leader>' :norm i"<cr>
  168. vnoremap <leader>' :norm i"<cr>
  169.  
  170. " comma-3 insert "#" commenting
  171. nnoremap <leader>3 :norm i#<cr>
  172. vnoremap <leader>3 :norm i#<cr>
  173.  
  174. " comma-- insert "--" commenting
  175. nnoremap <leader>- :norm i--<cr>
  176. vnoremap <leader>- :norm i--<cr>
  177.  
  178. " comma-6 uncomment
  179. nnoremap <leader>6 :norm ^x<cr>
  180. vnoremap <leader>6 :norm ^x<cr>
  181.  
  182. " Ignore compiled files
  183. set wildignore=*.o,*~,*.pyc
  184. if has("win16") || has("win32")
  185.     set wildignore+=.git\*,.hg\*,.svn\*
  186. else
  187.     set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
  188. endif
  189.  
  190. " Make Y yank everything from the cursor to the end of the line. This makes Y
  191. " act more like C or D because by default, Y yanks the current line (i.e. the
  192. " same as yy).
  193. noremap Y y$
  194.  
  195. " autocompletion of files and commands behaves like shell
  196. " (complete only the common part, list the options that match)
  197. set wildmode=list:longest
  198.  
  199. " FINDING FILES: **********************************************************
  200. " search down into subfolders
  201. " provides tab-completion for all file-related tasks
  202. " set path+=**
  203.  
  204. " display all matching files when we tab complete
  205. " set wildmenu
  206. " set wildmode=list:longest,full
  207. " set lazyredraw
  208.  
  209. " NOW WE CAN:
  210. " - hit tab to :find by partial match
  211. " - use * to make it fuzzy
  212. " THINGS TO CONSIDER:
  213. " - :b lets you autocomplete any open buffer
  214. " END FINDING FILES: **********************************************************
  215.  
  216. " FILE BROWSING: *********************************************************
  217. " tweaks for browsing
  218. " let g:netrw_banner=0                                    " disable annoying banner
  219. " let g:netrw_browse_split=4                              " open in prior window
  220. " let g:netrw_altv=1                                      " open splits to the right
  221. " let g:netrw_liststyle=3                                 " tree view
  222. " let g:netrw_list_hide=netrw_gitignore#Hide()
  223. " let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+'
  224.  
  225. " NOW WE CAN:
  226. " - :edit a folder to open a file browser
  227. " - <CR>/v/t to open in an h-split/v-split/tab
  228. " - check |netrw-browse-maps| for more mappings
  229. " END FILE BROWSING: *********************************************************
  230.  
  231. " Enable 256 colors palette in Gnome Terminal
  232. if $COLORTERM == 'gnome-terminal'
  233.     set t_Co=256
  234. endif
  235.  
  236. try
  237.     " Choose colorscheme
  238.     " *********************************************
  239.     if strftime('%H') >= 7 && strftime('%H') < 20
  240.         colorscheme sublimemonokai
  241.     else
  242.         " colorscheme office-dark
  243.         colorscheme allomancer
  244.         let g:airline_theme='cosmic_latte_dark'
  245.     endif
  246. catch
  247. endtry
  248.  
  249. set background=dark
  250.  
  251. " Set extra options when running in GUI mode
  252. if has("gui_running")
  253.     set guioptions-=T
  254.     set guioptions-=e
  255.     set t_Co=256
  256.     set guitablabel=%M\ %t
  257.     set cursorcolumn!
  258.  
  259.     " Set up the gui cursor to look nice
  260.     set guicursor=n-v-c:block-Cursor-blinkon0
  261.     set guicursor+=ve:ver35-Cursor
  262.     set guicursor+=o:hor50-Cursor
  263.     set guicursor+=i-ci:ver25-Cursor
  264.     set guicursor+=r-cr:hor20-Cursor
  265.     set guicursor+=sm:block-Cursor-blinkwait175-blinkoff150-blinkon175
  266. endif
  267.  
  268. " better backup, swap and undos storage
  269. set directory=~/.vim/dirs/tmp     " directory to place swap files in
  270. set backup                        " make backup files
  271. set backupdir=~/.vim/dirs/backups " where to put backup files
  272. set undofile                      " persistent undos - undo after you re-open the file
  273. set undodir=~/.vim/dirs/undos
  274. set viminfo+=n~/.vim/dirs/viminfo
  275. " store yankring history file there too
  276. let g:yankring_history_dir = '~/.vim/dirs/'
  277.  
  278. " create needed directories if they don't exist
  279. if !isdirectory(&backupdir)
  280.     call mkdir(&backupdir, "p")
  281. endif
  282. if !isdirectory(&directory)
  283.     call mkdir(&directory, "p")
  284. endif
  285. if !isdirectory(&undodir)
  286.     call mkdir(&undodir, "p")
  287. endif
  288.  
  289. " PLUGINS SETUP
  290. " ********************************************************************************
  291.  
  292. " NERDTree -----------------------------
  293. map <C-b> :NERDTreeToggle<CR>
  294. let g:NERDTreeDirArrowExpandable = '▸'" Prettier
  295. " open nerdtree with the current file selected
  296. nmap <leader>t :NERDTreeFind<CR>
  297. let g:NERDTreeDirArrowCollapsible = '▾'
  298. let g:NERDTreeMouseMode = 3
  299. let NERDTreeShowLineNumbers = 1
  300. let NERDTreeShowHidden = 1
  301. let NERDTreeMinimalUI = 1
  302. let NERDTreeIgnore=['\.pyc$', '\~$']         "ignore files in NERDTree
  303. "autocmd BufWinEnter * call timer_start(50, { tid -> execute('NERDTreeMirror')})    " open the new tab in NERDTree's buffer
  304.  
  305. " Tagbar -----------------------------
  306. " toggle tagbar display
  307. map <F4> :TagbarToggle<CR>
  308. " autofocus on tagbar open
  309. let g:tagbar_autofocus = 1
  310.  
  311. " Airline -----------------------------
  312. let g:airline_powerline_fonts = 1
  313. let g:airline_theme = 'distinguished'
  314. let g:airline#extensions#ale#enabled = 1
  315. let g:airline#extensions#tabline#enabled = 1
  316. let g:airline#extensions#whitespace#enabled = 0
  317. let g:Powerline_symbols = "fancy"
  318. let g:Powerline_dividers_override = ["\Ue0b0","\Ue0b1","\Ue0b2","\Ue0b3"]
  319. let g:Powerline_symbols_override = {'BRANCH': "\Ue0a0", 'LINE': "\Ue0a1", 'RO': "\Ue0a2"}
  320.  
  321. " to use fancy symbols for airline
  322. if !exists('g:airline_symbols')
  323.    let g:airline_symbols = {}
  324. endif
  325.  
  326. " Airline unicode symbols
  327. let g:airline_left_sep = '»'
  328. let g:airline_right_sep = '«'
  329. let g:airline_left_alt_sep = ''
  330. let g:airline_right_alt_sep = ''
  331.  
  332. let g:airline_symbols.branch = ''
  333. let g:airline_symbols.readonly = ''
  334. let g:airline_symbols.linenr = ''
  335. let g:airline_symbols.paste = 'ρ'
  336. let g:airline_symbols.whitespace = 'Ξ'
  337.  
  338. " vim-minimap -----------------------------
  339. let g:minimap_highlight='Visual'
  340. let g:minimap_show='<leader>ms'
  341. let g:minimap_update='<leader>mu'
  342. let g:minimap_close='<leader>gc'
  343. let g:minimap_toggle='<leader>gt'
  344.  
  345. " CtrlP -----------------------------
  346. " file finder mapping
  347. let g:ctrlp_map = '<leader>ee'
  348. " tags (symbols) in current file finder mapping
  349. nmap <leader>g :CtrlPBufTag<CR>
  350. " tags (symbols) in all files finder mapping
  351. nmap <leader>G :CtrlPBufTagAll<CR>
  352. " general code finder in all files mapping
  353. nmap <leader>f :CtrlPLine<CR>
  354. " recent files finder mapping
  355. nmap <leader>m :CtrlPMRUFiles<CR>
  356. " commands finder mapping
  357. nmap <leader>c :CtrlPCmdPalette<CR>
  358. " to be able to call CtrlP with default search text
  359. function! CtrlPWithSearchText(search_text, ctrlp_command_end)
  360.    execute ':CtrlP' . a:ctrlp_command_end
  361.    call feedkeys(a:search_text)
  362. endfunction
  363. " same as previous mappings, but calling with current word as default text
  364. nmap <leader>wg :call CtrlPWithSearchText(expand('<cword>'), 'BufTag')<CR>
  365. nmap <leader>wG :call CtrlPWithSearchText(expand('<cword>'), 'BufTagAll')<CR>
  366. nmap <leader>wf :call CtrlPWithSearchText(expand('<cword>'), 'Line')<CR>
  367. nmap <leader>we :call CtrlPWithSearchText(expand('<cword>'), '')<CR>
  368. nmap <leader>pe :call CtrlPWithSearchText(expand('<cfile>'), '')<CR>
  369. nmap <leader>wm :call CtrlPWithSearchText(expand('<cword>'), 'MRUFiles')<CR>
  370. nmap <leader>wc :call CtrlPWithSearchText(expand('<cword>'), 'CmdPalette')<CR>
  371. " don't change working directory
  372. let g:ctrlp_working_path_mode = 0
  373. " ignore these files and folders on file finder
  374. let g:ctrlp_custom_ignore = {
  375.             \ 'dir':  '\v[\/](\.git|\.hg|\.svn|node_modules|vendor)$',
  376.             \ 'file': '\.pyc$\|\.pyo$\|\.sh$\|\.so$',
  377.             \ }
  378.  
  379. " vim emmet trigger key, prest ctrl + e + comma -----------------------------
  380. let g:user_emmet_leader_key='<C-E>'
  381.  
  382. " TabMan ------------------------------
  383. " mappings to toggle display, and to focus on it
  384. let g:tabman_toggle = 'tl'
  385. let g:tabman_focus  = 'tf'
  386.  
  387. " Autoclose ------------------------------
  388. " Fix to let ESC work as espected with Autoclose plugin
  389. let g:AutoClosePumvisible = {"ENTER": "\<C-Y>", "ESC": "\<ESC>"}
  390.  
  391. " DragVisuals ------------------------------
  392. " mappings to move blocks in 4 directions
  393. vmap <expr> <S-M-LEFT> DVB_Drag('left')
  394. vmap <expr> <S-M-RIGHT> DVB_Drag('right')
  395. vmap <expr> <S-M-DOWN> DVB_Drag('down')
  396. vmap <expr> <S-M-UP> DVB_Drag('up')
  397. " mapping to duplicate block
  398. vmap <expr> D DVB_Duplicate()
  399.  
  400. " choosewin  ------------------------------
  401. " mapping
  402. nmap  -  <Plug>(choosewin)
  403. " show big letters
  404. let g:choosewin_overlay_enable = 1
  405.  
  406. " vim-javascript --------------------------
  407. " set conceallevel=1
  408. map <leader>co :exec &conceallevel ? "set conceallevel=0" : "set conceallevel=1"<CR>
  409. let g:javascript_conceal_function             = "ƒ"
  410. let g:javascript_conceal_null                 = "ø"
  411. let g:javascript_conceal_this                 = "@"
  412. let g:javascript_conceal_return               = "⇚"
  413. let g:javascript_conceal_undefined            = "¿"
  414. let g:javascript_conceal_NaN                  = "ℕ"
  415. let g:javascript_conceal_prototype            = "¶"
  416. let g:javascript_conceal_static               = "•"
  417. let g:javascript_conceal_super                = "Ω"
  418. let g:javascript_conceal_arrow_function       = "⇒"
  419. let g:javascript_conceal_noarg_arrow_function = "🞅"
  420. let g:javascript_conceal_underscore_arrow_function = "🞅"
  421.  
  422. " ALE (eslint)  -------------------------
  423. map <C-t> :ALEDetail<CR>
  424. let g:ale_fix_on_save = 1
  425. let g:ale_sign_error = '✗'
  426. let g:ale_sign_warning = '⚠'
  427. let g:ale_open_list = 1
  428. let g:ale_set_loclist = 0
  429. let g:ale_lint_on_enter = 0
  430. let g:ale_set_quickfix = 1
  431. let g:ale_keep_list_window_open = 0
  432. let g:ale_lint_delay = 960000                 " 16 minutes
  433. let g:ale_lint_on_text_changed= "never"
  434. let g:ale_list_window_size = 5                " Show 5 lines of errors (default: 10)
  435. nmap <silent> <Leader>k <Plug>(ale_previous_wrap)
  436. nmap <silent> <Leader>j <Plug>(ale_next_wrap)
  437. let g:ale_linters = {
  438.   \  'sh': ['shell'],
  439.   \  'javascript': ['eslint'],
  440.   \}
  441. let g:ale_fixers = {
  442.   \  'sh': ['shfmt'],
  443.   \  'javascript': ['prettier', 'eslint'],
  444.   \  'json': ['prettier'],
  445.   \  'markdown': ['prettier'],
  446.   \  'yaml': ['prettier'],
  447.   \  'css': ['prettier'],
  448.   \}
  449.  
  450. " vim jsx pretty -----------------------
  451. let g:vim_jsx_pretty_colorful_config = 1
  452.  
  453. let g:coc_node_path = '/home/you_username/.nvm/versions/node/v12.13.0/bin/node'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement