The "simplest" way is to just use :substitute: :%s/\s\+$//e :%s to run :substitute over the range %, which is the entire buffer. \s to match all whitespace characters. \+ to match 1 or more of them. $ to anchor at the end of the line. The e flag to not give an error if there is no match (i.e. the file is already without trailing whitespace). ...


Yes, use listchars: set list set listchars=tab:>- If you put these two lines in your .vimrc, tabs will be shown as > for the start position and - through the rest of the tab. (Sidenote: listchars can also show trailing spaces with trail:x (replace x with the character you want to use for a trailing space), which can be useful as well.)


The gJ mapping does this; from :help gJ: Join [count] lines, with a minimum of two lines. Don't insert or remove any spaces. You could rebind it to J, if you want to save a keystroke: :nnoremap J gJ Note that this doesn't remove any spaces, so if either the current line ends with a space or next line starts with one or more spaces they will be left as ...


Use a keybinding to strip all trailing whitespace Since some pages that I edit actually need trailing whitespaces (e.g. markdown) and others don't, I set up a keybinding to F5 so that it's trivial to do without being automatic. To do so, add the code below (from vim.wikia) or some variation of it to your .vimrc: "Remove all trailing whitespace by pressing ...


The basic answer is :set list, which causes tabs to display as ^I. However, I recommend going beyond that. Just :set list is problematic in that it fails to preserve visual alignment on screen. For example: %.o: %.cpp ^Ig++ -c $< doesn't look good, especially when you expect the g of g++ to appear under the first p of cpp (assuming tabstop=8). ...


You want expandtab. But there are usually a couple of options you want to set at the same time. If you add the following to your ~/.vimrc file " tabstop: Width of tab character " softtabstop: Fine tunes the amount of white space to be added " shiftwidth Determines the amount of whitespace to add in normal mode " expandtab: When ...


You are looking for the expandtab option. When this option is set, spaces are always used. You can put set expandtab in your vimrc to always have this option set when vim starts. If you want to only enable this option for specific languages, see this question. For help on this option, see :help 'expandtab'.


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 which is short for :nohlsearch —no high lighting. Permanent Tab highlighting " Highlight tabs as errors. " https://vi.stackexchange.com/a/9353/3168 ...


You could simply replace any consecutive space on the line with a newline using the command :s/\s\+/\r/g. \s\+ mean one or more whitespace characters, and \r is a newline, see :help :substitute and :help regexp for details. If you run the command on a line like: foo bar baz You get: foo bar baz If you have hlsearch enabled and you don't want to clutter ...


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


To delete all trailing whitespace (at the end of each line), you can use the command: :%s/ \+$// To include tabs, use \s instead of space. From the command-line: $ ex +'%s/\s\+$//e' -cwq file.c All the files in the current directory (recursively use **/*.*): $ ex +'bufdo!%s/\s\+$//e' -cxa *.* Python way: :py import vim :pydo vim.current.buffer[linenr ...


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 escape sequences. This is just highlighted by the intuition you have about what \n means. For example, consider that \n in the search doesn't match a literal \...


It gets reset by the Python filetype plugin; from /usr/share/vim/vim74/ftplugin/python.vim: " As suggested by PEP8. setlocal expandtab shiftwidth=4 softtabstop=4 tabstop=8 This file is loaded every time a Python file is loaded. Personally I find adding indentation settings here a bit surprising though. At any rate, to override this use this in your vimrc: ...


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 things, it provides a toggle command, that can be mapped to a key combination, so that you can turn it off, when you don't need it.


It's only a clumsy workaround, but if you :set list the cursor will be positioned on the other "side" of the tab.


Another trick you may try is to use replace. Sometimes this might be useful. %s/$\n//g Scenario: Delete the last character and join with the next line: %s/=$\n\(.\)/\1/g For example, xxxx= 123 becomes: xxxx123


You may want to move to the next section: ]] Documentation: :h paragraph A paragraph begins after each empty line, and also at each of a set of paragraph macros, specified by the pairs of characters in the 'paragraphs' option. :h section A section begins after a form-feed (<C-L>) in the first column and at each of a set of section macros, ...


I've been struggling with that behavior for a long time. Basically, the foreground color of SpecialKey on the current line is changed to the foreground color of Normal if: the cursorline option is enabled, the CursorLine highlight group has a background color set. I've never been able to fix that behavior, no matter what I tried. The problem lies ...


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's shortcut for space and tabs in regex.


The two commands below will reduce every line to the first sequence of non-whitespace character followed by a space: from 0.453945 -2.14126e-54 3.40152e-49 101325 214.355 to 0.453945 <-- space But your question is a little confusing so I'm not sure I understood what you want. With a substitution: :%s/\(\S\+\s\).*/\1 With a macro: :%normal! WD


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 file name patterns. Here we just set the tab values for the current buffer to the desired value in the event of reading or creating a file with .htm or .html ...


The cursor in normal mode is on the character not to either side. So you can do i and a to go to insert mode to the left or right of the tab respectively.


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. Explanation: %s/ - Substitute entire buffer \s\@<! - Not preceded by whitespace =\+ - One or more equal characters \s\@! - Not followed by whitespace / \...


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 EditorConfig file in this project, and in it it had these lines: [*] # other #stuff trim_trailing_whitespace = true I then subsequently added a section for diff ...


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. In the display they are shown as "^@". The translation is done when reading and writing files. To match a <Nul> with a search pattern you can just enter ...


Easiest method is to do :set list, which will show tabs as ^I and end of line as $. I like to use a mapping that calls :set invlist to toggle between regular display and list display. For example: :nmap <leader>l :set invlist<cr> This allows me to quickly check if there are tab vs space problems and then go back to a regular display.


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:.,extends:\#,nbsp:. endif (Adding for completeness, in case others find it useful).


Exapnding on Christopher Bottoms's answer a bit: Jonathan Palardy wrote a good article on this. In it, he writes a functions, Preserve(command), that preserves the state of the editor (mainly cursor position and last search pattern) while running an arbitrary command: function! Preserve(command) " Preparation: save window state let l:saved_winview = ...

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