├── .gitignore ├── rust-vim.png ├── using-mouse.gif ├── LICENSE ├── README.md └── VIM_Notes.md /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.swp 3 | *.swo 4 | -------------------------------------------------------------------------------- /rust-vim.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivanceras/rust-vim-setup/HEAD/rust-vim.png -------------------------------------------------------------------------------- /using-mouse.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivanceras/rust-vim-setup/HEAD/using-mouse.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Use VIM as your RUST IDE 3 | 4 | 5 | ### Install vim first, if its not already 6 | 7 | ```sh 8 | 9 | sudo apt-get install vim 10 | ``` 11 | If `vi` worked in your command line, it is most likely the light version of `vi` which is installed by default in Ubuntu, and it lacks most functionality of the real `vi`. 12 | 13 | 14 | You also need to install 15 | 16 | * `curl` 17 | * `git` 18 | * `CMake` 19 | * Python Headers 20 | * Development Tools 21 | 22 | I assume most of you have already installed it, if not then install it via 23 | 24 | ```sh 25 | 26 | sudo apt-get install curl 27 | sudo apt-get install git 28 | sudo apt-get install build-essential cmake 29 | sudo apt-get install python-dev python3-dev 30 | ``` 31 | 32 | 33 | 34 | 35 | ### Install pathogen plugin 36 | [Pathogen](https://github.com/tpope/vim-pathogen) is a vim plugin which allows you to easily install other plugins, by just adding files into the `~/.vim/bundle` (There are other alternatives, but pathogen is most commonly used) 37 | 38 | ```sh 39 | 40 | mkdir -p ~/.vim/autoload ~/.vim/bundle 41 | curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim 42 | ``` 43 | * Add this to `~/.vimrc` 44 | 45 | ```sh 46 | execute pathogen#infect() 47 | syntax on 48 | filetype plugin indent on 49 | ``` 50 | 51 | 52 | 53 | 54 | ### Install syntax highlighting for rust 55 | 56 | ```sh 57 | 58 | cd ~/.vim/bundle 59 | git clone https://github.com/rust-lang/rust.vim.git 60 | ``` 61 | 62 | 63 | 64 | ### Install YouCompleteMe 65 | 66 | [YouCompleteMe](https://github.com/Valloric/YouCompleteMe) - a code-completion engine for Vim with support for C-family languages and [Rust](http://blog.jwilm.io/youcompleteme-rust) 67 | 68 | ```sh 69 | cd ~/.vim/bundle 70 | 71 | git clone https://github.com/Valloric/YouCompleteMe 72 | 73 | cd ~/.vim/bundle/YouCompleteMe 74 | 75 | git submodule update --init --recursive 76 | 77 | ./install.py --rust-completer 78 | 79 | ``` 80 | 81 | * Download source code of the rust version you are using, for example [master branch](https://github.com/rust-lang/rust/) 82 | * Extract the zip file and put in your Development folder ie. `~/Developer` 83 | * Checkout and build racer 84 | 85 | ```sh 86 | 87 | mkdir -p ~/Developer/ 88 | cd ~/Developer/ 89 | git clone --depth 1 --branch master https://github.com/rust-lang/rust rust-master 90 | 91 | ``` 92 | Add this to your `.vimrc` 93 | 94 | ```sh 95 | let g:ycm_rust_src_path="/home//Developer/rust-master/src/" 96 | ``` 97 | 98 | 99 | 100 | ### Install Vim number toggle 101 | 102 | [vim-numbertoggle](https://github.com/jeffkreeftmeijer/vim-numbertoggle) adds line numbers to the code you are editing. 103 | Line numbers can either show absolute position or position relative to your cursor location. 104 | This will boost your productivity later, when you orchestrate vim commands such as moving 10 lines below the current cursor position: `10j`. 105 | 106 | 107 | 108 | ```sh 109 | 110 | cd ~/.vim/bundle 111 | git clone git://github.com/jeffkreeftmeijer/vim-numbertoggle.git 112 | ``` 113 | 114 | 115 | 116 | ### Install `NERDtree` for displaying files in a tab 117 | [NERDTree](https://github.com/scrooloose/nerdtree) is a file manager, that most text editors have, such as `sublime`, `atom`, or `eclipse` where it lists the files in the directory you are editing from. 118 | 119 | ```sh 120 | 121 | cd ~/.vim/bundle 122 | git clone https://github.com/scrooloose/nerdtree.git 123 | ``` 124 | * Add this to `~/.vimrc` 125 | 126 | ``` 127 | autocmd VimEnter * NERDTree 128 | autocmd BufEnter * NERDTreeMirror 129 | 130 | "CTRL-t to toggle tree view with CTRL-t 131 | nmap :NERDTreeToggle 132 | "Set F2 to put the cursor to the nerdtree 133 | nmap :NERDTreeFind 134 | ``` 135 | 136 | 137 | 138 | 139 | 140 | ## Controls 141 | 142 | ```sh 143 | 144 | CTRL-t - Open/Close the files tab 145 | CTRL-n - Toggle relative / absolute numbering 146 | CTRL-ww - Switch between the files tab and the main window 147 | F2 - Focus cursor to files tab 148 | - Open the focused files/directory, duh! 149 | h,j,k,l - Navigate the cursor left, down, up, right respectively 150 | i - Insert mode, you can start typing in your code. 151 | - Back to default mode, where you can issue commands in vi 152 | :w - Write/save the file, you are editing 153 | :wqa - Save the file, then quit the editor closing vi including the files tab 154 | ``` 155 | ## Some advance commands 156 | 157 | ```sh 158 | 159 | :bp - Open previous file/buffer 160 | :bn - Open next file/buffer 161 | :b - Open the file you are looking for without typing the exact filename 162 | :vsp - Vertically split the window 163 | :vsp - Open the file in vertical split 164 | :sp - Horizontal split 165 | :sp - Open the file in horizontal split 166 | 167 | ``` 168 | * You don't really have to quit the editor using `wq` whenever you want to build the project. 169 | A convenient way is to open a new tab in a terminal via `--t` 170 | and issue your command (`cargo build --release`) from there. That way, you don't lose the state of your editor, 171 | i.e. you can undo `u` or redo `-r` your code changes when needed 172 | 173 | ## Compile without opening another tab 174 | Alternatively, you can compile your project without opening another terminal instance by issuing the command directly from `vim` using `:! ` 175 | 176 | ```sh 177 | :! cargo run --release 178 | ``` 179 | 180 | 181 | 182 | ## Try to `vi`ew some files 183 | 184 | ```sh 185 | 186 | vi main.rs 187 | ``` 188 | 189 | 190 | * It should look something like this 191 | 192 | ![](https://raw.githubusercontent.com/ivanceras/rust-vim-setup/master/rust-vim.png) 193 | 194 | 195 | 196 | ## Enable mouse support 197 | 198 | If you want to use the mouse to point and click files and move the cursor around, add this to your `~/.vimrc` 199 | 200 | ``` 201 | 202 | "enable mouse support 203 | set mouse=a 204 | ``` 205 | 206 | Additionally, you can use arrow keys to move the cursor around. 207 | However, if you are really serious about using `vi` and want to maximize your `vi` skills, you should minimize the use of the arrow keys or the mouse. 208 | 209 | ![Using Mouse](https://raw.githubusercontent.com/ivanceras/rust-vim-setup/master/using-mouse.gif) 210 | 211 | ## A helpful vim cheatsheet at 212 | * http://vim.rtorr.com/ 213 | * [My Comprehensive List](https://github.com/ivanceras/rust-vim-setup/blob/master/VIM_Notes.md) 214 | 215 | 216 | ## Automatically reload files when changed 217 | 218 | Sometimes some of your files might get edited outside of your current `vi` session, such as other editors/code generators, dropbox sync, git pulls. 219 | 220 | * Add this to your `~/.vimrc` to refresh them automatically 221 | 222 | ``` 223 | 224 | " check file change every 4 seconds ('CursorHold') and reload the buffer upon detecting change 225 | set autoread 226 | au CursorHold * checktime 227 | ``` 228 | 229 | ## Enable the global Clipboard in vim 230 | In Linux distros, you have to install `vim-gtk` to gain clipboard functionality. 231 | 232 | [More information here.](http://stackoverflow.com/questions/3961859/how-to-copy-to-clipboard-using-vim) 233 | 234 | ```sh 235 | 236 | sudo apt-get install vim-gtk 237 | 238 | ``` 239 | Then you can 240 | 241 | Copy to `+` register, which is the global/OS clipboard 242 | `"+y` 243 | 244 | Paste from `+` register 245 | `"+p` 246 | 247 | 248 | Pasting is equivalent to `--v` in insert mode. 249 | It is equivalent to pasting (`-v`) in terminal. 250 | 251 | 252 | 253 | ## One step install for those who have never used vim before or people who want to do it automatically 254 | * This will replace your existing `~/.vimrc` and `.vim`, if you have one 255 | * Don't hold me responsible for breaking your vim configuration, your laundry machine or anything else that would make you angry. 256 | 257 | ```sh 258 | 259 | sudo apt-get install curl 260 | 261 | curl -sSf https://raw.githubusercontent.com/ivanceras/rustupefy/master/setup.sh | sh 262 | 263 | ``` 264 | 265 | ## Update 266 | 267 | * Update it via (same as setup) 268 | 269 | ```sh 270 | 271 | curl -sSf https://raw.githubusercontent.com/ivanceras/rustupefy/master/setup.sh | sh 272 | 273 | ``` 274 | 275 | ## Uninstall 276 | 277 | ```sh 278 | 279 | curl -sSf https://raw.githubusercontent.com/ivanceras/rustupefy/master/uninstall.sh | sh 280 | 281 | ``` 282 | -------------------------------------------------------------------------------- /VIM_Notes.md: -------------------------------------------------------------------------------- 1 | 2 | # Basic Controls 3 | CTRL-t open or close nerdtree 4 | CTRL-n toggle relative / absolute numbering 5 | CTRL-w w switch focus on nerdtree and open windows 6 | h,j,k,l navigate the cursor left, down, up, right respectively 7 | i insert mode, you can start typing in your code 8 | go back to normal/default mode, where you can issue vi commands 9 | :w write/save the file, you are editing 10 | :wqa save the file, then quit the editor closing vi including the files tab 11 | set focus on the nerd tree 12 | 13 | ## Rust specific commands 14 | 15 | CTRL-x CTRL-o activate auto rust autocompeletion (example: type in `String::` then press CTRL-x CTRL-o then select from the drop down list the appropriate functions) 16 | gd go to function/struct/variable declaration of the focused item ( this is equivalent to eclipse' open declaration ) 17 | gD go to declaration split open in window tab 18 | :bp to go back to the previous edited file (very useful when following a declaration) 19 | :b when you have open a lot of files, this comes in handy in showing back the previously open files 20 | 21 | 22 | # NERDTree specific commands 23 | 24 | o open files, directories and bookmarks 25 | go open selected file, but leave cursor in the NERDTree 26 | t open selected node/bookmark in a new tab 27 | T same as 't' but keep the focus on the current tab 28 | i open selected file in a split window 29 | gi same as i, but leave the cursor on the NERDTree 30 | s open selected file in a new vsplit 31 | gs same as s, but leave the cursor on the NERDTree 32 | O recursively open the selected directory 33 | x close the current nodes parent 34 | X recursively close all children of the current node 35 | e edit the current dif 36 | 37 | ENTER open files, directories and bookmarks 38 | double-click open files, directories and bookmarks 39 | 40 | D delete the current bookmark 41 | 42 | P jump to the root node 43 | p jump to current nodes parent 44 | K jump up inside directories at the current tree depth 45 | J jump down inside directories at the current tree depth 46 | CTRL-J jump down to the next sibling of the current directory 47 | CTRL-K jump up to the previous sibling of the current directory 48 | 49 | C change the tree root to the selected dir 50 | u move the tree root up one directory 51 | U same as 'u' except the old root node is left open 52 | r recursively refresh the current directory 53 | R recursively refresh the current root 54 | m display the NERD tree menu 55 | cd change the CWD to the dir of the selected node 56 | 57 | I toggle whether hidden files displayed 58 | f toggle whether the file filters are used 59 | F toggle whether files are displayed 60 | B toggle whether the bookmark table is displayed 61 | 62 | q close the NERDTree window 63 | A zoom (maximize/minimize) the NERDTree window 64 | ? toggle the display of the quick help 65 | 66 | 67 | 68 | 69 | # Cursor movement 70 | 71 | h move left 72 | j move down 73 | k move up 74 | l move right 75 | 76 | *Note: Prefix a cursor movement command with a number to repeat it. For example, 4j moves down 4 lines.* 77 | 78 | CTRL-b page up 79 | CTRL-f page down 80 | % jump to matching brace 81 | w jump by start of words (punctuation considered words) 82 | W jump by words (spaces separate words) 83 | e jump to end of words (punctuation considered words) 84 | E jump to end of words (no punctuation) 85 | b jump backward by words (punctuation considered words) 86 | B jump backward by words (no punctuation) 87 | ge jump backward to end of words (punctuation considered words) 88 | gE jump backward to end of words (no punctuation) 89 | 0 (zero) start of line 90 | ^ first non-blank character of line 91 | $ end of line 92 | gg go to first line 93 | G go to last line of the file 94 | [N]G go To line N, (example 20G - go to Line 20) 95 | 96 | 97 | # Inserting/Appending text 98 | 99 | i start insert mode at cursor 100 | I insert at the beginning of the line 101 | a append after the cursor 102 | A append at the end of the line 103 | o open (append) blank line below current line (no need to press return) 104 | O open blank line above current line 105 | ea append at end of word 106 | ESC exit insert mode, to normal mode 107 | 108 | # Editing 109 | 110 | r replace a single character (does not use insert mode) 111 | J join line below to the current one 112 | cc change (replace) an entire line 113 | cw change (replace) to the end of word 114 | c$ change (replace) to the end of line 115 | s delete character at cursor and subsitute text 116 | S delete line at cursor and substitute text (same as cc) 117 | xp transpose two letters (delete and paste, technically) 118 | u undo 119 | CTRL-r redo 120 | . repeat last command 121 | ~ switch case 122 | g~iw switch case of current word 123 | gUiw make current word uppercase 124 | guiw make current word lowercase 125 | >> indent line one column to right 126 | << indent line one column to left 127 | == auto-indent current line 128 | ddp swap current line with next 129 | ddkP swap current line with previous 130 | 131 | # Cut and Paste 132 | 133 | dd delete (cut) a line 134 | dw delete the current word 135 | x delete current character 136 | X delete previous character 137 | D delete from cursor to end of line 138 | yy yank (copy) a line 139 | 2yy yank 2 lines 140 | yw yank word 141 | y$ yank to end of line 142 | p put (paste) the clipboard after cursor/current line 143 | P put (paste) before cursor/current line 144 | :set paste avoid unexpected effects in pasting 145 | 146 | # Visual Mode - Marking, Highligting text 147 | 148 | v start visual mode, mark lines, then do command (such as y-yank) 149 | V start Linewise visual mode (i.e selecting the whole line at the cursor location ) 150 | o move to other end of marked area 151 | U upper case of marked area 152 | CTRL-v start visual block mode (that is, selecting text in rectangular area marker) 153 | O move to Other corner of block 154 | aw mark a word 155 | ab a () block (with braces) 156 | aB a {} block (with brackets) 157 | ib inner () block 158 | iB inner {} block 159 | ESC exit visual mode, go to normal mode 160 | gv re-select the last selected visual area 161 | 162 | *Note: right after entering visual mode, you can use the same cursor movement commands in the normal/default mode to highlight your selection* 163 | 164 | # Visual Mode 165 | 166 | ## Commands 167 | 168 | > shift right the marked text 169 | < shift left the marked text 170 | c change (replace) marked text 171 | y yank (copy) marked text 172 | d delete (cut) marked text 173 | ~ switch case of the marked text 174 | 175 | ## Cut and paste 176 | 177 | 1. Place the cursor at the start of your text. 178 | 2. ma (marks the location as point 'a') 179 | 3. Place the cursor at the end of your text. 180 | 4. d'a (cuts back to location 'a') 181 | 182 | ## Exiting 183 | 184 | :w - write (save) the file, but don't exit 185 | :wq - write (save) and quit 186 | :x - same as :wq 187 | :q - quit (fails if anything has changed) 188 | :q! - quit and throw away changes 189 | 190 | # Search/Replace 191 | 192 | /pattern search for pattern 193 | ?pattern search backward for pattern 194 | n repeat search in same direction 195 | N repeat search in opposite direction 196 | :%s/old/new/g replace all old with new throughout file 197 | :%s/old/new/gc replace all old with new throughout file with confirmations 198 | % go to the corresponding (, {, [. 199 | * go to next occurrence of the word under the cursor 200 | # go to previous occurrence of the word under the cursor 201 | 202 | 203 | # Working with multiple files 204 | 205 | :e filename edit a file in a new buffer 206 | :n **/*.pl open all perl files under the current directory, recursively 207 | :tabe filename edit a file in a new tab (Vim7, gVim) 208 | :bnext (or :bn go to next buffer 209 | :bprev (or :bp go to previous buffer 210 | :bd delete a buffer (close a file) 211 | :sp filename open a file in a new buffer and split window 212 | CTRL-w s split windows 213 | CTRL-w w switch between windows 214 | CTRL-w q quit a window 215 | CTRL-w v split windows vertically 216 | CTRL-w x swap the current window with the next one 217 | :e# Open previous file 218 | CTRL-^ Edit the alternate file. Mostly the alternate file is 219 | the previously edited file. This is a quick way to 220 | toggle between two files. It is equivalent to ":e#", 221 | except that it also works when there is no file name. 222 | 223 | ### Moving the cursor in between windows 224 | CTRL-w h Move cursor left to the current window 225 | CTRL-w k Move cursor top to the current window 226 | CTRL-w j Move cursor bottom to the current window 227 | CTRL-w l Move cursor right to the current window 228 | 229 | ## Moving windows with respect to the current focused window 230 | CTRL-w H Move current window to the far left 231 | CTRL-w K Move current window to the top 232 | CTRL-w J Move current window to the bottom 233 | CTRL-w L Move current window to the right 234 | 235 | ## Window movements 236 | CTRL-w | Maximize the window horizontally 237 | CTRL-w _ Maximize the window vertically 238 | CTRL-w = Resize all window to equal sizes 239 | 240 | # Changeset, last edit jumping back and forth 241 | `. jump to the last edit 242 | g; go to previous edit 243 | g, go to next edit 244 | CTRL-o go to previous edit 245 | CTRL-i go to next edit 246 | '' jump to last location (no-edits) 247 | `` jump to last location (no-edits) 248 | 249 | # Fuzzy searching files with CTRL.P plugin 250 | CTRL-p Open up search user interface 251 | you can then start typing what you are looking for 252 | CTRL-f By default your search text is match against files, 253 | pressing CTRL-f will switch to match for content of the files, buffers, 254 | directories, etc. 255 | CTRL-b same as CTRL-f but cycle on opposite direction 256 | 257 | CTRL-j Move down 1 line of the search results 258 | CTRL-k Move up 1 line on the search results 259 | Open the file of the focused line in the search result 260 | CTRL-t Open the focused file of the line in the search result in a new tab 261 | CTRL-v Open the focused file of the line in the search result in a vertical split 262 | CTRL-x Open the focused file of the line in the search result in a horizontal split 263 | CTRL-z Mark select the focused file of the line in the search result 264 | CTRL-o Opens all the mark selected files in the search results 265 | 266 | 267 | --------------------------------------------------------------------------------