Vim-Sexp - How do I move each inner form to a new line? - vim

I have the awesome vim-sexp and vim-sexp-mappings-for-regular-people plugins installed, and I've come across a situation I'm not sure how to solve.
Suppose I have the following form:
(alimony barbara (code determinant) eclair final-countdown)
How can I transform that to:
(alimony
barbara
(code determinant)
eclair
final-countdown)
I can go ahead and insert a newline before every inner-form/element, but that is a bit tedious. There should be a way with or without the sexp plugin

This is an old question, but maybe an updated answer will help someone who comes here in the future.
You don't have to write the program mentioned by Kaz. Others have already done it. I have not tried them, but here are a few:
fipp,
cljfmt,
cljstyle,
zprint,
joker. (The last one does more than code formatting.)
As Kaz suggests, once installed, you can pipe code to a formatter using !. You can even bind this operation to a key combination. Some of the formatters offer suggestions about how to do this sort of thing.
In addition, some vim IDE plugins, such as vim-iced provide support for using an external formatter.

A productive way to get this behavior would be, rather than fighting with Vim modules and extensions, to write a Lisp program which reads S-expressions and outputs them reformatted in the desired way. To use that program out of Vim, just pipe a range of lines into it using the ! command.

Related

How to design plain tex data entry helpers such as autocompletion and syntax highlighting

There are some files like GEDCOM and ADIF that are plain text files, but many people tend to work with them through GUIs. Say I wanted to do data entry on these files directly without any GUI.There are a number of things that make this a little dangerous. Things like misspellings of necessary file-grammar, missing a necessary key, incorrect types for values, etc. There is also something to be said for the additional difficulty of having to type additional characters relative to a GUI.
From what I can tell by thinking about this for 15mins ;) is that having the following would make the job of plain text entry much easier.
A formatter. I think of something like Python's Black which is a CLI that can be run on a file. It can let users know of bad formatting and can provide fixes.
A linter. I think of flake8 to ensure the styling matches the standard.
Autocomplete. The file type examples I showed above have a dictionary of key words. To save on typing it would be nice to have autocomplete.
Syntax Highlighting. Having a way to know if my data entry is good or bad in real-time would be helpful.
It seems like requirements 1-2 could be solved by making a file specific CLIs that combs through plain text files.
Requirement 4 seems IDE specific. vim and vscode allow users to make syntax highlighting plugins. The problem is that this is normally solved by connecting to a language server. When you are not looking for a language server, but for key words and proper values in a plain text file how does let their IDE know that to look for? Is this just a regex soup solution or is there a better way?
Requirement 3 may also be IDE specific, but the same question applies as for requirement 4. When there is not a language server how can I let an IDE know what/how to autocomplete?
Any examples of plain text data entry made easier would be appreciated.
Thanks!

Sublime 3 - Highlight variable in Perl/PHP string

I am turning to use Sublime3 instead of Notepad++. I have some concern when working with Perl/PHP or any kind of languages that use dollar sign for declare variable.
Here is an example, in Notepad ++:
As can be seen, "HELO $name" was displayed with different colors.
By that way, we can easily recognize there is a variable in the string.
In Sublime 3 , it looked like this:
So you can see there are no different between text and variable. It would caused confusion in some case.
May I know is there are any solution for this ?
Thank you and best regards.
Alex
This is self-promoting, but it will actually solve the problem
You may want to check out my Neon Color Scheme, available via Package Control. Its goal is to make as many languages as possible look as good as possible, and has hundreds of selectors that are specific for many different syntaxes, including Perl and PHP. Specifically, both languages support highlighting for string interpolation. Here is your code using Sublime's Perl syntax from dev build 3118, which should be very similar to the latest public build, which you should be using if you're not registered yet:
And here is the equivalent code in PHP:
Please note that these images were taken using a work-in-progress version of Neon, which I'm planning on releasing in the next day or so. The current version should look the same, as I don't think I've edited any of these scopes, but if not just let me know and I'll point you to the dev version.

How to change a variable name automatically across the project in VIM?

In eclipse, if you change a variable name, eclipse will automatically change this variable's name in whole project.
Can vim do that too?
Vim is a text editor, not an IDE. Though it has some notion of a filetype's syntax, it does not fully parse nor understand the language's full syntax. Refactorings, even simple ones like Rename identifier, do require such full understanding (to be 100% correct).
There are attempts at refactoring support in Vim, most language-specific, some also generic. But I'd advise to keep using a real IDE for this (for its comfort, safety, and correctness), and instead use Vim only for simple, text-based replacements, using :bufdo substitute/... or macros, as described here.
Sort of.
Because it is not an IDE and thus doesn't understand anything about your code, Vim only sees text where you see a variable name. It can't infer anything from the scope or whatever. Without the use of some external program, renaming a variable in Vim is usually done with a buffer-wide or project-wide search/replace.
Since you didn't tell us what language you are working with we can't tell you if there is a language-specific solution for your needs.
try this plugin -> Clighter, for c-family rename-refactoring. It's based on clang, but there are limitations. Still in development

