rust-lang / rust.vim Goto Github PK
View Code? Open in Web Editor NEWVim configuration for Rust.
License: Apache License 2.0
Vim configuration for Rust.
License: Apache License 2.0
What is the license? Is it a free/libre one?
Probably dual Apache + MIT like the other Rust stuff?
In vim's official filetype.vim
, I found that in line 860:
au BufNewFile,BufRead *.vc,*.ev,*.rs,*.sum,*.errsum setf hercules
Maybe it is better to move ftdetect
to after/ftdetect
?
Opened up a Rust file somewhere in the current directory while a few parent directories up had a space in it. I'm not sure where the hang happens but I think the plugin gets stuck in a loop while processing the whole path. Replacing the spaces with a different character makes the issue go away.
fn f() {
if x &&
y {
}
}
Steps to reproduce:
Open a rust buffer
Open a second rust buffer
See error message:
Error detected while processing function delimitMate#Get..<SNR>74_get:
line 7:
E716: Key not present in Dictionary: 3.excluded_regions
E15: Invalid expression: s:options.3.excluded_regions
Open a third buffer
See error message:
Error detected while processing function delimitMate#Get..<SNR>74_get:
line 7:
E716: Key not present in Dictionary: 4.excluded_regions
E15: Invalid expression: s:options.4.excluded_regions
And so on...
Autoformatting is great, but I can see the changes it made only when reviewing the diff.
I think the possibility to see the style errors and fix them manually will helps to write well-formatted code from the start.
ftplugin/rust.vim
will source $VIMRUNTIME/macros/matchit.vim
regardless of whether or not it needs to be loaded, and always assumes it's in the macros
dir.
This is not true as of neovim/neovim#2723. That PR made matchit.vim
always loaded by default and moved matchit.vim
: runtime/macros/matchit.vim → runtime/plugin/matchit.vim
. I believe that a solution would be to instead perform the following:
if !exists('loaded_matchit')
source $VIMRUNTIME/macros/matchit.vim
endif
But I'm still relatively new to vim so I'm not really sure. This appears to work on my machine though.
nvim details:
~
❯ nvim -v
NVIM 0.0.0-alpha+201506222256 (compiled Jun 23 2015 20:42:16)
Commit: 20a57c497b55bb3632f0d4bcd76c18628cfa5f43
Build type: RelWithDebInfo
Compilation: /usr/local/Library/ENV/4.3/clang -Wconversion -O2 -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -DINCLUDE_GENERATED_DECLARATIONS -DHAVE_CONFIG_H -I/tmp/neovim20150623-23404-1k8l993/build/config -I/tmp/neovim20150623-23404-1k8l993/src -I/tmp/neovim20150623-23404-1k8l993/.deps/usr/include -I/tmp/neovim20150623-23404-1k8l993/.deps/usr/include -I/tmp/neovim20150623-23404-1k8l993/.deps/usr/include/luajit-2.0 -I/tmp/neovim20150623-23404-1k8l993/.deps/usr/include -I/tmp/neovim20150623-23404-1k8l993/.deps/usr/include -I/tmp/neovim20150623-23404-1k8l993/.deps/usr/include -I/tmp/neovim20150623-23404-1k8l993/.deps/usr/include -I/Library/Frameworks/Mono.framework/Headers -I/usr/include -I/tmp/neovim20150623-23404-1k8l993/build/src/nvim/auto -I/tmp/neovim20150623-23404-1k8l993/build/include
Compiled by [email protected]
Optional features included (+) or not (-): +acl +iconv +jemalloc
For differences from Vim, see :help vim-differences
system vimrc file: "$VIM/nvimrc"
user vimrc file: "~/.nvimrc"
2nd user vimrc file: "~/.nvim/nvimrc"
user exrc file: "~/.exrc"
fall-back for $VIM: "/usr/local/Cellar/neovim/HEAD/share/nvim"
https://gist.github.com/dmitry-smith/5f72970e84b38ed38db2
:RustRun does not work for me. It always shows the same error:
main.rs:9:25: 9:41 error: unresolved name rand::thread_rng
main.rs:9 let secret_number = rand::thread_rng().gen_range(1, 101);
^~~~~~~~~~~~~~~~
error: aborting due to previous error
But when I try to do the same from a command line with "Cargo run" everything is ok. What can I do to fix it? Thx.
Vim Bootstrap is generator provides a simple method of generating a .vimrc configuration for vim, NeoVim, MacVim and GVim.
After adding rust.vim
to my vim suite buffer switching with :bnext
/ :bprevious
gets annoyingly slow. It takes around a second for the new buffer to be redrawn.
If you want to write a multiline string in a way that lets you edit it exactly as it's printed on the terminal, it's common to write something like this:
fn printsomething() {
println!(
"line__1
line______2
line________3
line___________4"
);
}
Unfortunately the indenter does not leave this as is but tries and indents it into something that makes it impossible to edit, unless you remember to not indent the string (or the region containing it).
Indented properly:
fn test() {
f(x, y,
z);
}
Indentation gets weird when I wrap x, y
with parens:
fn test() {
f((x, y),
z);
}
E.g.
pub fn with_wait_queue<F>(&self, f: F)
where F: Fn(&mut Vec<Weak<Mutex<select::Inner>>>) {
// here?
Currently, the syntastic integration (which will hopefully soon also be used by neomake) runs rustc
with -Zparse-only
to check a particular file. While this is fine, it doesn't catch the vast majority of errors that come up during development.
Obviously, just dropping -Zparse-only
won't work, as the compiler will complain about missing imports/types, but maybe some kind of integration with cargo
could work? Maybe look up the file tree to find Cargo.toml
, run cargo build
, and parse out any warning/error that pertains to the currently open file? It's not pretty, but would be extremely useful!
In imports like use super::super::math::{Vec3, Mat3};
the second (and possible 3rd, 4th, ...) super
is highlighted like a keyword although the first one is highlighted like a module name.
Trying to format some code and:
Error detected while processing function rustfmt#Format:
line 7:
E117: Unknown function: systemlist
E15: Invalid expression: systemlist(command . g:rustfmt_options . " " . shellescape(l:tmpname))
The cause of this - CentOS base repository vim version 7.4.160. Please add to requirement vim minimal version 7.4.568.
Thanks!
P.S. On CentOS 7 you can build fresh version of vim from Fedora repo:
rpmbuild --rebuild https://download.fedoraproject.org/pub/fedora/linux/releases/22/Everything/source/SRPMS/v/vim-7.4.640-4.fc22.src.rpm
struct Circle {
x: f64,
y: f64,
radius: f64,
}
is now indented as
struct Circle {
x: f64,
y: f64,
radius: f64,
}
How to fix this?
currently writing
pub struct foo {
}
results in:
pub struct foo {
}
If you select the following code block in visual mode and hit ==
(automatic indentation)
let philosophers = vec![
Philosopher::new("Judith Butler"),
Philosopher::new("Gilles Deleuze"),
Philosopher::new("Karl Marx"),
Philosopher::new("Emma Goldman"),
Philosopher::new("Michel Foucault"),
];
It closing vec bracket is not correctly indented.
let philosophers = vec![
Philosopher::new("Judith Butler"),
Philosopher::new("Gilles Deleuze"),
Philosopher::new("Karl Marx"),
Philosopher::new("Emma Goldman"),
Philosopher::new("Michel Foucault"),
];
So, I have some weird issues when saving files using rust.vim. Whenever I changed a file and want to save it, vim displays the whole file in that scrollable mode (--- More --- at the bottom line, scrolling with arrow keys) and only when I scroll to the bottom, the file gets saved. This does not happen without rust.vim.
I use pathogen and have nerdtree, youcompleteme, syntastic and rust.vim in my bundle folder.
vim --version
:
$ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Mar 19 2016 22:56:19)
Included patches: 1-1000
Compiled by jan@jan-laptop
Huge version with GTK2 GUI. Features included (+) or not (-):
+acl +farsi +mouse_netterm +syntax
+arabic +file_in_path +mouse_sgr +tag_binary
+autocmd +find_in_path -mouse_sysmouse +tag_old_static
+balloon_eval +float +mouse_urxvt -tag_any_white
+browse +folding +mouse_xterm -tcl
++builtin_terms -footer +multi_byte +terminfo
+byte_offset +fork() +multi_lang +termresponse
+cindent +gettext -mzscheme +textobjects
+clientserver -hangul_input +netbeans_intg +title
+clipboard +iconv +path_extra +toolbar
+cmdline_compl +insert_expand -perl +user_commands
+cmdline_hist +jumplist +persistent_undo +vertsplit
+cmdline_info +keymap +postscript +virtualedit
+comments +langmap +printer +visual
+conceal +libcall +profile +visualextra
+cryptv +linebreak +python +viminfo
+cscope +lispindent -python3 +vreplace
+cursorbind +listcmds +quickfix +wildignore
+cursorshape +localmap +reltime +wildmenu
+dialog_con_gui -lua +rightleft +windows
+diff +menu -ruby +writebackup
+digraphs +mksession +scrollbind +X11
+dnd +modify_fname +signs -xfontset
-ebcdic +mouse +smartindent +xim
+emacs_tags +mouseshape -sniff +xsmp_interact
+eval +mouse_dec +startuptime +xterm_clipboard
+ex_extra -mouse_gpm +statusline -xterm_save
+extra_search -mouse_jsbterm -sun_workshop +xpm
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
system gvimrc file: "$VIM/gvimrc"
user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
system menu file: "$VIMRUNTIME/menu.vim"
fall-back for $VIM: "/usr/local/share/vim"
f-b for $VIMRUNTIME: "/usr/share/vim/vim74"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -pthread -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/libdrm -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/pango-1.0 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -L/usr/local/lib -Wl,--as-needed -o vim -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype -lXt -lX11 -lSM -lICE -lm -lncurses -lacl -L/usr/lib/python2.7/config -lpython2.7 -ldl -lutil -lm -Xlinker -export-dynamic
In gentoo, as root, I had to do:
time emerge -nav app-vim/syntastic
(took ~46 seconds)
or else there were no errors in vim, but only syntax highlighting was working.
Having syntastic installed, syntax errors are now detected on save. (ie. rustc is ran with -Zparse-only on the saved file)
I believed that match
is a keyword like let
and fn
in rust, but only to found there is no highlight for match
.
Is it a bug or feature?
Hi, it appears as if the output generated by :RustFmt
gets loaded into the pager, and I have to hit q
to have it disappear and continue editing. Is there a way to avoid that happening?
need to set it with :set syntax=rust
just in case, here is my vimrc
Currently, if you use a type like Box<Fn(A) -> B>
the latter part of the arrow is misinterpreted as the closing bracket of the generic parameter list. This leads to an incorrect matching, so that the wrong bracket is highlighted. Can this be fixed by this plugin?
Minimal example:
impl X {
//}
}
let g:rust_conceal = 1
let g:rust_conceal_mod_path = 1
How to fix it?
How to bind it?
!= to ≢ or ≠
== to ≡
<= to ≤
= to ≥
=> to ⇒
-> to →
in to ∈
/ to ÷
|| to ∨
&& to ∧
How to deal with "for x in iterator"? ∀
Most of them are not even special cases in the compiler. E.g., giving Vec special highlighting makes no sense.
This looks like a reasonable subset:
" Things from the prelude (src/libstd/prelude.rs) {{{2
syn keyword rustTrait Copy Send Sized Sync
syn keyword rustTrait Add Sub Mul Div Rem Neg Not
syn keyword rustTrait BitAnd BitOr BitXor
syn keyword rustTrait Drop Deref DerefMut
syn keyword rustTrait Shl Shr Index IndexMut
syn keyword rustTrait PartialEq PartialOrd Eq Ord
syn keyword rustTrait Box
syn keyword rustSelf self
syn keyword rustBoolean true false
Rust's got a new contextual keyword, only an unstable feature so far, default
that is used by specialization.
I've installed the vim plugin with Pathogen and get the following error on initial write:
"main.rs" 4L, 77C written
Error detected while processing function 245..191:
line 9:
E700: Unknown function: SyntaxCheckers_rust_rustc_IsAvailable
Error detected while processing function <SNR>43_UpdateErrors..<SNR>43_CacheErrors..248..250..256..196:
line 1:
E15: Invalid expression: self._isAvailableFunc()
E15: Invalid expression: self._isAvailableFunc()
Subsequent writes to the same file produce:
"main.rs" 4L, 77C written
Error detected while processing function <SNR>43_UpdateErrors..<SNR>43_CacheErrors..248..250..256..196:
line 1:
E15: Invalid expression: self._isAvailableFunc()
E15: Invalid expression: self._isAvailableFunc()
I've been using vim-go, which has this feature, and it's really nice.
So that you can do :make
and :cc
for populating the QuickFix list.
Line joining with J
on line 1 here:
1: foo();
2: // comment
Produces incorrect result:
1: foo() comment
There is a very annoying issue with VIM not redrawing on certain TERM values with a dark background after returning from :RustRun. According to the VIM experts,
"this only happens with :! and :shell. use system() instead. This will avoid the curses mucking that results in the required redraw."
Just trying to open a file with the hello_world
example.
"hw.rs" 3L, 45C
Error detected while processing /Users/chr0n1x/.vim/bundle/rust.vim/ftplugin/rust.vim:
line 93:
E484: Can't open file /usr/local/Cellar/neovim/HEAD/share/nvim/runtime/macros/matchit.vim
This is done by https://github.com/tpope/vim-markdown, so it might be helpful to start there.
It's a simple autocmd FileType rs autocmd BufWritePre <buffer> :%s/\s\+$//e
I don't know where this would go, or otherwise I would submit a PR.
I very much like having rustfmt fix my formatting when I save, but sometimes I make syntax errors because I'm human. rustfmt proactively tries to tell me about that, and rust.vim helpfully shows me the error. However, if I've done :wq
rather than merely :w
Vim ends up in a strange state where the only thing open is the quickfix list with the error in it, the things I type are written into the buffer, but when I hit enter the command I typed is executed.
Possible solutions:
Stackoverflow has a working solution for that, but I don't know how to integrate it into the files in this repository.
It says I should add this to my .vimrc
:
autocmd Filetype c,cpp set comments^=:///
This works (after replacing c,cpp
with rust
), but ftplugin/rust.vim
already adds :///
to the set of possible comments. Moving it to the end does not help either.
Hey all,
Sorry for using an issue as a message box, but I wasn't sure who to contact.
I/we are currently working on an RFC that will change up the compiler error output a bit: rust-lang/rfcs#1644 This may have some IDE impacts, if the plugin is doing a match against the output.
We've also been talking about standardizing a JSON output for the compiler so that IDEs can get more information that way.
Would love to get your feedback on what impact it has on the vim plugin.
As a new Rust user, I was very confused about why Rustfmt wasn't working. I enabled it to run automatically on save, but if you don't have Rustfmt installed then it just echo's the source file to the terminal - no error messages or anything. So it would be really helpful if you could either add an error message or a note in the docs telling people to install rustfmt using cargo install rustfmt
. Thanks!
///
and //!
comments don't show up as comments.
I have syntastic installed, it works for other filetypes. Can't get it to work with this plugin. I don't get any errors, it just doesn't work.
Here's example:
fn main() {
let x: i32 = "test";
}
When I'm trying to compile, I get:
test.rs:2:18: 2:24 error: mismatched types:
expected `i32`,
found `&'static str`
(expected i32,
found &-ptr) [E0308]
test.rs:2 let x: i32 = "test";
^~~~~~
error: aborting due to previous error
Saving file or running :SyntasticCheck
doesn't do anything.
Here's :SyntasticInfo
output:
Syntastic version: 3.6.0-86 (Vim 704, Darwin)
Info for filetype: rust
Global mode: active
Filetype rust is active
The current file will be checked automatically
Available checker: rustc
Currently enabled checker: rustc
Could these be pushed upstream for inclusion in 7.5? Having it available by default offers a much nicer initial experience.
If you type std::pro
and then tab, the first suggestion that comes up is Process
, which is wrong according to racer:
racer complete std::pro
MATCH process,1,0,/Users/kaiyin/rust_source/rust/src/libstd/process.rs,Module,/Users/kaiyin/rust_source/rust/src/libstd/process.rs
Having documentation inline in a source file is a blessing when working in a new codebase, but when working in a familiar file large amounts of comments between each piece of code only serve to obscure clarity. A way to fold them up would go a long way towards alleviating this problem.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.