junegunn / vim-easy-align Goto Github PK
View Code? Open in Web Editor NEW:sunflower: A Vim alignment plugin
:sunflower: A Vim alignment plugin
I often need to align around the = sign within a paragraph. I created a function to do this operation and mapped it to a leader
key.
Perhaps this is useful for others
I do like the plugin, but after some testing and wanting to align a paragraph after --> as column delimiter, I couldn't find out how. So i thought: why not let the liveEditing accept any string as delimiter followed by and then match the lines according to the string entered.
Hi, great plugin, thanks for creating it.
I have a question about the mappings. I'd like both visual and normal mode mappings to use the same key.
At first I thought that could be <enter>
so I had these mappings:
vmap <Enter> <Plug>(EasyAlign)
nmap <Enter> <Plug>(EasyAlign)
I quickly realized how foolish is that. After opening a quickfix window I couldn't select a file (because enter
was remapped). Doh.
I've since started using pipe character |
for both visual and normal mode. But that's not as nice as enter
, especially since this plugin also uses enter
for right and center alignment.
So a question: do you know of a way to use enter
mapping for normal mode but in a way that it does not mess up quicklist?
Also, are there other scenarios where nmap <enter>
would be an issue? (if yes, is there a way around it?)
Thanks for the help!
# vim: set filetype=yaml:
---
cdh_version: 4.2.1
Following your recommendation here I have the following mapping:
nmap <Leader>& mz<Plug>(EasyAlign)ip*&`z
When calling the mapping I would like to suppress the
:EasyAlign *&
message that is returned in the command line (as seen in the image)
Is there a way to do this? I tried adding <silent>
to the mapping definition but it does not work.
Thanks!! (awesome plugin btw)
Hey! I saw the last commit implementing recursive alignment (if I read right).
I get it right, it should be able to help transform something like:
class Offer
include DataMapper::Resource
property :id, serial
property :title, string, required: true
property :description, text, required: true
property :company_name, text, required: true
property :company_logo, string, length: 250
property :location, text, required: true
property :starting_date, datetime
property :created_at, datetime
end
Into something like:
class Offer
include DataMapper::Resource
property :id, serial
property :title, string, required: true
property :description, text, required: true
property :company_name, text, required: true
property :company_logo, string, length: 250
property :location, text, required: true
property :starting_date, datetime
property :created_at, datetime
end
Am I right? If so, I'd like to know how to use it. If not, can someone explain to me what I missed? :)
For the record, all I've managed to get is:
class Offer
include DataMapper::Resource
property :id, serial
property :title, string, required: true
property :description, text, required: true
property :company_name, text, required: true
property :company_logo, string, length: 250
property :location, text, required: true
property :starting_date, datetime
property :created_at, datetime
end
I really like this plugin, and the interactive mode is very useful!
One thing that would be very cool, though, would be to have a realtime interactive mode. With this I mean that the selected table/lines would be aligned in realtime in an interactive mode. Something like:
I don't know how involved this is, but I noticed that I have already often needed several attempts to tweak my desired aligning. I think it could be very useful to tweak in realtime.
The error message refers to do_align
at:
{ 'pivot_len': 0.0, 'token_len': 0, 'just_len': 0, 'delim_len': 0, 'indent': 0, 'tokens': 0, 'strip_len': 0 }
The error message disappears, when I change 0.0
to '0.0'
in the named function, but of course then the alignment does not work at all. I also tried with an integer instead of a float with the same result as with the string.
What I did:
vip
<Enter>
<Space>
I use Vim 7.3.547 on Ubuntu Linux. I also have lightline and fugitive installed.
What am I missing?
Since f6586ba, repeating an alignment in visual mode using <Plug>(EasyAlignRepeat)
doesn't work if the first alignment was done in live visual mode. It appears to do the alignment and then immediately undo it. For example:
vmap <CR> <Plug>(LiveEasyAlign)
vmap <C-^> <Plug>(EasyAlignRepeat)
operating on this text:
1 let VCSCommandCVSExec = ''
2 let VCSCommandCVSDiffOpt = '--internal-diff'
3 let VCSCommandBZRExec = ''
4
5 let VCSCommandSVKExec = ''
6 let VCSCommandDisableMappings = 1
If I select lines 1-3 and press <CR>==
it aligns the =
s, but then if I select 5-6 after that and press <C-^>
the problem described above happens.
I tried to fix it but could only cause more problems to show up in the Vader tests.
If you're using tabs to indent instead of spaces the functionality is strange.
Ex (» denotes beginning of tab)
» » a = 1
» » » b =2
» » » c = 4
» » » » f=4
Running :EasyAlign= results in this
» » a = 1
» » » b = 2
» » » c = 4
» » » » f = 4
Running an align on = using shallow or deep indentation removes tabs and uses spaces. Ex:
a = 1
b = 2
c = 4
f = 4
Is there a way to align using the N-th parameter such as:
-) or 2=
Inside of the easy_align_delimiters variable? What I'm looking to do is:
let g:easy_align_delimiters =
{
'pattern' : ')',
'left_margin' : 1,
'right_margin' : 0,
'stick_to_left' : 0,
'n-th_param' : '-'
}
Or something similar...
Having some trouble aligning javascript comments like so:
var clientId = null; // chrome extension address
var connection = null; // connection to the mooltipass
var connected = false; // current connection state
var version = 'unknown'; // connected mooltipass version
var authReq = null; // current authentication request
I tried the regexps //
, \/\/
, \\/\\/
and \\\/\\\/
I was wondering if the plugin could be extended by adding alignment to comments. Like in the following python code:
var1 = 10 # This is a variable
var2 = 1000 # This is another variable
Which would produce:
var1 = 10 # This is a variable
var2 = 1000 # This is another variable
Also, for comment using /**/. Like
/*
* This is a comentary
*/
Which would became
/*
* This is a comentary
*/
In the R language, it is common practice to use the combination <-
for assignment. It would be nice if there were a way to align on this.
Example:
x <- 5
something.longer<- 83
becomes
x <- 5
something.longer <- 83
Could you suggest an easy way to achieve this using vim-easy-align?
"Unknown delimiter:" when pressing again to toggle right-justification
What's the matter? How to use right justification?
let g:EasyGrepReplaceWindowMode=2 " autowriteall all changes during a search and replace session
let g:EasyGrepOptionPrefix='<leader>e' " shortcut to turn on and off certain grepoptions
let g:EasyGrepRecursive=1 " turn on recurse option for replacement
let g:EasyGrepCommand=1 " using system 'grepprg' instead of 'vimgrep
Better would be:
let g:EasyGrepReplaceWindowMode=2 " autowriteall all changes during a search and replace session
let g:EasyGrepOptionPrefix='<leader>e' " shortcut to turn on and off certain grepoptions
let g:EasyGrepRecursive=1 " turn on recurse option for replacement
let g:EasyGrepCommand=1 " using system 'grepprg' instead of 'vimgrep
My solution doesn't work:
let g:easy_align_delimiters = {
\ '"': { 'pattern': ' \(\S\+\s*[;=]\)\@=', 'left_margin': 1, 'right_margin': 1, 'stick_to_left': 0 } }
Are there any resources where I can look up those things?
Hi,
I like your plugin! I've been using Tabular, and happened to stumble upon this plugin by chance, and I think I will make the switch!
My request is to add &
as a predefined delimiter. I know that I can use regexp with <CTRL-X>
and that I may define custom patterns myself, but I still feel like the &
for LaTeX tables and environments is important enough that it should be included by default.
The documentation is quite good, but it lacks a table of contents to make it easier to find what your looking for.
I have this snippet of code:
call s:Color('CtrlPNoEntries', 'base7', 'orange') " there are no entries
call s:Color('CtrlPMatch', 'green') " the matching part
call s:Color('CtrlPLinePre', 'base2') " the '>' in the match window
call s:Color('CtrlPPrtBase', 'magenta') " wat
call s:Color('CtrlPPrtText', 'cyan') " the text in the prompt
I'm trying to align it in order to become this:
call s:Color('CtrlPNoEntries', 'base7', 'orange') " there are no entries
call s:Color('CtrlPMatch', 'green') " the matching part
call s:Color('CtrlPLinePre', 'base2') " the '>' in the match window
call s:Color('CtrlPPrtBase', 'magenta') " the wft
call s:Color('CtrlPPrtText', 'cyan') " the text in the prompt
I tried using <C-x>
in interactive mode and insert "
as a regex, but it doesn't seem to work. I also tried this:
let g:easy_align_delimiters = { '"': { 'pattern': '"' } }
but neither did this.
The only way I managed to make it work is by using "
as the regular expression (note the two spaces), which however leaves me with extra spaces surrounding the double quotes, like this:
call s:Color('CtrlPNoEntries', 'base7', 'orange') " there are no entries
Am I doing something wrong? Thanks in advance, and great plugin btw!
Thanks for the work on this great plugin, much appreciated!I have a question, for example:
This is (example)
Yet another (example)
When I visual select that block, and align on the key ), it is an unknown delimiter key for EasyAlign.
In the very well written EasyAlign documentation, I see this are the only known delimiter keys:
Delimiter key (a single keystroke; <Space> , `=`, `:`, `.`, `|`, `&`, `,`)
So I want to be able to add custom delimiter keys like '(' or '[' or ", or even in future cases, characters like 'e' or 'o'.
Any thoughts on this?
Hello,
The One-minute guide
works for me, but not as showed in the initial gif animation.
I receive the error Unknow delimiter key: x
4 times, where x is {g,a,i,p}
and EasyAlign(_)
isn't populated.
vim 7.4.540
urxvt 9.2
Edit: Oh, my bad. That's more easy than I tought, awesome.
I think it's a good idea to specify in README how does this module differ from it's competitors (f.i. tabular)
I expected text to be aligned with these operations, but the text was not changed, while no error was raised.
Am I missing something?
Select a chunk of text with visual mode
language_model translation_table
test_set test_references
tune_set tune_references
(to suppress other plugin as possible), call :'<,'>EasyAlign \␣
I'm using MacVIM 7.4, if that matters.
Thanks!
I want to align some comments inside my .vimrc:
autocmd BufNewFile,BufRead *.sql set filetype=mysql " force mysql highlight
autocmd FocusLost * silent! :wa " addition to autowriteall
When I select them, press Enter, then Ctrl-X for a regular expression and then Enter again. Command line shows :EasyAlign /"/
and comments are not aligned. Neither it works with \%x22
(char code for "
) as regex.
How about a special keystroke, such as i
(perhaps too naive, say <c-i>
) that allows one to enter interactive mode after <plug>easyalign
? In this way one can halve the mappings needed to invoke easyalign in all its variants.
Hi, is there any reason # isn't a default alignment? Seems very useful.
I tried using both # and # as a regexp, neither worked. Any idea how to align # comments?
Thank you!
I found it not so easy to type EasyAlign full, with the shifts and so on.
Is there a possibility to have a alias. Like
<,'>Ea=
instead
<,'>EasyAlign=
If a delimiter exists but is in an ignored group, undo will be triggered when no changes have been made, and it undos another level for every attempted change in the command. For example:
printf("foo = %f\n", foo);
printf("foobar = %f\n", foobar);
Using <Plug>LiveEasyAlign
to align the =
s makes no change because the =
s are in strings, but undo is triggered anyway. Easy enough to fix that I don't want to fork the repository:
diff --git a/autoload/easy_align.vim b/autoload/easy_align.vim
index dbaa73f..e0730f2 100644
--- a/autoload/easy_align.vim
+++ b/autoload/easy_align.vim
@@ -640,7 +640,9 @@ function! s:interactive(range, modes, n, d, opts, rules, vis, live, bvis)
let output = s:process(a:range, mode, n, d, s:normalize_options(opts), regx, a:rules, a:bvis)
let &undolevels = &undolevels " Break undo block
call s:update_lines(output.todo)
- let undo = 1
+ if !empty(output.todo)
+ let undo = 1
+ endif
let rdrw = 1
endif
if rdrw
lr* -> lrrr...
lr** -> lrlrlr...
I have mapped CR to EasyAlign in visual mode, but sometimes I get sloppy with my fingers and accidentally select and hit enter. Sometimes I do this in plugin buffers (like gitv) that are not normal editing buffers (and have enter mapped to command). This start EasyAlign, but that doesn't make sense in that buffer.
Since EasyAlign cannot complete the operation in a 'nomodifiable' buffer, maybe it should do nothing (immediately exit)?
(My workaround solution is to unmap EasyAlign in that buffer, so this is not a big deal for me.)
I wanted to use easy-align on a LaTeX table that looks like this:
\begin{tabular}{lrr}
\toprule
Parameter & & Value \\
\midrule
$p_0$ & & \SI{8}{bar} \\
$T_0$ & & \SI{30}{\degreeCelsius} \\ \\
\multicolumn{3}{l}{Some text} \\
Component & Amount [\si{kg/h}] & Amount [\%] \\
\midrule
\CO & \num{33111} & \num{4.80} \\
N$_2$ & \num{333} & \num{77.06} \\
O$_2$ & \num{333391} & \num{16.83} \\
Argon & \num{1122} & \num{1.31} \\
\bottomrule
\end{tabular}
However, \multicolumn
kind of screws this up by making the first column way to wide. I was wondering if it would be possible to add more options to a given pattern to ignore certain kinds of lines, for instance in this case to ignore lines with \multiline
.
For example, in OCaml you often have code like:
match xxx with
| [] -> ...
| x::y::xs -> ...
| _ -> ...
How would I align on the ->
token using this plugin?
I found a break
at autoload/easy_align.vim
line 846, without while
or for
statement.
How would I go about doing two different alignments? For example, given the following coffeescript:
user: Ember.belongsTo('models.User', key: 'user', embedded: true)
cost: Ember.belongsTo('models.Cost', key: 'cost', embedded: true)
booking: Ember.belongsTo('models.Booking', key: 'booking', embedded: true)
pageTab: Ember.belongsTo('models.pageTab', key: 'page_tab_id')
I'd like to first align the keys, then align the arguments in Ember.belongsTo
, like so:
user: Ember.belongsTo('models.User', key: 'user', embedded: true)
cost: Ember.belongsTo('models.Cost', key: 'cost', embedded: true)
booking: Ember.belongsTo('models.Booking', key: 'booking', embedded: true)
pageTab: Ember.belongsTo('models.PageTab', key: 'page_tab_id')
Hi,
I have not looked at the code for vim-easy-align
, so I am not sure to which extent it is optimized or not. However, when I use the :EasyAlign
command for relatively complex tables that spans multiple lines and columns, I find it is rather slow. If there is any chance of optimizing the code for more speed, that would be great!
- Repeating visual-repeat
When repeating a Visual mode operator, the operator will be applied to the
same amount of text as the last time:
- Linewise Visual mode: The same number of lines.
- Blockwise Visual mode: The same number of lines and columns.
- Normal Visual mode within one line: The same number of characters.
- Normal Visual mode with several lines: The same number of lines, in the
last line the same number of characters as in the last line the last time.
The start of the text is the Cursor position. If the "$" command was used as
one of the last commands to extend the highlighted text, the repeating will
be applied up to the rightmost column of the longest line.
Hi,
Is it possible to select a range of delimiter, for example the 1st and 2nd delimiter without having to repeat the EasyAlign command for each delimiter?
It would be very nice to be able to add an ignore expression during aligning. For instance, given the following code:
print *, 'Plotting isentrope data:', trim(fname) // 't_p.dat'
call plot(ta, 'T', pa/1.0e5, 'p', trim(fname) // 't_p.dat')
print *, 'Plotting isentrope data:', trim(fname) // 'p_u.dat'
call plot(pa/1.0e5, 'p', ua, 'u', trim(fname) // 'p_u.dat')
print *, 'Plotting isentrope data:', trim(fname) // 'p_c.dat'
call plot(pa/1.0e5, 'p', ca, 'c', trim(fname) // 'p_c.dat')
print *, 'Plotting isentrope data:', trim(fname) // 'a_p.dat'
call plot(aa, 'A', pa/1.0e5, 'p', trim(fname) // 'a_p.dat')
print *, 'Plotting isentrope data:', trim(fname) // 'a_u.dat'
call plot(aa, 'A', ua, 'p', trim(fname) // 'a_u.dat')
print *, 'Plotting isentrope data:', trim(fname) // 'a_c.dat'
call plot(aa, 'A', ca, 'p', trim(fname) // 'a_c.dat')
print *, 'Plotting isentrope data:', trim(fname) // 'b_a.dat'
call plot(beta(:,2), '%', aa, 'A', trim(fname) // 'b_a.dat')
It would be very nice if I could select all lines, then start LiveEasyAlign, align on ,
, then add an ignore expression, for instance with <CTRL-I>
and ignore all lines that start with print
.
Shouldn't this follow regular expression rules and differentiate on letter case?
Given the following unformatted SQL:
SELECT tt.something,
tt.something_else,
tot.something,
tot.something_else
FROM this_table tt
JOIN this_other_table tot
ON tot.table = tt.table
I'd like the following final result:
SELECT tt.something,
tt.something_else,
tot.something,
tot.something_else
FROM this_table tt
JOIN this_other_table tot
ON tot.table = tt.table
However, the command :EasyAlign /[A-Z]*/
matches lower and upper case, providing the following:
SELECT tt.something,
tt .something_else,
tot .something,
tot .something_else
FROM this_table tt
JOIN this_other_table tot
ON tot.table = tt.table
The command :EasyAlign /[a-z]*/
provides the same results:
SELECT tt.something,
tt .something_else,
tot .something,
tot .something_else
FROM this_table tt
JOIN this_other_table tot
ON tot.table = tt.table
Hi @junegunn!
Thanks for a nice plugin :). The latest version has an incorrect help file with tag: "easy-align-examples" occuring twice. It results in E154: Duplicate tag
when the :helptags
has been performed.
All the best
szw
I added 's': { 'pattern': "'" }
and 'd': { 'pattern': '"' }
to g:easy_align_delimiters
, however it doesn't work, any suggestions?
I've compiled vim from sources with all the patches, and when I try to use easy-align all that happens is that the cursor move to the first line / first column of the file. the text I selected is not aligned at all.
It looks like the problem appeared with one of the latest patches (e.g. patch 530 seems to have modified something about ranges), but I'm not sure which one or how I can discover it. If you need some help just ask, I'll do some more tests.
here's my vim version:
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Nov 28 2014 09:00:28)
MacOS X (unix) version
Included patches: 1-537
Compiled by Homebrew
Huge version without 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 -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
+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"
fall-back for $VIM: "/usr/local/share/vim"
Compilation: /usr/bin/clang -c -I. -Iproto -DHAVE_CONFIG_H -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -DMACOS_X_UNIX -Os -w -pipe -march=native -mmacosx-version-min=10.10 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: /usr/bin/clang -L. -L/usr/local/lib -L/usr/local/lib -Wl,-headerpad_max_install_names -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -o vim -lm -lncurses -liconv -framework Cocoa -fstack-protector -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE -lperl -framework Python -lruby.2.0.0 -lobjc
Think I found an edge-case
Running :EasyAlign= on this (_ spaces in indent area, » tabs in indentation)
» » n2f = {}
» » n2v = {}
» » f2v = {}
» » n2gv = {}
» » n2vt = {}
Yeilds this
_» » n2f = {}
_» » n2v = {}
_» » f2v = {}
_» » n2gv = {}
_» » n2vt = {}
When using ruby in a DSL like way, I'd like to align:
many_to_one :workspace
many_to_many :resources,
:join_table => :asset_resources
to:
many_to_one :workspace
many_to_many :resources,
:join_table => :asset_resources
I'd like to specify the column where to align the semi colon.
How can I do that?
If I'm calling EasyAlign with a delimiter alignment option, like :EasyAlign {'a':'l'}
, I'm getting the following error:
:EasyAlign (_) {'a': 'l'}
Error detected while processing function easy_align#align..<SNR>172_align..<SNR>172_interactive:
line 55:
E716: Key not present in Dictionary: m, 1)
E116: Invalid arguments for function strpart(opts.m, 1)
E15: Invalid expression: mode . strpart(opts.m, 1)
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.