creating tags for a script language for easy browsing in vim

I use ctags+Vim for a lot of my projects and I really like the ability to easily browse through large chunks of code quickly.
I am also using Stata, a statistical package, which has a script language. Even though you can have routines in the code, its code tends to be series of commands that perform data and statistics operations. And the code files can be very long. So I always find myself in need of a way to browse it efficiently.
Since I use Vim, I can use marks. But I was wondering if I could use ctags to do this. That is, I want to create a tag marker which (1) won't cause a problem when I run the script (2) easy to introduce to ctags.
Because it is supposed to not break the script, it needs to be a comment. In Stata, comment lines start with * and flow comments can be made by /* ..... */.
It would be great, for example, have sections in the code, marked by comments:
* Section: Data
And ctags picks up "Data Manipulation" as the tag. So I can see a list of sections and jump to them easily without the needs for creating marks.
Is there anyway to do this? I'd appreciate any comments.
You need a way to generate a tags database for your Stata files. The format is simple, see :help tags-file-format. The default tags program, Exuberant Ctags can be extended with regular expressions (--langmap, --regex); that probably only yields an approximate parsing for complex languages, but it should suffice for custom section marks; maybe you could even directly extract interesting language keywords.

Command-T for Emacs?

I'm a long time Emacs user, but partially switched to MacVim 2 years ago, and have been using it for all my programming work (still using Emacs for other stuff). I decided to switch back to Emacs now, mainly because of the awesome evil-mode. I'm quite happy, but I still haven't found something as good and simple as the Vim Command-T plugin.
The main problem with the Emacs alternatives is that they are either too complicated and or slow.
The closest thing to Command-T is helm/helm-cmd-t, but it doesn't quite work like it.
Let's say you have two paths:
app/controllers/admin/feedback_controller.rb
app/controllers/fee_controller.rb
In Vim's Command-T, you can write:
app/controllers/fe
And it will match both paths.
With helm-cmd-t, if I write app/controllers/fee, it will only match fee_controller. If I want to match both, I have to use a regexp, as in app/controllers/.*, which is not that bad, but requires more keystrokes.
Any suggestions appreciated!
Any Emacs package that uses ido can do this, provided that ido-flex-match is non-nil. Helm-cmd-t deliberately doesn't support this kind of flexible matching.
You can get the behaviour you describe using find-file-in-repository with ido-flex-match set to 't.
I've recently started using flx with ido-mode and projectile it has exceptionally good, ranked fuzzy matching and has a very similar feel to CtrlP and CmdT for Vim.
It can be installed via MELPA.
M-x package-install
flx
For more info see the flx project.
Here's a screengrab to illustrate...
Here it is, but required helm to be installed first: https://github.com/emacs-helm/helm-cmd-t
EDIT: See my Helm guide. Read why it is powerful. See helm with projectile in action in that section.
With fuzzy searcher like Ido + flx or the like in Vim, you have to type thing in order.
With Helm, you can perform out of order matching.I called it out of order because whether I enter "main.c x86" or "x86 main.c", I get the same set of results for the either query. But it also makes sense to call it multi-steps search. Without having to enter the search strings (called "patterns", which are actually regexp) in an orderly fashion, Helm gives me greater freedom: I can enter the thing I wanted first in my mind without having to remember its complex path; if there are many candidates from the target I wanted, I narrow it down further with more details (patterns).
The above example to illustrate the two cases from the advantage above:
If my desire target is not unique, fine I can narrow further.
If my desire target is unique, I can immediately get it.
As you can see, the Linux kernel source tree contains more than 40kfiles, and I narrowed it down to a few files immediately.
Visual Studio also implements this mechanism in their project search, but it's not generic as Helm. In Helm, you can reuse the same Helm interface for many other things; for example, see helm-semantic-or-imenu. You have something like an outline tree, but you can interactively and incrementally narrow to the candidates you want with a few simple patterns.
Finally, fyi, flx author - Le Wang - is using Helm.
Did you try LustyExplorer? It's based on the Vim plugin with the same name.
Also, it looks like you are not using Command-T to the best of its capabilities: acfe should be enough for it to match those two files. What you do is not particularly better than :e app/con*/**/fe<Tab>.
I've once run across gpicker which advertises speed as one of its advantages over Ido and other "native" elisp packages. Never got to try it out on real-world projects though, but it might work for you.
Long story short - there's nothing quite like command-T for Emacs. Best options are gpicker or Peepcode's peepopen, but they are external applications, and I find them to be distracting after using command-T for so long. I'll stick to MacVim for now, only because of command-T, but might look into implementing something that behaves just like command-T as an exercise.
Thank you all for the answers and comments!
Give textmate.el a try :)
https://github.com/defunkt/textmate.el
You'll just have to use "Command+T" instead of "Ctrl+P" :)
https://github.com/bling/fzf.el
This is the best solution out there in my opinion. Here's why:
Uses projectile to determine project root if you're in a project.
Otherwise it very quickly indexes the file in the current directory.
Fuzzy matching.
Can be customized (top or bottom placement, number of records, etc.)

Resources