Programming Scheme(Racket) with VIM - How to get started - vim

recently, I started programming Racket (formerly Scheme) in DrRacket.
I quite fast I began to miss all the features of VIM in DrRacket, so I would like
to use VIM for my scheme(racket) programming.
I know that Emacs might be the best choice for intense lisp programming, but all
I want is write a scheme(racket) file check syntax and then run it.
Unfortunately, I could not figure out, how to invoke "racket" in the commandline
on a file to get it doing the same as DrRacket.
I am running Ubuntu 10.10 Maverick Meerkat, VIM 7.3 and I downloaded and
installed Racket from the official website.
Help to get started would be very appreciated.

If you just want to load a file into Racket on the command-line and run it, I think that this should work:
$ racket -f file.scm -i
The -i option would leave you at the REPL to test your code in file.scm.
However, you might want to take a look at this blog post:
http://technotales.wordpress.com/2007/10/03/like-slime-for-vim/
You can set up a GNU screen session running the command-line Racket, and send s-expressions to it from Vim. There's a link to a bit of Vimscript which will make this automatic. I used this for a while with mit-scheme, and it was reasonably effective. It's not quite the as powerful as SLIME or DrRacket though. I just tested the steps described on OS X and it works with the command-line racket, it should work on Ubuntu, that's what I was using when I first used this method.
You might also want to take a look at this:
http://evalwhen.com/scmindent/index.html
... which has some information on better indentation in Vim for Lisp and Scheme code.
I eventually switched to Emacs, but don't let the Vim haters get you down. Paul Graham supposedly uses vi and he's gotta be one of the top 5 most prominent Lisp programmers.
http://paul.graham.usesthis.com/

Several add-ons are available to make coding in Racket more satisfying with Vim.
Vim’s lisp mode (set lisp) -- improves some basics for indenting and w/e/b word-hopping.
vim-racket -- sizable set of vim-syntax recognition for functions and syntax
syntastic -- identify errors upon save (vim-racket sets makeprg for this to work)
Rainbow Parentheses -- set your own paren colors for maximal contrast!
vim-slime -- use with Tmux to connect Vim to a Racket REPL
surround -- wrap forms and elements in parens
vim-sexp for normal people
Molokai color scheme -- high contrast
VROD* -- K-based Vim documenation, and auto-completion of Racket functions
REPTL* -- very simple continuous rackunit test runner
I prefer slime over slimv for its simplicity.
If you are using Vundle, here is a way to install most of the add-ons mentioned:
Plugin 'tpope/vim-surround.git'
Plugin 'kien/rainbow_parentheses.vim'
Plugin 'scrooloose/syntastic.git'
Plugin 'MicahElliott/vrod'
Plugin 'guns/vim-sexp'
Plugin 'tpope/vim-sexp-mappings-for-regular-people'
Plugin 'wlangstroth/vim-racket'
Plugin 'tomasr/molokai.git'
Put those into your ~/.vimrc, and then invoke to install:
% vim +PluginInstall +qall
Here is a screenshot showing off most of these:
(* disclosure: I wrote VROD and REPTL, and they are immature)
Also, here is a related blog post describing a Vim/SICP setup.

As of about a week ago, SLIMV (SLIME for Vim) supports Racket. SLIMV is generally regarded as the most mature Lisp environment for Vim at the moment.

Related

Debugging scheme on vim

