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.


8

I'm going to say this is not possible because vim is not executing remote commands. It is simply using scp to copy the file over, edit it locally and scp it back when done. As stated in this question sudo via scp is not possible and it is recommended that you either modify permissions to accomplish what you're wanting or just ssh across to the remote machine....


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

With "wq", "!" asks Vim to ignore the read-only attribute. From the documentation: :wq [++opt] Write the current file and quit. Writing fails when the file is read-only or the buffer does not have a name. Quitting fails when the last file in the argument list has not been edited. :wq! [++opt] ...


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()...


4

Like the accepted answer, I don't think this is possible directly. However, I see at least two ways to still accomplish your goal. Running vim remotely ssh user@myserver sudo vim /some/file This has disadvantages: Your interactions with vim go over the network. Significant lag will be annoying, and if your connection dies, so does vim (eventually). ...


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, ...


3

In my answer I will not concern myself with Vim, but instead look at the underlying mechanisms, that you have stumbled upon. It is important to understand these, as it affects the security of your entire system. It has nothing to do with owner: try it, make a file not owned by you, then give your self read not write. You will get the same results. So why is ...


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

You would need the root password or have your public ssh key in ~root/.ssh/authorized_keys. Once you had that, you could probably do vim scp://root@nagios//tmp/notouch Bottom line: this is effectively just a shortcut for scp root@nagios:/tmp/notouch /tmp/notouch vim /tmp/notouch scp /tmp/notouch root@nagios:/tmp/notouch If you have the necessary access ...


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.


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