• Stars
    star
    196
  • Rank 192,200 (Top 4 %)
  • Language
  • License
    MIT License
  • Created almost 9 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Setting up vim to be used in rust development

Use VIM as your RUST IDE

Install vim first, if its not already

sudo apt-get install vim

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.

You also need to install

  • curl
  • git
  • CMake
  • Python Headers
  • Development Tools

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
sudo apt-get install build-essential cmake
sudo apt-get install python-dev python3-dev

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

cd ~/.vim/bundle

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

cd ~/.vim/bundle/YouCompleteMe

git submodule update --init --recursive

./install.py --rust-completer
  • Download source code of the rust version you are using, for example 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/<username>/Developer/rust-master/src/"

Install Vim number toggle

vim-numbertoggle adds line numbers to the code you are editing. Line numbers can either show absolute position or position relative to your cursor location. This will boost your productivity later, when you orchestrate vim commands such as moving 10 lines below the current cursor position: 10j.

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

Install NERDtree for displaying files in a tab

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.

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 the editor using wq whenever you want to build the project. A convenient way is to open a new tab in a terminal via <CTRL>-<SHIFT>-t and issue your command (cargo build --release) from there. That way, you don't lose the 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 directly from vim 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 use the mouse to point and click files and move the cursor around, add this to your ~/.vimrc


"enable mouse support
set mouse=a

Additionally, you can use arrow keys to move the cursor around. 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 might get edited outside of your current vi session, such as other editors/code generators, dropbox sync, git pulls.

  • Add this to your ~/.vimrc to refresh them automatically

" 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, you have to install vim-gtk to gain clipboard functionality.

More information here.

sudo apt-get install vim-gtk

Then 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 pasting (<CTRL>-v) in terminal.

One step install for those who have never used vim before or people who want to do it automatically

  • This will replace your existing ~/.vimrc and .vim, if you have one
  • Don't hold me responsible for breaking your vim configuration, your laundry machine or anything else that would make you angry.
sudo apt-get install curl

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

Update

  • 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

More Repositories

1

svgbob

Convert your ascii diagram scribbles into happy little SVG
Rust
3,675
star
2

sauron

A versatile web framework and library for building client-side and server-side web applications
Rust
1,875
star
3

sauron-native

Truly cross platform, truly native. multiple backend GUI for rust
Rust
630
star
4

diwata

A user-friendly database interface
Rust
394
star
5

rustorm

an orm for rust
Rust
248
star
6

spongedown

Markdown with svg bob support
Rust
237
star
7

old-rustorm

An ORM for rust
Rust
165
star
8

curtain

Moved to https://github.com/ivanceras/diwata
Rust
141
star
9

sakila

Sakila sample database for each database platform
TSQL
131
star
10

titik

A cross platform minimalistic text user interface
Rust
118
star
11

hackernews-sauron

A fast, resilient, isomorphic hacker news clone in ~1k lines of rust.
Rust
113
star
12

r2d2-sqlite

r2d2 connection pool for sqlite
Rust
105
star
13

elm-examples

Elm examples and snippets
HTML
78
star
14

ultron

Web base text editor written in rust
Erlang
62
star
15

restq

Compacting the SQL into the URL rest API
Rust
56
star
16

balisong

Voxel renderer using raytracing, written in rust
Rust
44
star
17

ivancerust

Unlimited detail voxel engine in rust
Rust
31
star
18

sql-ast

SQL abstract syntax tree
Rust
29
star
19

inquerest

url parameter parser for rest filter inquiry
Rust
25
star
20

sauron-perf

Rust frontend webframework relative to react
JavaScript
21
star
21

codegenta

Generate source code for your models which corresponds from the database tables
Rust
15
star
22

futureostech

a simplified demo of futuristic UI
HTML
14
star
23

rustupefy

Automagically transform vim into a stunningly beautiful and fast IDE for rust
Shell
13
star
24

fluentsql

fluent sql is a SQL writer used by ivanceras ORM
Java
12
star
25

futuristic-ui

An example project for sauron web framework, showcasing animation transition
Rust
12
star
26

orm

ivanceras ORM, a very simple extensible ORM, which supports offline database handling in the browser using GWT
Java
10
star
27

mt-dom

Generic virtual dom implementation for rust
Rust
10
star
28

blob-uuid

Convert Uuid to a url friendly 22 character string blob
Rust
10
star
29

tinki

A personal wiki
CSS
9
star
30

jss

Easily create dynamic css using json notation
Rust
8
star
31

machine-ip

Get local ip address in rust, equivalent to `hostname -I` in linux
Rust
7
star
32

rust-node-ffi-string

A very practical example of rust and node ffi call using string, json
Rust
6
star
33

curtain-elm

A rebooted implementation of curtain client using elm
HTML
4
star
34

r2d2-sqlite3

An r2d2 connection pool manager for sqlite3
Rust
4
star
35

elm-webclient

elm webclient for diwata
Elm
3
star
36

Books

Collection of my self written books
Shell
3
star
37

ivanceras.github.io

JavaScript
3
star
38

keywordSQL

All the SQL keywords in Java
Java
3
star
39

winapi-rust-example

Example of rust windows ui
Rust
3
star
40

url_path

Rust
2
star
41

dota-sql

A sample data structure using dota2 heroes by valve
Rust
2
star
42

pallet-chainbridge

Chainbridge pallet
Rust
2
star
43

html2sauron

Convert html code to sauron view code
Rust
2
star
44

sauron-markdown

A markdown processor which converts markdown code into a sauron Node
Rust
2
star
45

mandelbrot

A simple implementation of limited iterative calculation of mandrelbot set
Rust
2
star
46

helloworldOS

A minimal code for booting an OS using grub and prints hello world
Assembly
2
star
47

curtain_ui

Client for curtain implemented in javascript
JavaScript
2
star
48

voxel

Rust
1
star
49

madnotes

Interactive notebooks for the mad scientist that you are!
Rust
1
star
50

mushroom

A fork of substrate-api-client
Rust
1
star
51

bazaar

Bazaar plugin for curtain
Rust
1
star
52

crypto-gwt

Provides cryptographic operations for the Google Web Toolkit
Java
1
star
53

curtain_gtk

Gtk client for curtain
Rust
1
star
54

rust-examples

rust test and example codes
Rust
1
star
55

comic

Rust
1
star
56

sample-data

Sample data from mysql db
PLpgSQL
1
star