55
votes
How to add indentation guides/lines?
Another option I use, which isn't exactly what you asked for, but accomplishes the same purpose of making it easier to see what is in the same column, is to set the following in your vimrc:
set ...
13
votes
Accepted
Align a block of code on the basis of a single character
If you're in a pinch and want to get the expressions aligned, without having to install and learn any plug-ins, here is a quick way to do it.
Select the lines on a visual selection. For example, if ...
12
votes
How can I easily create and maintain tables?
If you don't want to install any plugins and you want to edit tables keeping the alignment:
-- use the built in VREPLACE mode, activated by gR.
(Make sure you has vim latest version, and check if it's ...
11
votes
Accepted
How do I align C++ comments to be compliant with Google styling?
clang-format is a command line tool that formats c++ code. One of the default formatters is google.
clang-format -style=google
There are plugins that would allow you to run clang-format in vim. One ...
10
votes
Accepted
How to left-align two columns of text?
See accepted answer to Align a block of code on the basis of a single character
To recap
ggVG to select all
:'<,'>normal f:5a you don't have to enter '<,'> and also note space at the end....
10
votes
Accepted
How to sort lines by the right most characters?
If you can use the rev command, you could reverse each line, sort and reverse again, using external commands in a pipe:
%!rev | sort | rev
This can be done entirely in Vimscript, but it's way more ...
8
votes
Accepted
How to align statements around a particular word or token?
The Tabular plugin works with regular expressions. So, you can give a word or a pattern, not just a single character.
:Tabularize /from/
will align in the way you wanted.
You can find a great ...
6
votes
How can I easily create and maintain tables?
I've created the command-line tool tablign for this purpose; it works from within vim as well. Simply install with
[sudo -H] pip3 install tablign
mark the table in vim and call
:'<,'>:!...
6
votes
How to add space around a symbol using vim?
I'm not sure why you don't want to use search/replace, but here's a reusable command:
command! HTMLArgEq %s/\s\@<!=\+\s\@!/ \0 /g
It uses search/replace, but you only need to create it once. ...
6
votes
Accepted
simple map to right align text selection within visual block?
Here's a simple mapping to do the task:
vnoremap <silent> rs "zy:call setreg("z", system("echo \"" . @z . "\" \| sed 's/[ \\t]\\+//' \| rs -j 0 1"), "b")<CR>gv"zp
It uses z register to ...
5
votes
Accepted
How to move word under current cursor to begin at current cursor?
Without entering insert mode (not sure if it's better though):
Example text (cursor on C of the first line):
A BBCBB
A BBCBB
Type:
bjywkP
Decomposing:
bj go back to the start of the word,...
5
votes
How to add space around a symbol using vim?
Here's what I would do. Visually select all of your HTML you want to do this to, and hit the following:
:norm f=i<space><C-v><esc>la<space>
Note that <C-v>, <esc>,...
5
votes
Accepted
Is it possible to align the results in the quickfix list in columns
Some more searching yielded the qf-layout plugin, which is working great in my initial tests!
In order to show only the basename instead of the entire filepath, I modified line 84 from
let l....
5
votes
Is it possible to align the results in the quickfix list in columns
If your Vim includes the patch 8.2.0959, you can set the 'quickfixtextfunc' option to the name of a Vimscript function whose task is to format each entry displayed in the quickfix window.
To get the ...
5
votes
Working with line continuations (\).
Plugin vim-lion
by Tom McDonald
Install and add following line to your vimrc:
let g:lion_squeeze_spaces = 1
Now you can change
#define SOME_FUNCTION_LIKE_MACRO(a,b) \
foo(a); ...
5
votes
Align a block of code on the basis of a single character
The answer provided by filbranden shows the sequence in general. Though, it is quite complicated. The most interesting part there is command normal. So, I would simplify and generalize the whole ...
4
votes
Accepted
Align C preprocessor definitions
You can use :<range>Align \s which will use the white spaces as separators. It will give you the following:
#define ORING 'r'
#define OLRING "ring"
To align only the part between the ...
4
votes
How to add indentation guides/lines?
Try the most recent updated of Goneovim, not the current release 0.4.6.
It's not pure vim but a neovim gui, and it does not gain much attention.
The indent guides feature of goneovim is native, and ...
4
votes
Can I justify text in Vim?
Here are two easy options:
with a block of text selected, type !fmt
with your cursor at the start of a block, type !}fmt
Both of these send a block of text to unix fmt, see man fmt for options. You ...
4
votes
How to add indentation guides/lines?
The indentLine plugin tends to be fairly slow on non-small files, observable when clicking enter as it lags by a second or so.
I've found vim-indentguides to be a faster and visually similar plugin, ...
4
votes
Accepted
Align code functions documentation
Vim's comment formatting only handles
comment characters that appear at the
start of the line. However you could make
use of the list formatting facility (:help 'formatlistpat')
that kicks in when n ...
4
votes
Align a block of code on the basis of a single character
Install vim-easy-align, assume you bind <Plug>(EasyAlign) to ga, execute gaip=, done.
This plugin comes with a lot of predefined rule to handle common align scenarios.
Another way to do this is ...
4
votes
Accepted
How to position cursor at a particular column (beyond the end of the line)?
You can put set virtualedit=all in your vimrc to allow cursor to be
positioned anywhere, even where there are no chars, and then you can use the
normal mode command 80| to move the cursor to the 80th ...
3
votes
How can I replace a word in a column without changing the width
If you were using Vim them you could use some alignment plugin, as mentioned on the question comments. Or you could use the vimwiki plugin, which provides several helpers to use tables.
As you are ...
3
votes
How to add space around a symbol using vim?
Search and replace can be used, but I must admit, the syntax is not simple to remember:
:%s/\s*=\@<!==\@!\s*/ = /g
The first \@<! matches with zero width if the preceding atom doesn't match = (...
3
votes
How can I set up a ruler at a specific column?
I mostly do coding in vim (version 7.4) and I have added the below two lines in my .vimrc to maintain a "colorcolumn" for 100 character length.
:set colorcolumn=100 ...
3
votes
Accepted
Using Align plugin
\adec is not a parameter to :Align, it is a key mapping.
Don't type :Align \adec
Just hit the keys \adec
3
votes
Accepted
How can I right-align end-of-line comments with the Tabular plugin?
Just figured this out and wanted to share with people. You can use
:Tabularize /^\s*\S.*\zs#
where the ^\s*\S.*\zs# is a vim regexp that matches only the last comment character, while ignoring ...
3
votes
simple map to right align text selection within visual block?
What about doing the substitution on the visual selection with \%V, and avoiding external programs?
For instance, the following does the job (I'll use \v to simplify the patterns):
'<,'>s/\v%V(...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
alignment × 52indentation × 8
formatting × 7
plugin-tabular × 4
plugin-easy-align × 4
ascii-art × 4
key-bindings × 3
neovim × 3
comments × 3
vimrc × 2
visual-mode × 2
insert-mode × 2
plugin-system × 2
wrapping × 2
tab-characters × 2
word-processing × 2
regular-expression × 1
substitute × 1
normal-mode × 1
colorscheme × 1
replace × 1
filetype-tex × 1
quickfix × 1
scrolling × 1
visual-block × 1