Skip to main content
39 votes

How can I display tabs as characters?

Highlighting tabs Temporary Tab highlighting For occasional use, one can simply highlight all tabs in a document using the following search / command: /\t To remove the highlighting, simply type :noh ...
Serge Stroobandt's user avatar
35 votes
Accepted

Setting TAB to 2 spaces

Have you sourced your .vimrc since making these changes? When having vim open just type source ~/.vimrc (assuming it is in it's default location) EDIT: This could help too
Gleland's user avatar
  • 521
23 votes
Accepted

How to remove Neovim trailing white space?

This should do the trick: vim.api.nvim_create_autocmd({ "BufWritePre" }, { pattern = { "*" }, command = [[%s/\s\+$//e]], }) Be sure to read the h:nvim_create_autocmd() for ...
InsertSON's user avatar
  • 426
15 votes
Accepted

What is the rationale for \r and \n meaning different things in s command?

At the most basic level, there's already an asymmetry between the search and replace portions of :substitute because the former is a regular expression and the latter is text, with specific additional ...
jamessan's user avatar
  • 11.2k
10 votes

How can I display tabs as characters?

I personally like the use of the plugin indentLine, which displays a vertical line at indentation levels. It is of great help especially in python, where the indentation is important. Among other ...
mike's user avatar
  • 959
10 votes
Accepted

How to show illegal whitespace (such as unbreakable space) in source code?

List & Listchars 'list' is a boolean option that, when set, instructs vim to display whitespace characters. And it is completely customizable using 'listchars'. For example, to show non-breaking ...
D. Ben Knoble's user avatar
  • 27.2k
9 votes

How to split a line into multiple lines efficiently?

The easiest way I've found to split lines in Vim is the normal mode command gq (type both letters in quick succession in normal or visual mode). In visual mode, it will split whatever is selected, in ...
vdicarlo's user avatar
  • 123
9 votes
Accepted

vim search for arbitrary combination of spaces and tabs

If you're looking for a substitute command: :s/a[ \t]\+b/c/ The default regex mode doesn't see + as an operator. You have to escape it to make it special. You can also use: :s/a\s\+b/c/ \s is Vim'...
muru's user avatar
  • 25.1k
9 votes

How do I replace single whitespaces without affecting multi-whitespace such as indentation in Vim?

The substitution is easier to read with word-boundaries in my opinion, and very magic mode makes typing easier: :%substitute/\v>\s+</_/g
D. Ben Knoble's user avatar
  • 27.2k
9 votes

How to remove Neovim trailing white space?

I agree with the accepted answer. Something that begins to annoy quickly is that the cursor position is reset to the beginning of the line. To keep it, one can use getpos/setpos like this: vim.api....
BillGatesPriv's user avatar
8 votes
Accepted

Moving to the end of the last word on a line

g_ will to go to the last non-blank character of the line For more help see :h g_
Peter Rincker's user avatar
8 votes
Accepted

What does breakat&vim mean?

It resets the breakat option to the Vim default: ^I!@*-+;:,./?. Where ^I stands for the tab character. You get the corresponding help paragraph with the :help :set-default command. :se[t] {option}&...
Vivian De Smedt's user avatar
7 votes
Accepted

Expand <TAB> into 2 spaces when and only when editing HTML

Put this in your .vimrc file: autocmd BufRead,BufNewFile *.htm,*.html setlocal tabstop=2 shiftwidth=2 softtabstop=2 Briefly, autocmds get processed when the specified events occur for the specified ...
B Layer's user avatar
  • 20k
7 votes
Accepted

Moved from vim to neovim and now <BS> deletes 4 spaces at a time, instead of 1 as I'm used to. How to fix?

Neovim sets smarttab by default, which will cause this behaviour. Try turning it off: :set nosmarttab
Rich's user avatar
  • 32.4k
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. ...
Tommy A's user avatar
  • 6,800
6 votes

What is the rationale for \r and \n meaning different things in s command?

A NUL byte is a string terminator in C, and for this reason Vim uses this convention, described in the manual at :h NL-used-for-Nul: <Nul> characters in the file are stored as <NL> in memory. ...
Sato Katsura's user avatar
  • 4,019
6 votes
Accepted

Stop vim from removing whitespace on save for diff files

Since there was nothing explicit in my .vimrc that acted on only-whitespace lines and the diff syntax file did no such thing either, this had to with my plugins somehow. I find out that I had an ...
oligofren's user avatar
  • 1,103
5 votes
Accepted

ignoring spaces in search like ignoring cases

You can use a mapping and replace all spaces by e.g. \_s* which would match linebreaks as well. Something like this should work: :func! ReplaceSearch() if getcmdtype() =~# '[?/]' return ...
Christian Brabandt's user avatar
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>,...
DJMcMayhem's user avatar
  • 17.8k
5 votes

How can I display tabs as characters?

You may want to show tabs differently in a regular terminal and gvim. set list! if has('gui_running') set listchars=tab:▶\ ,trail:·,extends:\#,nbsp:. else set listchars=tab:>.,trail:.,...
ideasman42's user avatar
  • 3,783
5 votes

How can I display tabs as characters?

This can be easily achieved using listchars by specifying the tab as: ,tab:\ \ ┊, By providing two escaped spaces in front of your tab declaration, vim will repeat the spaces. This is opposed to the ...
Swivel's user avatar
  • 151
5 votes

Removing redundant whitespaces on save/write

Probably something like that should work: autocmd BufWritePre * :%s/\s\+$// The autocommand triggers :%s/\s\+$// each time a buffer will be written. And the substitution command removes all of the ...
statox's user avatar
  • 50.4k
5 votes

How to remove trailing white-spaces automatically while typing?

I'd do it with an autocommand that fires whenever you leave insert mode: function! PreciseTrimWhiteSpace() " We need to save the view because the substitute command might " or might not move the ...
Rich's user avatar
  • 32.4k
5 votes

How to delete and replace a block of text with spaces?

You can replace every character of your selection with one of your choosing by using r, the replace command. In your case, in visual mode, type r<space>
Biggybi's user avatar
  • 2,780
5 votes
Accepted

How can I make zz not center cursor when approaching end of file?

If you're willing to bring a function into the mix I whipped this up... func! ModifiedZZ() " modify to your liking let l:max_pad_lines = 10 norm! zz let l:to_scr_end = winheight(...
B Layer's user avatar
  • 20k
4 votes

How to join lines without producing a space?

To always join with a single space : nmap J gJi <ESC>ciW <ESC> To join with no space at all (removes trailing+leading space) : nmap <C-J> gJi <ESC>diW
phil's user avatar
  • 41
4 votes

How to join lines without producing a space?

Create a macro and reuse it: qaJxq Now replay the macro, a by using @a wherever you want to join two lines with no space. @@ will repeat the previous macro. So you can just hold @ to join multiple ...
pellucide's user avatar
  • 141
4 votes
Accepted

How to center a cursor on the screen, even at the start of the file?

zz does what you want, sort of, but it doesn't work near the top of the file, nor near the bottom (when the file is too short). There is another way to keep track of the cursor, by highlighting ...
Sato Katsura's user avatar
  • 4,019
4 votes
Accepted

Toggle highlighting of trailing whitespace

Extraneous autocmd First, you told Vim to call your toggle function every time you enter or leave the insert mode. i.e. by using the InsertEnter and InsertLeave events as follows: autocmd ...
grochmal's user avatar
  • 1,666

Only top scored, non community-wiki answers of a minimum length are eligible