We are working on a project with scheme on UNIX terminal using vim.
We are using mzscheme (though startup prompt says Welcome to Racket v6.1.
Is there any way we can use vim to debug the program?
I tried using Dr.Racket with the following libraries:
#lang racket
#lang scheme
#lang r5rs
but I wasn't even able to run the program so we are thinking of just doing it in vim.
I appreciate all of your suggestion
Maybe that gist might help.
But be aware that actually the vim vs emacs war found an end in spacemacs - we have just to use it and declare an end to this useless meaningless war. spacemacs is an under-the-hood-emacs but presenting itself with vim keybindings.
So this means you can use emacs (a very able lisp editor written in a lisp) to parse lisp code (be it Racket or be it emacs lisp or be it common lisp) using your beloved vim key bindings - and the interactive behaviour of vim.
(emacs is actually an operating system in your operating system. You can make it even open pdf files! I was so amazed when I saw it the first time).
You might give it a shot!
The advantage of this is that emacs is a code-aware editor for lisp code.
Maybe that link will help.

Vim: good pascal support (syntax, indent, probably omnicomplete)

I need to work on existing freepascal project ( it's an open-source project double commander ), so I'm trying to set Vim for editing source files, but pascal support bundled with Vim is surprisingly ugly.
More, I can't even find anything for better pascal support. At least, I really need for working syntax and indent scripts (both of them are buggy by default).
It would be very nice to set up omnicompletion too, but it seems this is completely hopeless.
I will probably hack on syntax and indent scripts myself, but I can't believe we still don't have them, so I decided to ask first.
Perhaps you can improve the situation by telling Vim to use the "delphi" mode instead of the "pascal" mode (this trick works with Emacs too). The reason for this is that in general "Pascal" refers to the old language designed by Wirth in the '70, while Free Pascal incorporates many syntactical additions introduced by Turbo Pascal and Delphi in the following years. Most of the development on Vim/Emacs modes usually goes in the Delphi mode, not the Pascal one.
Have a look at http://www.vim.org/scripts/script.php?script_id=3078. This will not provide autocompletion, but at least it will highlight keywords like "unit", "interface", "implementation", etc., as well as // comments, correctly.
As VIM 7.4.52 for Linux there isn't 'Delphi' option. So far, the 'Pascal' mode works good.
for a freepascal project (fpc), you need to get fpc.vim.
Doing it with 'Plug'
open your .vimrc file and add:
call plug#begin('~/.vim/plugged')
Plug 'vim-scripts/fpc.vim'
call plug#end()
reopen your vim, and use the command :PlugInstall
Highlighting
in order to highlight pascal use command:
:set filetype=pascal
this also enables indent for the code. and it will auto indent the existing code.
or you can use:
:set syntax=pascal
this may fail to indent.

Refactoring in Vim

Of course the fact that you can refactor on IDEs is priceless for many, I hardly ever do it when I am coding but I may try to do it when editing some one else's source. How do you accomplish such a trivial task across multiple files in Vim?
I found this plugin for refactoring Ruby, but how about "any" language?
I agree with the 'Vim is not an IDE' paradigm. But there are times when there isn't an IDE. Here's what I use in those situations:
Disclaimer: The ubiquity of Language Server Protocol servers, linters and fixers since I wrote this have also brought some great refactoring capabilities to Vim (and other editors). IMO they are a long way from equaling the capabilities of a purpose-built IDE (I prefer ALE and nvim-lspconfig for these kinds of features). See other answers on this question for more info!
:grep, :vimgrep, :GrepperAg, :Ggrep
Refactoring that has more to do with regular replacements I usually use :grep on my project tree and then record a macro to do the refactor - :g and :s are no brainers. Usually it'll let me quickly modify a large number of files with very little effort. Honestly, I use this method more than any other.
Depending on your workflow the built-in commands might be slow/inconvenient. If you use git, then you'll wanna use the excellent Fugitive plugin and its :Ggrep command to only search files checked into git. I also like the vim-grepper because it is search-tool-agnostic (supports ag, sift, ripgrep, etc) and speedy.
:argdo, :cdo, and :bufdo
:cdo and :argdo are handy to execute vim commands over a set of files.
command line
When it's harder to determine the list of files that need changes via :vimgrep I resort to the command line grep/find commands to more closely curate the list of files that I need to refactor. Save the list to a text file and use :e and a mashup of macro recordings to make the changes I need to make.
I find that the less rusty I keep my macro recording skills the more useful I find Vim for refactoring: feeling comfortable saving/restoring from registers, incrementing/decrementing register counter variables, cleaning/saving macro recordings to file for later use, etc.
Update
Since writing this more videocasts for the methods I describe have been published on vimcasts.org (I encourage you to watch ALL the Vimcasts!). For refactoring watch these ones:
Substitution with :Subvert
Project wide search/replace
Search multiple files with :vimgrep
Use :argdo to change multiple files
Vimgolf is also a great way to practice.
Language Server Protocol (LSP)
The Language server protocol contains the feature for smart renaming of symbols across a project:
https://microsoft.github.io//language-server-protocol/specifications/specification-3-14/#textDocument_rename
For example following language server support this:
Clangd for C++
ccls for C/C++/Objective-C
Eclipse.jdt.ls for Java
pyls (with rope) for Python
tsserver for TypeScript
Solargraph for Ruby
gopls official lsp for Go (alpha stage in Nov 2019)
texlab for LaTeX
You can find more language servers under https://langserver.org/.
Vim
A vim editor client is necessary to use them within vim. Following options exist:
LanguageClient-neovim (requires rust) suggests the mapping:
nnoremap <silent> <F2> :call LanguageClient_textDocument_rename()<CR>
coc.nvim (requires node.js) suggests the mapping:
" Remap for rename current word
nmap <leader>rn <Plug>(coc-rename)
Ale has
nnoremap <silent> <Plug>(ale_rename) :ALERename<Return>
Ale does not define any keybindings. This has to be done by the user.
vim-lsp provides following command
:LspRename
Similar to Ale no mapping is suggested. However, of course you can define one as following
nmap <leader>r <plug>(lsp-rename)
(<leader>r is to be replaced by your choice; I do not know one which most plugins agree on)
vim-lsc has a default mapping:
'Rename': 'gR'
See also YouCompleteMe which facilitates LSPs as well.
Neovim
Neovim has initial builtin support for lsp since 13.11.2019
See for common configurations of LSPs the project nvim-lspconfig which suggests <space>rn as a mapping for vim.lsp.buf.rename().
Other Refactorings
I do not know if there are plans for the LSP protocol to support more complex refactorings, such as changing class structure, adding parameters to methods/functions or moving a method to a different class. For a list of refactorings see https://refactoring.com/catalog/.
Python
For the python language following plugins provide 'smart' renaming capabilities for vim:
jedi-vim (github) <leader>r
ropevim (github) CTRL-c r r
python-mode (github) :h pymode-rope-refactoring
C-Family
Try the plugin Clighter for rename-refactoring for the c-family. It is based on clang, but there are limitations and the plugin is marked as deprecated.
Suggested mapping by Clighter is
nmap <silent> <Leader>r :call clighter#Rename()<CR>
Note, the successor plugin clighter8 has removed the renaming functionality in the commit 24927db42.
If you use neovim, you can take a look at the plugin clamp. It suggests
nmap <silent> <Leader>r :call ClampRename()<CR>
Maybe not the most elegant solution, but I found it very handy: I use ECLIM to connect VIM and Eclipse. Of course all my source code editing is done in VIM, but when it's time to refactor, one can take advantage of Eclipse's superior cababilities in this matter.
Give it a try.
I wrote this plugin for generic refactoring. It still requires many improvements. Sometime in the future I'll try to abandon ctags in favour of clang for C&C++ refactorings.
Plugin YouCompleteMe (YCM) (20k stars on github)
http://ycm-core.github.io/YouCompleteMe/#the-refactorrename-new-name-subcommand
:h RefactorRename-new-name
In supported file types, this command attempts to perform a semantic
rename of the identifier under the cursor. This includes renaming
declarations, definitions and usages of the identifier, or any other
language-appropriate action. The specific behavior is defined by the
semantic engine in use.
Similar to FixIt, this command applies automatic modifications to your
source files. Rename operations may involve changes to multiple files,
which may or may not be open in Vim buffers at the time. YouCompleteMe
handles all of this for you. The behavior is described in the
following section.
Supported in filetypes: c, cpp, objc, objcpp, cuda, java, javascript,
typescript, rust, cs
By default there is no mapping.
Plugin Factorus
There is another vim plugin dedicated for refactoring called factorus which is available on github.
Currently (2017-12), it supports the languages
c,
java, and
python.
Place cursor at name to refactor and type
gd (or gD if you're refactoring a global variable).
Then
cgn new_name esc
and
. one or more times to refactor next occurrence(s)
or
:%norm . to refactor all occurrences in the buffer at once.
I write a lot of C/C++ code in vim. The most common refactoring that I do is renaming variables, class names, etc. Usually, I use :bufdo :%s/source/dest/g to do a search/replace in files, which is almost the same as renaming provided by big IDE's.
However, in my case, I found that I usually rename similar entities, spelled in different cases (i.e CamelCase, snake_case, etc.), so I decided to write a small utility to help with this kind of "smart-case" search/replace, it is hosted here. It is a command-line utility, not a plugin for vim, I hope that you can find it useful.
Go
The tool godoctor (github) supports several refactoring capabilities
Rename
Extract Function
Extract Local Variable
Toggle var ⇔ :=
Add Godoc stubs
There is a vim plugin https://github.com/godoctor/godoctor.vim which makes them available
With cursor in thing to rename:
:Rename <newname>
Highlighting block to extract:
:Refactor extract newfunc
vim-go
Precise type-safe renaming of identifiers with :GoRename.
Language server gopls
https://github.com/golang/tools/blob/master/gopls/doc/status.md#rename
For refactoring, if you're using Unite (and you should), you can then use vim-qfreplace and make it extremely easy. Check this video that demonstrates how it works. Once your workflow is set, you can make some mappings to optimize it (instead of typing most things like in the video).
A combination of two plugins: vim-ripgrep, to find across files and put the results in the quickfix window, and quickfix-reflector to save the changes right in the quickfix window and have it automatically save each change across the files.
I would consider using the spacemacs version of emacs. It is uses the same modes and most keystrokes as Vim but has many more add-on because of it's lisp nature. If you want to program in C++ you just add the c++ layer and most of the IDE is just set up for you already. For other interpreted languages like python or bash you do not need to leave spacemacs to use them. They even have a way to run blocks of code directly within your text which works fantastic for literate programming or reproducible programming where the code and the data are in the same file. Both done as text.
Spacemacs is much more heavy handed in it's initial load but the additional stuff you can do with it is worth the few seconds of startup cost. One layer org-mode is worth checking it out. It is the best outliner, programmer, day timer / todo list I have ever used.
The CoC addon has (among other features) the ability to rename variables.
https://github.com/neoclide/coc.nvim
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)

IDE / Emacs mode for Shell scripting in Bash/Sh, etc

I use Emacs for shell scripts. I know I read somewhere there's some mode to make it easier (code completion, autocomplete, bracket matching, syntax highligting, check syntax) to write Shell scripts on Emacs but haven't been able to find it. In short, I would like to turn Emacs into a Bash IDE.
Also, is there any other tool/IDE to make scripting easier on the GNU/Linux Shell?
Well, there's a built-in shell mode that does syntax highlighting, if it's not already turned on, M-x shell-script-mode will do it for you.
Regarding a tool to make scripting easier. There's a bash shell debugger, so if you program in bash, that would help quite a bit.
Of course there's eshell, a shell written in Emacs lisp, so you can get all the syntax highlighting you'd expect from lisp, the auto-completion, and the emacs lisp debugger.
I don't think there is any mode for code completion for shell-scripts, at least not in Emacs. (I've actually never felt the need.) However, there is support in bash for completion when running interactively (the package is called "bash-completion", or something similar). This provides tab-completion for many shell-commands.
Another IDE for the VIM world:
Plugin bash-support.vim
screen shots
Help file on-line
I know it is old post, but i will like to share my settings.
I had the same issue and now I use the code below in my .emacs file for sh/bash code autocompletion.
(require 'auto-complete)
(require 'auto-complete-config)
(ac-config-default)
The syntax highlighting should already work if you use a recent version of Emacs.
Griffon is an IDE specifically designed for BASH scripting. Its features include autocomplete, syntax highlighting, error detection, and more.
I am not very familiar to Emacs, but I believe it's not convenient. As I see, good ide always can do:
Jump to declaration
Find references
Code Outline & Show Symbols
Highlight occurrences
Code completion
So I will recommend Jetbrain Idea(with bashsupport plugin) and Visual Studio Code(with bash ide and shell-format extension).
ps:
bashsupport - https://plugins.jetbrains.com/plugin/4230-bashsupport/
bash ide - https://marketplace.visualstudio.com/items?itemName=mads-hartmann.bash-ide-vscode

Favorite (G)Vim plugins/scripts? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
What are your favorite (G)Vim plugins/scripts?
Nerdtree
The NERD tree allows you to explore your filesystem and to open files and
directories. It presents the filesystem to you in the form of a tree which you
manipulate with the keyboard and/or mouse. It also allows you to perform
simple filesystem operations.
The tree can be toggled easily with :NERDTreeToggle which can be mapped to a more suitable key. The keyboard shortcuts in the NERD tree are also easy and intuitive.
Edit: Added synopsis
Tim Pope has some kickass plugins. I love his surround plugin.
Pathogen plugin and more things commented by Steve Losh
Taglist, a source code browser plugin for Vim, is currently the top rated plugin at the Vim website and is my favorite plugin.
I love snipMate. It's simular to snippetsEmu, but has a much better syntax to read (like Textmate).
A very nice grep replacement for GVim is Ack. A search plugin written in Perl that beats Vim's internal grep implementation and externally invoked greps, too. It also by default skips any CVS directories in the project directory, e.g. '.svn'. This blog shows a way to integrate Ack with vim.
A.vim is a great little plugin. It allows you to quickly switch between header and source files with a single command. The default is :A, but I remapped it to F2 reduce keystrokes.
I really like the SuperTab plugin, it allows you to use the tab key to do all your insert completions.
I have recently started using a plugin that highlights differences in your buffer from a previous version in your RCS system (Subversion, git, whatever). You just need to press a key to toggle the diff display on/off. You can find it here: http://github.com/ghewgill/vim-scmdiff. Patches welcome!
Elegant (mini) buffer explorer - This is the multiple file/buffer manager I use. Takes very little screen space. It looks just like most IDEs where you have a top tab-bar with the files you've opened. I've tested some other similar plugins before, and this is my pick.
TagList - Small file explorer, without the "extra" stuff the other file explorers have. Just lets you browse directories and open files with the "enter" key. Note that this has already been noted by previous commenters to your questions.
SuperTab - Already noted by WMR in this post, looks very promising. It's an auto-completion replacement key for Ctrl-P.
Desert256 color Scheme - Readable, dark one.
Moria color scheme - Another good, dark one. Note that it's gVim only.
Enahcned Python syntax - If you're using Python, this is an enhanced syntax version. Works better than the original. I'm not sure, but this might be already included in the newest version. Nonetheless, it's worth adding to your syntax folder if you need it.
Enhanced JavaScript syntax - Same like the above.
EDIT: Comments - Great little plugin to [un]comment chunks of text. Language recognition included ("#", "/", "/* .. */", etc.) .
Not a plugin, but I advise any Mac user to switch to the MacVim distribution which is vastly superior to the official port.
As for plugins, I used VIM-LaTeX for my thesis and was very satisfied with the usability boost. I also like the Taglist plugin which makes use of the ctags library.
clang complete - the best c++ code completion I have seen so far. By using an actual compiler (that would be clang) the plugin is able to complete complex expressions including STL and smart pointers.
No one said matchit yet ? Makes HTML / XML soup much nicer
http://www.vim.org/scripts/script.php?script_id=39
Tomas Restrepo posted on some great Vim scripts/plugins. He has also pointed out some nice color themes on his blog, too. Check out his Vim category.
With version 7.3, undo branches was added to vim. A very powerful feature, but hard to use, until Steve Losh made Gundo which makes this feature possible to use with a ascii
representation of the tree and a diff of the change. A must for using undo branches.
Matrix Mode.
My latest favourite is Command-T. Granted, to install it you need to have Ruby support and you'll need to compile a C extension for Vim. But oy-yoy-yoy does this plugin make a difference in opening files in Vim!
Conque Shell : Run interactive commands inside a Vim buffer
Conque is a Vim plugin which allows you to run interactive programs, such as bash on linux or powershell.exe on Windows, inside a Vim buffer. In other words it is a terminal emulator which uses a Vim buffer to display the program output.
http://code.google.com/p/conque/
http://www.vim.org/scripts/script.php?script_id=2771
The vcscommand plugin provides global ex commands for manipulating version-controlled source files and it supports CVS,SVN and some other repositories.
You can do almost all repository related tasks from with in vim:
* Taking the diff of current buffer with repository copy
* Adding new files
* Reverting the current buffer to the repository copy by nullifying the local changes....
Just gonna name a few I didn't see here, but which I still find extremely helpful:
Gist plugin - Github Gists (Kind
of Githubs answer to Pastebin,
integrated with Git for awesomeness!)
Mustang color scheme (Can't link directly due to low reputation, Google it!) - Dark, and beautiful color scheme. Looks really good in the terminal, and even better in gVim! (Due to 256 color support)
One Plugin that is missing in the answers is NERDCommenter, which let's you do almost anything with comments. For example {add, toggle, remove} comments. And more. See this blog entry for some examples.
I like taglist and fuzzyfinder, those are very cool plugin
TaskList
This script is based on the eclipse Task List. It will search the file for FIXME, TODO, and XXX (or a custom list) and put them in a handy list for you to browse which at the same time will update the location in the document so you can see exactly where the tag is located. Something like an interactive 'cw'
I really love the snippetsEmu Plugin. It emulates some of the behaviour of Snippets from the OS X editor TextMate, in particular the variable bouncing and replacement behaviour.
Zenburn color scheme and good fonts - [Droid Sans Mono](http://en.wikipedia.org/wiki/Droid_(font)) on Linux, Consolas on Windows.
If you're on a Mac, you got to use peepopen, fuzzyfinder on steroids.
I use the following two plugins all the time:
project
vimoutliner
For vim I like a little help with completions. Vim has tons of completion modes, but really, I just want vim to complete anything it can, whenver it can.
I hate typing ending quotes, but fortunately this plugin obviates the need for such misery.
Those two are my heavy hitters.
This one may step up to roam my code like an unquiet shade, but I've yet to try it.
Txtfmt (The Vim Highlighter)
Screenshots
The Txtfmt plugin gives you a sort of "rich text" highlighting capability, similar to what is provided by RTF editors and word processors. You can use it to add colors (foreground and background) and formatting attributes (all combinations of bold, underline, italic, etc...) to your plain text documents in Vim.
The advantage of this plugin over something like Latex is that with Txtfmt, your highlighting changes are visible "in real time", and as with a word processor, the highlighting is WYSIWYG. Txtfmt embeds special tokens directly in the file to accomplish the highlighting, so the highlighting is unaffected when you move the file around, even from one computer to another. The special tokens are hidden by the syntax; each appears as a single space. For those who have applied Vince Negri's conceal/ownsyntax patch, the tokens can even be made "zero-width".
tcomment
"I map the "Command + /" keys so i can just comment stuff out while in insert mode
imap :i

Resources