Hot answers tagged

16

If you mean you want to keep every 10th line and delete the rest: %norm 9ddj Explanation: % whole file norm execute the following commands in "normal mode" 9dd delete 9 lines j move down one line (i.e. keep it) note: this deletes the first row. Adapted from http://www.rayninfo.co.uk/vimtips.html Or using the global command: Duplicate the first ...


12

:2,$v/0$/d deletes the lines that don't end in 0 starting from the second one.


6

In the replacement side of vim substitution, a newline is represented by \r. Thus, try: %s/\n\n/#\r\r/g The resulting file will look like: elephant# rhino# giraffe# /* animals who live in Africa */ In the first half of a substitute command, \n is a newline and \r is a carriage return. By contrast, in the replacement side of the command, \n is a ...


5

This might be best suited to http://vi.stackexchange.com/ But anyhow, :h :sort actually explains what is happening in there: If a {pattern} is used, any lines which don't have a match for {pattern} are kept in their current order, but separate from the lines which do match {pattern}. If you sorted in reverse, they will be in reverse order after the sorted ...


4

You can put the following lines in your vimrc to quit vim if any of its arguments are a directory: for f in argv() if isdirectory(f) echomsg "vimrc: Cowardly refusing to edit directory " . f quit endif endfor Alternatively, if you only want to quit if all arguments are directories, you can try something like this: let ndirs = 0 for f in argv()...


3

You can position the cursor on the first match using the -s (script) option. According to the vim manual: -s {scriptin} The script file {scriptin} is read. The characters in the file are interpreted as if you had typed them. The same can be done with the command ":source! {scriptin}". If the end of the file is reached before the editor exits, ...


2

you can set global parameter in your .vimrc set hidden or specify hidden attribute for selected buffer using bufhidden. When the buffer is hidden (not abandoned like default) when you modify it outside vim you will be noticed that some changes occured and you can load new content or discard this changes.


2

The command you are looking for is args: For example: :args /path_to_dir/*.py or :args /path_to_dir/**/*.py ** to match files recursively. (As suggested by @the_velour_fog) will open all files which has .py extension in the directory. Once the files are opened use :tab all to put them in individual tabs.


2

On most installation I have come across: ALT-something is the same as: ESC (release after press) something So, vim commands are always "ALT-Prefixed". But, as you have found out in the meantime, there is a way to specify this key combination in the vimrc.


2

To complement grochmal's fine answer, you could use :sort!n/.*=\|^/ Or: :sort!n/[^=]*$/r To get the desired result. As to why \= gives you an error, is because it's a special regex operator in vim. It's the same as \? except that it can also be used in the ? command. .*\= same as .*\? would then be an invalid regexp.


1

:sor! n /\(^[0-9]\+$\|=.*\)/ r You were very close. You just missed a '\' before '+'.


1

Question had been solved at stackoverflow.com: Adding noremap <Esc>a h noremap <Esc>s j noremap <Esc>w k noremap <Esc>d l to .vimrc solved the problem.


1

You can use a shell script to hold the options, and set your editor variable to that. For example #!/bin/sh vim -c "set fo+=aw" "$@" The Mutt FAQ suggests a similar approach in How to trim quoted replies (like stripping signatures)?, though this is not generally material for an FAQ.


1

The screenshots in the question do not show dtterm (some people are confused by the ability to set the TERM environment variable to dtterm, xterm, etc., while using other programs, supposing that those other programs are identical to dtterm, xterm). Here's a screenshot for instance from Oracle's documentation: Given that, it is unclear what actual ...



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