├── .gitignore ├── README.md ├── coc-settings.json ├── ginit.vim └── init.vim /.gitignore: -------------------------------------------------------------------------------- 1 | autoload 2 | plugged 3 | tags.temp 4 | tags.lock 5 | tags 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Neovim Ruby 2 | 3 | ## Alert 4 | I've migrated to doom emacs: https://github.com/hlissner/doom-emacs Its like vim, but with steroids! 5 | 6 | ## About 7 | A complete IDE for Rails development with vim. Uses coc.nvim for auto-complete. 8 | 9 | https://github.com/neoclide/coc.nvim (Recommended to read) 10 | 11 | ## Demonstration 12 | ![demonstration](https://i.imgur.com/SLyoGwS.gif) 13 | 14 | obs: I just doing random stuff with a very old code that i found =D 15 | 16 | ## Video demonstration of some commands(pt_BR): 17 | https://youtu.be/3MYo9z0YsLg 18 | 19 | ## Dependencies 20 | - python3-neovim 21 | - fzf 22 | - silversearcher-ag 23 | - exuberant-ctags 24 | - yarn (Installed with nvm (https://github.com/creationix/nvm)) 25 | - xclip 26 | - Ruby (with rvm ou rbenv) 27 | - NerdFonts 28 | 29 | Tested on: 30 | - Solus 31 | - Ubuntu 32 | - Arch Linux 33 | - MacOS (Thanks Sérgio Maia) 34 | 35 | To Ubuntu \ Mint, run: 36 | 37 | sudo apt install python3-neovim python3-pip python3-setuptools exuberant-ctags silversearcher-ag; sudo pip3 install pynvim 38 | 39 | On Solus, run: 40 | sudo eopkg install neovim xclip ctags neovim silver-searcher python-neovim 41 | 42 | Install fzf: 43 | https://github.com/junegunn/fzf 44 | 45 | 46 | ``` 47 | git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf 48 | ~/.fzf/install 49 | ``` 50 | 51 | Install YARN: 52 | 53 | npm install -g yarn 54 | 55 | ### Nerd fonts for cool icons: 56 | 57 | #### Linux 58 | 59 | ```sh 60 | mkdir -p ~/.local/share/fonts 61 | cd ~/.local/share/fonts && curl -fLo "Droid Sans Mono for Powerline Nerd Font Complete.otf" https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/DroidSansMono/complete/Droid%20Sans%20Mono%20Nerd%20Font%20Complete.otf 62 | ``` 63 | 64 | _Note:_ deprecated alternative paths: `~/.fonts` 65 | 66 | #### macOS (OS X) 67 | 68 | ```sh 69 | cd ~/Library/Fonts && curl -fLo "Droid Sans Mono for Powerline Nerd Font Complete.otf" https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/DroidSansMono/complete/Droid%20Sans%20Mono%20Nerd%20Font%20Complete.otf 70 | ``` 71 | 72 | ## Installation 73 | 74 | 1 - Install Neovim 75 | 76 | 2 - Put the files on .config/nvim/ (git clone https://github.com/otavioschwanck/neovim_ruby.git ~/.config/nvim) 77 | 78 | 3 - Open neovim (nvim on terminal) 79 | 80 | 4 - Run `:PlugInstall` 81 | 82 | 5 - Exit from nvim (:q) 83 | 84 | 6 - open neovim again (nvim) and run: `:call coc#util#build()` 85 | 86 | 7 - Run it too: `:CocInstall coc-json coc-html coc-css coc-solargraph coc-snippets` 87 | 88 | 8 - create a .backups folder on home. (mkdir ~/.backups) 89 | 90 | ## Ruby Auto-complete 91 | 92 | Install Ruby with rvm or rbenv and install solargraph. 93 | 94 | `gem install solargraph rubocop neovim` 95 | 96 | Thats it! 97 | 98 | # Some commands 99 | | Command | Action | 100 | | --- | ---------- | 101 | | ctrl + e | Open Nerdtree | 102 | | ctrl + p | Find files in project | 103 | | , + shift + f | Find text on project. you can select more than one file using tab, and apply commands on all selected files with :cfdo [command_1] | [command_2] 104 | | , + b | List buffers | 105 | | , + p | Previous buffer | 106 | | , + n | Next buffer | 107 | | , + d | Close the buffer | 108 | | , + F | Search by text in entire project | 109 | | , + 1..9 | Change tab | 110 | | alt + 1..9 | Change tab (neovim-qt (sudo apt install neovim-qt)) | 111 | | , + if | JsFileImport | 112 | | , + iF | JsFileImportList | 113 | | , + ig | JsGotoDefinition | 114 | | , + iG | JsGotoDefinition | 115 | | , + ip | PromptJsFileImport | 116 | | , + is | SortJsFileImport | 117 | | , + ic | JsFixImport | 118 | | F4 | Toggle Terminal | 119 | | F5 | Exit Terminal Mode | 120 | | , + shift + B | Run the current file | 121 | | ctrl + ] | Go to definition of Class \ Method on cursor | 122 | | } | Go to next blank line (Cool for navigation) | 123 | | { | Go to previous blank line (Cool for navigation) | 124 | 125 | # Git Epic Commands 126 | | Command | Action | 127 | | --- | -----------| 128 | | , + gs | Show de status | 129 | | , + gd | Show de Git Diff of current File (cool to use with ,gs) | 130 | | , + gb | Open your repository site | 131 | | , + ga | git add . on your project directory | 132 | | , + gc | git commit | 133 | | , + gg | git log, use [q and ]q to navigate in file history | 134 | | , + ge | Leave the git log (Gedit) | 135 | | , + gh | Git checkout | 136 | | , + gg | git pull | 137 | | , + gm | git checkout master | 138 | | , + gwd | Git diff on entire project | 139 | 140 | TIP: For Git Push, git pull, etc, use `, + shift + d` to close the buffer faster. (:bd! equivalent) 141 | 142 | # Ruby \ Rails Epic Commands 143 | | Commands | Action | 144 | | --- | ------------| 145 | | , rt | Alternate from File to Test | 146 | | , rm | Find the model of current resource | 147 | | , rc | Find controller of curent resource | 148 | | , rv | Find view of current resource (must be on Action in controller) 149 | | , rwt | Alternate from File to Test but using vsplit | 150 | | , rwm | Find the model of current resource but using vsplit | 151 | | , rwc | Find controller of curent resource but using vsplit | 152 | | , rwv | Find view of current resource (must be on Action in controller) but using vsplit | 153 | | , ru | Run :Rubocop on project | 154 | | , rwu | Run :Rubocop -a on project | 155 | | ]m | Navigate to next method definition | 156 | | [m | Navigate to prevous method definition | 157 | 158 | # Running Tests like a boss 159 | | Commands | Action | 160 | | --- | ------------| 161 | | , tn | Test nearest spec on cursor | 162 | | , tf | Test current opened file | 163 | | , ta | Run Tests on entire project | 164 | | , tl | Run Last Test | 165 | 166 | Super TIP: If you want to scroll in your test output, you need to do it on normal mode. Press F5 to exit insert mode, and navigate normaly. You close terminal, just use `, + shift + D` 167 | 168 | # Copy and Paste with system clipboard (requires xclip) 169 | | Commands | Action | 170 | | --- | ------------| 171 | | \y | y integrated with system clipboard, do \yy to yank line, or \yw to yank a word, etc... | 172 | | \p | same as \y but for paste | 173 | 174 | # Miscellaneous 175 | 176 | | Commands | Action | 177 | | --- | ------------| 178 | | :MarkdownPreview | Open current file in browser with markdown preview. It's async! | 179 | 180 | You can uncomment the line with `set clipboard=unnamedplus` to make yank always synced with system, but i not recommend (Is really boring when you copy something from outside and use a dd and lost it.) 181 | 182 | # Recomended material to study: 183 | 184 | - https://github.com/tpope/vim-surround - Super cool when masterized. 185 | - https://github.com/terryma/vim-multiple-cursors - Nice for multiple cursors 186 | - https://github.com/junegunn/fzf.vim - Learning more about fzf 187 | 188 | # Want to learn basics of vim? 189 | 190 | I really recommend this udemy course: https://www.udemy.com/vim-commands-cheat-sheet/ 191 | 192 | Very great course! 193 | 194 | # Troubleshoot 195 | 196 | Run :checkhealth to find some errors. 197 | 198 | # Autocomplete doesn't work 199 | 200 | Go to ~/.config/nvim/plugged/coc.nvim and run yarn. 201 | -------------------------------------------------------------------------------- /coc-settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "suggest.noselect": false, 3 | "suggest.preferCompleteThanJumpPlaceholder": true 4 | } 5 | -------------------------------------------------------------------------------- /ginit.vim: -------------------------------------------------------------------------------- 1 | Guifont Menlo:h13 2 | -------------------------------------------------------------------------------- /init.vim: -------------------------------------------------------------------------------- 1 | if empty(glob('~/.config/nvim/autoload/plug.vim')) 2 | silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs 3 | \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim 4 | autocmd VimEnter * PlugInstall 5 | endif 6 | 7 | call plug#begin() 8 | " Coc <3 9 | Plug 'neoclide/coc.nvim', {'do': { -> coc#util#install()}} 10 | 11 | " JS 12 | Plug 'kristijanhusak/vim-js-file-import', {'do': 'npm install'} 13 | 14 | " Airline for the tabs 15 | Plug 'vim-airline/vim-airline' 16 | Plug 'vim-airline/vim-airline-themes' 17 | Plug 'honza/vim-snippets' 18 | 19 | " Syntax Check 20 | Plug 'vim-syntastic/syntastic' 21 | 22 | " Markdown Support 23 | Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' } 24 | 25 | " Ctags 26 | Plug 'ludovicchabant/vim-gutentags' 27 | 28 | " Unpaired 29 | Plug 'tpope/vim-unimpaired' 30 | 31 | " One dark theme 32 | Plug 'joshdick/onedark.vim' 33 | 34 | " Comments 35 | Plug 'tomtom/tcomment_vim' 36 | 37 | " Best plugin ever 38 | Plug 'tpope/vim-surround' 39 | 40 | " Every one should have a pair (Autogenerate pairs for "{[( ) 41 | Plug 'jiangmiao/auto-pairs' 42 | 43 | " Navigation tree 44 | Plug 'scrooloose/nerdtree' 45 | Plug 'Xuyuanp/nerdtree-git-plugin' 46 | 47 | " Git Diff 48 | Plug 'airblade/vim-gitgutter' 49 | 50 | " Vim Fugitive 51 | Plug 'tpope/vim-fugitive' 52 | 53 | " Vim Gitlabs 54 | Plug 'shumphrey/fugitive-gitlab.vim' 55 | 56 | " Multple cursors is hot 57 | Plug 'terryma/vim-multiple-cursors' 58 | 59 | """ FZF 60 | Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } 61 | Plug '~/.fzf' 62 | Plug 'junegunn/fzf.vim' 63 | 64 | " CoolIcons 65 | Plug 'ryanoasis/vim-devicons' 66 | 67 | " Ruby 68 | Plug 'tpope/vim-rails' 69 | Plug 'vim-ruby/vim-ruby' 70 | Plug 'ngmy/vim-rubocop' 71 | " Plug 'thoughtbot/vim-rspec' 72 | Plug 'janko-m/vim-test' 73 | 74 | " Run code with ,r 75 | Plug 'xianzhon/vim-code-runner' 76 | 77 | " Vim end-wise 78 | Plug 'tpope/vim-endwise' 79 | 80 | call plug#end() 81 | 82 | " Indent Stuff 83 | 84 | inoremap 85 | \ pumvisible() ? coc#_select_confirm() : 86 | \ coc#expandableOrJumpable() ? coc#rpc#request('doKeymap', ['snippets-expand-jump','']) : 87 | \ check_back_space() ? "\" : 88 | \ coc#refresh() 89 | 90 | function! s:check_back_space() abort 91 | let col = col('.') - 1 92 | return !col || getline('.')[col - 1] =~# '\s' 93 | endfunction 94 | 95 | let g:coc_snippet_next = '' 96 | 97 | """ Ruby Stuff 98 | syntax on " Enable syntax highlighting 99 | filetype plugin indent on " Enable filetype-specific indenting and plugins 100 | 101 | augroup myfiletypes 102 | " Clear old autocmds in group 103 | autocmd! 104 | " autoindent with two spaces, always expand tabs 105 | autocmd FileType ruby,eruby,yaml,markdown set ai sw=2 sts=2 et 106 | augroup END 107 | 108 | " Syntax highlighting and theme 109 | syntax enable 110 | 111 | " Show trailing whitespace and spaces before a tab: 112 | :highlight ExtraWhitespace ctermbg=red guibg=red 113 | :autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\\t/ 114 | 115 | set ignorecase 116 | 117 | nnoremap :NERDTreeToggle 118 | 119 | " Airline 120 | let g:airline#extensions#tabline#enabled = 1 121 | let g:airline_theme='onedark' 122 | let g:airline#extensions#tabline#tab_nr_type = 1 123 | let g:airline#extensions#tabline#formatter = 'default' 124 | let g:airline#extensions#tabline#fnametruncate = 16 125 | let g:airline#extensions#tabline#fnamecollapse = 2 126 | let g:airline#extensions#tabline#buffer_idx_mode = 1 127 | 128 | " Personal Configuration " 129 | 130 | " Leader with , 131 | let mapleader="," 132 | 133 | " Show number 134 | set number 135 | 136 | " show the cursor position. 137 | set ruler 138 | 139 | " More itens on history 140 | set ruler 141 | 142 | " Show incomplete commands 143 | set showcmd 144 | 145 | " Wildmenu for the win 146 | set wildmenu 147 | 148 | " Keep 5 lines on z enter. 149 | set scrolloff=5 150 | 151 | " High Light search 152 | set hlsearch 153 | set incsearch 154 | 155 | " Backup files and backup dir 156 | set backup 157 | set backupdir=~/.backups 158 | 159 | " Line Wrap 160 | set lbr 161 | 162 | " Follow last identation 163 | set ai 164 | set si "Smart Ident =D 165 | 166 | " Remove highlights with leader + enter 167 | nmap :nohlsearch 168 | 169 | 170 | " Save file with leader w 171 | map w :w! 172 | map :w! 173 | map W :wall! 174 | map n :bn 175 | map p :bp 176 | map b :Buffers 177 | map F :Ag 178 | 179 | " Close a buffer 180 | map d :bd 181 | map D :bd! 182 | 183 | " Edit multiple buffers 184 | set hidden 185 | 186 | nmap :FZF 187 | 188 | set ai sw=2 sts=2 189 | 190 | " Colorscheme 191 | set termguicolors 192 | colorscheme onedark 193 | set bg=dark 194 | 195 | " Tabs for 196 | inoremap pumvisible() ? "\" : "\" 197 | let g:coc_snippet_next = '' 198 | let g:coc_snippet_prev = '' 199 | 200 | " Change tabs with , + 1...9 201 | nmap 1 AirlineSelectTab1 202 | nmap 2 AirlineSelectTab2 203 | nmap 3 AirlineSelectTab3 204 | nmap 4 AirlineSelectTab4 205 | nmap 5 AirlineSelectTab5 206 | nmap 6 AirlineSelectTab6 207 | nmap 7 AirlineSelectTab7 208 | nmap 8 AirlineSelectTab8 209 | nmap 9 AirlineSelectTab9 210 | 211 | " Change tabs with ALT + 1...9 212 | nmap AirlineSelectTab1 213 | nmap AirlineSelectTab2 214 | nmap AirlineSelectTab3 215 | nmap AirlineSelectTab4 216 | nmap AirlineSelectTab5 217 | nmap AirlineSelectTab6 218 | nmap AirlineSelectTab7 219 | nmap AirlineSelectTab8 220 | nmap AirlineSelectTab9 221 | 222 | " Terminal integrated with F4 223 | let g:term_buf = 0 224 | function! Term_toggle() 225 | 1wincmd w 226 | if g:term_buf == bufnr("") 227 | setlocal bufhidden=hide 228 | close 229 | else 230 | topleft vnew 231 | try 232 | exec "buffer ".g:term_buf 233 | catch 234 | call termopen("zsh", {"detach": 1 }) 235 | let g:term_buf = bufnr("") 236 | endtry 237 | startinsert! 238 | endif 239 | endfunction 240 | nnoremap :call Term_toggle() 241 | 242 | " Exit from terminal 243 | :tnoremap 244 | 245 | nmap B CodeRunner 246 | 247 | " Vim-Fugitive 248 | nmap gs :Gstatus 249 | nmap gd :Gdiff 250 | nmap gb :Gbrowse 251 | nmap ga :!git add . 252 | nmap gc :Gcommiti 253 | nmap gl :Glog 254 | nmap ge :Gedit 255 | nmap gh :Git checkout 256 | nmap gg :Git pulla 257 | nmap gm :Git checkout mastera 258 | nmap gwd :Git diff HEAD . 259 | 260 | " Recommend to run it first: git config --global push.default current 261 | nmap gp :Git pusha 262 | 263 | " Rails Stuff 264 | nmap rt :A 265 | nmap rm :Emodel 266 | nmap rc :Econtroller 267 | nmap rv :Eview 268 | 269 | nmap rwt :AV 270 | nmap rwm :Vmodel 271 | nmap rwc :Vcontroller 272 | nmap rwv :Vview 273 | 274 | nmap rwu :RuboCop -a 275 | 276 | map tn :TestNearest 277 | map tf :TestFile 278 | map ta :TestSuite 279 | map tl :TestLast 280 | 281 | " Copy and Paste with system clipboard 282 | nmap \y "+y 283 | nmap \p "*p 284 | xnoremap \y "+y 285 | 286 | let $FZF_DEFAULT_COMMAND = 'ag --hidden --ignore .git -l -g ""' 287 | 288 | " If you prefer the yank always sync with the system, comment above maps and 289 | " uncomment the line below 290 | " set clipboard=unnamedplus 291 | 292 | " Personal configurations 293 | 294 | let g:gitlab_api_keys = {'gitlab.com': 'your-api-key'} 295 | 296 | " Discomment here if you use docker 297 | " let test#ruby#rspec#executable = 'docker-compose exec app rspec' 298 | 299 | set colorcolumn=120 300 | --------------------------------------------------------------------------------