Aligning two columns of text in Vim - vim

I want to align the below code:
Sample Code:
.abc (abc)
.bcd (dfdfd)
.xyzdddddd (xyzdfdd)
After alignment:
.abc (abc)
.bcd (dfdfd)
.xyzdddddd (xyzdfdd)
How can we align this with Vim?

If you're on linux, you can call an external tool to do the job (no need for a plugin):
:%!column -t
See help range!:
:{range}![!]{filter} [!][arg] :range!
Filter {range} lines through the external program
{filter}...

Emacs M-x align-regexp (
Does exactly what you are asking for.
Searched 'vim equivalent of emacs align regexp'
and the answer is that there is a plugin called
'easy align'
See
www.reddit.com/r/emacs/comments/59uh2m/is_there_an_emacs_equivalent_to_vimeasyalign/
Here is a link to easy align with instructions:
https://github.com/junegunn/vim-easy-align

Related

Vim: Display similar snippets in a highly efficient manner

Summary
Is there a "find similar snippets" plugin is available for VIM, OR ALTERNATIVELY,
is there a plugin for vim which could easily be extended to do this efficiently?
Details
I realize this is a strange question to ask without context, so here is the context. I'm open to other solutions to the same problem if a "vim plugin" isn't ideal.
I generally do a lot of grepping when working on a new project. Is there a way inside of vim, that i can "grep" and display several snippets (the 2 lines above/below) for a particular string which im currently highlighting.
Clarification: For example, in this post, If i highlighted "inside of vim", I'd like to see (in the VIM window) the results of grep -r -B 2 -A 2 "inside of vim".
The hard part here is of course (1) the visualization pop up and (2) having the shortcut to type when text is selected, otherwise its easy to grep for this kind of thing in a separate terminal. I generally find "CTRL+N" is VERY useful largely because the 2nd dimension it adds for auto-completion, and im mostly looking for an extension of it which shows a glimpse of similar code snippets in other files of a directory.
You probably want the CtrlSF plugin. Try it, you'll be impressed.
On a side note, CtrlSF can make use of ack and ag. These are essentially improved versions of grep, tuned up for programming. Take a look at those too, they will change your programming life for the better.
There are also Ack and Ag plugins that can interface Vim with ack and ag directly, which work by putting the output of said programs in quickfix lists. However, CtrlSF does all that and much more.

Vim: customize tex equation highlight

How do I force vim to highlight the following environment:
\begin{dmath*}
2 + 2
\end{dmath*}
the same way as
\begin{equation*}
2 + 2
\end{equation*}
?
i.e I want the dmath environments (in its plain and starred versions) to be highlighted the same ways as the equation (plain and starred) environment.
I pasted your question into Vim, :setf tex, and then used the SyntaxAttr.vim - Show syntax highlighting attributes of character under cursor plugin to find out that the corresponding syntax group name is texMathZoneES.
Then I opened $VIMRUNTIME/syntax/tex.vim and searched for it. I didn't find that directly, but something like this:
call TexNewMathZone("E","equation",1)
Then I looked up :help ft-tex-syntax (completed from the command-line via <C-D>), and found under :help tex-math a nice documentation. With that, I created the following solution:
call TexNewMathZone("M","dmath",1)
You can put that into ~/.vim/after/syntax/tex.vim, as suggested, to make it permanent. Easy, isn't it?!

VIM Editor: How to do auto formatting in VIM?

I am new to VIM, so still learning. The thing I wanna do is instead of using tabs, I wanna to use 2 spaces to replace A tab. I wanna apply this format to my entire java code. How would I do it? Thanks!
Updated I used this following and it worked
:%s/\t/ /
There are many ways of replace tabs with spaces. If you want to use search-and-replace, you need the :s command. Try typing ":help :s" for help. You'll find that the following works:
:%s/<ctrl-v><tab>/ /g
There is a builtin :retab
You can also use gg=G to reindent the entire source file.
You may use the = command to format code, if you indent a line with two spaces, the following lines may be indented with 2 spaces if you use the =<movement> command on them.

Vim: map GNU Screen command

Apologies if this has been asked before, but I feel overwhelmed with the Vim docs and I can't seem to figure this out.
I want to map the F5 key in Vim to accomplish the following actions:
Yank text from the visual selection in Vim.
Execute the yanked portion of the text in another GNU Screen session named ipython.
The second portion could be achieved by issuing the following command line argument (via :!), if only I was able to find a way to paste the register content between the double quotes of that line (but I can't figure out how):
map <F5> :!screen -x ipython -X stuff "[REGISTER 0 CONTENT]"<CR><CR>
Any help would be much appreciated!
For the second part, you can use
:execute "!screen -x ipython -X stuff " . shellescape(#0)
Here I copy my previous answer:
Maybe one of these two plugins is what you need:
slime is screen-based.
tslime is a tmux-based version of slime.
Given the nature of your question - I encourage you to take a look at vim-ipython. Using this plugin, you can send lines or whole files for IPython to execute, and also get back object introspection and word completions in Vim, like what you get with: object?<enter> and object.<tab> in IPython.
If you follow that github link, there are a few screencasts demonstrating what you can do with it. It requires IPython 0.11 or later, though, with ZeroMQ enabled.

Run bash command on Vim and copy result to clipboard

How can I create a Vim command and copy it's results to clipboard?
I want to convert Markdown to HTML and copy the result to the clipboard. So far I got:
nmap md :%!/bin/markdown/Markdown.pl --html4tags
But this will substitute my opened file on Vim to the result of Markdown.
You didn't say which system you're using, but generally saving it in the +
register should work. You can call system():
:let #+=system("markdown --html4tags", join(getline(1,line("$")), "\n"))
The system() function takes the second parameter (optional) as input to the
command, and here I'm using a chain of other functions to retrieve the contents
of the current buffer. Not sure, but there should be a better way to do it (if
someone knows, please let me know).
Alternatively, you can pass markdown your file name as input directly:
:let #+=system("markdown --html4tags " . shellescape(expand("%:p")))
But keep in mind that you'll need to write the file before calling this.
Two important notes:
I didn't type your full path to markdown. Use it.
I didn't use maps here, the final result would be something like:
nnoremap md :let #+=system(...)
get the xsel package
and pipe stdout to xsel --clipboard
For instance:
cat /etc/passwd | xsel --clipboard
Is that what you're looking for?
Filling in a missing piece (2+ years late). With the clarification that the user was on a Mac and since the asker's "why doesn't it work for me?" question was not answered.
To redirect the output of a command to the system clipboard from within MacVim (GUI version) you need to set the '*' to be the "clipboard register" you need to change the clipboard setting to 'unnamed':
set clipboard 'unnamed' # 'cb' can be substituted for 'clipboard'
Then sidyll's answer should work except specify the '*' register and not the '+' register:
:let #*=system(...)
The clipboard feature is likely not compiled into the "terminal version" of MacVim and when it is available option setting is different from 'unnamed'. To see more details regarding what works where and how, see the documentation in MacVim using the Vim help command:
:help 'clipboard' (include the single quotes since it's a set option!)
(I'll skip the command mapping issue since it always takes me several tries and I still have to look it up; finding the help for the mapping commands should be easier than finding it for the * register.)

Resources