Coder Social home page Coder Social logo

rust-vim-setup's Introduction

Use VIM as your RUST IDE

Install vim first, if its not already

sudo apt-get install vim

If your vi did work in your command line, most likely it is the light version of vi which is installed by default in ubuntu, and it lacks the most functionality of the real vi

You also need to install

  • curl
  • git

I assume most of you have already installed it, if not then install it via

sudo apt-get install curl
sudo apt-get install git

Install pathogen plugin

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)

mkdir -p ~/.vim/autoload ~/.vim/bundle
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
  • Add this to ~/.vimrc
execute pathogen#infect()
syntax on
filetype plugin indent on

Install syntax highlighting for rust

cd ~/.vim/bundle
git clone https://github.com/rust-lang/rust.vim.git

Install YouCompleteMe

YouCompleteMe - a code-completion engine for Vim with support for C-family languages and Rust

git clone https://github.com/Valloric/YouCompleteMe

cd ~/.vim/bundle/YouCompleteMe

git submodule update --init --recursive

./install.py --racer-completer
  • Download the source code of version of rust you may be using, say master branch
  • Extract the zip file and put in your Development folder ie. ~/Developer
  • Checkout and build racer
mkdir -p ~/Developer/
cd ~/Developer/
git clone --depth 1 --branch master https://github.com/rust-lang/rust rust-master

Add this to your .vimrc

let g:ycm_rust_src_path="/home//Developer/rust-master/src/"

Install Vim number toggle

vim-numbertoggle shows line numbers to the code you are editing in vim, You can toggle the numbers to absolute or relative position with respect to your current cursor location. This will boost your productivity later, when you orchestrate vim commands such as moving 10 lines below the current cursor location 10j

cd ~/.vim/bundle
git clone git://github.com/jeffkreeftmeijer/vim-numbertoggle.git

Install NERDtree for displaying files in a tab

NERDTree is kind of like the left side tabs of most text editors such as sublime, atom, or eclipse where it list down the files in the current directory you are editing from.

cd ~/.vim/bundle
git clone https://github.com/scrooloose/nerdtree.git
  • Add this to ~/.vimrc
autocmd VimEnter * NERDTree
autocmd BufEnter * NERDTreeMirror

"CTRL-t to toggle tree view with CTRL-t
nmap <silent> <C-t> :NERDTreeToggle<CR>
"Set F2 to put the cursor to the nerdtree
nmap <silent> <F2> :NERDTreeFind<CR>

Controls

CTRL-t  - Open/Close the files tab
CTRL-n  - Toggle relative / absolute numbering
CTRL-ww - Switch between the files tab and the main window
F2      - Focus cursor to files tab
<Enter> - open the focused files/directory, duh!
h,j,k,l - navigate the cursor left, down, up, right respectively
i       - insert mode, you can start typing in your code.
<ESC>   - back to default mode, where you can issue commands in vi
:w      - write/save the file, you are editing
:wqa    - save the file, then quit the editor closing vi including the files tab

Some advance commands

:bp - Open previous file/buffer
:bn - Open next file/buffer
:b <filename-part> - Open the file you are looking for without typing the exact filename
:vsp - vertically split the window
:vsp <filename> - open the file in vertical split
:sp - horizontal split
:sp <filename> - open the file in horizontal split
  • You don't really have to quit wq the editor, whenever you want to go back to the shell to build the project. A convenient way, is to open a new tab in a terminal via <CTRL> <SHIFT> t and issue you cargo build --release commands from there. That way, you don't loose state of your editor, i.e. you can undo u or redo <CTRL> r your code changes when needed

Compile without opening another tab

Alternatively, you can compile your project without opening another terminal instance by issuing the command using :! <external terminal command>

:! cargo run --release

Try to view some files

vi main.rs
  • It should look something like this

Enable mouse support

If you want to be able to use the mouse to point and click files, move the cursor around.

  • Add this to your ~/.vimrc

"enable mouse support
set mouse=a

Additionally by default, you can use the arrow keys to navigate the cursor. 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.

Using Mouse

A helpful vim cheatsheet at

Automatically reload files when changed

Sometimes some of your files maybe edited outside of your current vi session, such other editors/code generators, dropbox sync, git pulls. You may want to have that content be in your current vi session instead.

  • Add this to your ~/.vimrc

" check file change every 4 seconds ('CursorHold') and reload the buffer upon detecting change
set autoread
au CursorHold * checktime  

Enable the global Clipboard in vim

In Linux distros, for some reason, you have to install vim-gtk first to gain clipboard functionality. http://stackoverflow.com/questions/3961859/how-to-copy-to-clipboard-using-vim

sudo apt-get install vim-gtk

The you can

Copy to + register, which is the global/OS clipboard "+y

Paste from + register "+p

Pasting is equivalent to

CTRL-SHIFT-v in insert mode. It is equivalent to Paste (CTRL-v) when used in terminal

Install in one go for the lazy or those who never have used their vim before

  • Make sure you know what you are doing
  • This will replace your existing ~/.vimrc and .vim, if you have one (No worries for non vim users)
  • Don't held me responsible for breaking your vim configuration, your laundry machine and anything that makes you angry.
sudo apt-get install curl

curl -sSf https://raw.githubusercontent.com/ivanceras/rustupefy/master/setup.sh | sh

Comeback here for changes?

  • Update it via (same as setup)
curl -sSf https://raw.githubusercontent.com/ivanceras/rustupefy/master/setup.sh | sh

Uninstall

curl -sSf https://raw.githubusercontent.com/ivanceras/rustupefy/master/uninstall.sh | sh

rust-vim-setup's People

Contributors

i-e-b avatar ivanceras avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.