Tag Info

Hot answers tagged

15

There are several options to do so: You can use a terminal multiplexer like screen or tmux. In screen, for example, the shortcut Ctrl+a - a, has the same functiononality as Alt+Tab in graphical environments: switch to the last screen. Or you use vim's internal function. Type :!command in vim's command mode. For example: :!ls -l. After the command ...


9

Yes there is a way to automate this. And it starts with selecting the right tool, for the job. In this case you should be using e.g sed and not try to bend vi which was designed for interactive use (and not for automation). The replacement syntax for sed is largely the same as the one for vi. sed -i.backup 's/boy/Boy/g' file-name-1 file-name-2 ...


5

You can not do this with vim directly, vim will always resolves the links to find the name of the actual file. From :h E773: For symbolic links Vim resolves the links to find the name of the actual file. The swap file name is based on that name. Thus it doesn't matter by what name you edit the file, the swap file name will normally be the same. You ...


5

Have you tried to use aliases? example Create an alias for the new command: alias ntpversion='ntpq -c "rv 0 version"' Run the command: ntpversion Running ntpversion, after it is set as an alias, will provide the output for your one-liner. http://www.linuxhowtos.org/Tips%20and%20Tricks/command_aliases.htm


5

Vim scripts (gvim,vim) can be elegant and are very easy to adapt vi -s edit.vim test.txt where edit.vim contains (the :wq is optional) :%s/boy/Boy/g :%s/girl/Girl/g :g/^$/d :wq where test.txt contains boys & girls boys & girls boy & girl boys & girls here's a generic vim script to clean up a "mucky" text file :" clean.vim :" ...


4

Why not use sed ? With sed you could easily loop over the files in the directory: for f in *.txt do sed 's/boy/Boy/g;s/girl/Girl/g;/^\s*$/d' $f > tmp mv tmp $f done Above example would change boy->Boy, girl->Girl and delete empty the lines.


4

Without a count, ^ and _ are indeed equivalent, but the latter supports a count: _ <underscore> [count] - 1 lines downward, on the first non-blank character |linewise|. The linewise explains your second observation: when used as a motion, it not just covers the text between the previous position and the new ...


4

You can use \0 or & in the replacement as in :%s/2009.a/ \0 /gc :%s/2009.a/ & /gc


4

You can press Ctrl-z to stop vim and go to CLI, do whatever you need to (edit another vim file perhaps), then press fg on command line to return back into vim at the same place you left off at. If you didn't see the command fg being typed, then it's very likely that screen was being used.


3

I don't know about the "suddenly returned ..." part, but the first bit is fairly trivial. The :shell command opens your shell. For me, it opens at wherever I was when I opened vim, so it is inheriting settings from vim, as G-Man notes. That gives you the CLI mode. You can also open another vim from it. Quitting this shell returns you to wherever you where in ...


2

And an inline vi script: $ vi test.txt -c '%s/boy/Boy/g | %s/girl/Girl/g | g/^$/d | wq'


2

You could make your history very large and then execute stuff from there. And there's commandlinefu.com... You could note all those one liners in a plain text file you keep around. I run a private habari instance where I put this kind of stuff (and more documentation)...


1

Alternatives Unless you really need special Vim capabilities, you're probably better off using non-interactive tools like sed, awk, or Perl / Python / Ruby / your favorite scripting language here. That said, you can use Vim non-interactively: Silent Batch Mode For very simple text processing (i.e. using Vim like an enhanced 'sed' or 'awk', maybe just ...


1

NOTE: Using sed is the appropriate way to do this, as shown by @Anthon's answer! Just to show you how you could do this in vim. You can use the argdo command within vim. From the :help argdo in vim: :argdo[!] {cmd} Execute {cmd} for each file in the argument list. Example: :args *.c :argdo set ff=unix | update This sets the ...


1

Running commands from vim You asked about vim. In vim, you can create a file with your shortcuts. It would have lines such as: !ntpq -c "rv 0 version" You can then copy that line to the vim command line (:) to execute it. Because the line starts with !, vim will give it the the shell to execute when you press enter. You never have to leave vim. With ...


1

Assuming your vi is actually vim or gvim, it can certainly be implemented in vimscript, but it may be complicated to work on multiple files at once. Better the right tool for the job: sed, the stream editor, which used a very similar syntax like vi, but is intended to work on files as a stream line by line, without interaction. With the option -i, sed can ...


1

sed is the tool for you. Most of the commands that you will use in vi will be available in sed and so, there is not much learning curve. The commands in vi that are started with a : are based on the underlying editor ed and they are also available in sed. You will use those commands without the : and they are, by default, applied to the entire file. For ...


1

I second @Anthon's answer. Use sed: $ sed -e "s/boy/Boy/g" -e "s/girl/Girl/g" -e '/^\s*$/d' file NOTE: (This also deletes lines with only whitespaces) Add -i to sed if you want to replace in-place (your files are under version control, right?). For multiple files: $ for $f in $(ls mydir); do sed -e "s/boy/Boy/g" -e "s/girl/Girl/g" -e '/^\s*$/d' $f ...


1

@Gnouc's answer goes into the right direction, but you must not invoke an external command from within the statusline evaluation! This will spawn a new process on every cursor move and typed character, and drag down Vim's performance (as you've experienced). Better split this into two parts: an :autocmd that updates a variable whenever the current buffer ...


1

As umläute suggested in a comment, to Tyler Durden's answer, I opened a feature request/bug report issue 258 in vim. The fix is in patch 7.4.444.



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