Tag Info

New answers tagged

0

"+ is the vim register that stands for the system clipboard. Using @grish and @serenesat we can select some visual text, and enter "+y We can use any other vim positioner to define the "copy to clipboard" area. Ex: "+yG (to save from current position to EOF) This way the text is copied to the system clipboad and can be paste with the clipbord ...


1

Without using mouse you can select lines in Vim. Get out of insert mode, hit one of the options below, and then move up or down a few lines. You should see the selected text highlighted. V - selects entire lines v - selects range of text ctrl-v - selects columns gv - reselect block After selecting the text, try d to delete, or y to ...


2

Try :set mouse=a, should be what you're looking for. Edit: As a side note, when you try to scroll through the file (as in two-finger scroll on a touchpad, for example), the text may not highlight as you'd expect. However, if you click where you want to start, then simply drag the mouse down, then everything should highlight as the mouse moves and the page ...


0

I use set wrap margin 1 in a 80 char terminal :set textwidth=80 :set wm=1 And it words pretty well. (when you want to switch off wrapping do :set wm=0 )


0

Use this Vim plugin: Vinfo To read Info documentation like Vim help-files


0

From https://stackoverflow.com/questions/4608161/copy-text-out-of-vim-with-set-mouse-a-enabled/4608387 Press 'shift' key while selecting with the mouse. This will make mouse selection behave as if mouse=a was not enabled. This works and has been verified by reviewers of stack-overflow who have accepted this as answer :)


3

To determine what editor to run, sudo checks three environment variables (in order): SUDO_EDITOR, VISUAL, and EDITOR, and uses the first editor it finds. (If it doesn't find one, it falls back to a default.) So you can make it run vimdiff instead of vim as follows: $ VISUAL=vimdiff sudoedit file1 file2 If your sudoers policy only lets you edit certain ...


1

Here is a fiddly solution. Please feel free to optimise it! Perhaps this might work in ~/vimrc? Open both files with sudoedit $ sudoedit file1 file2 Vertically split one buffer :vsp | b2 In each window, run :diffthis


0

Hmm, we had a wrong hash specified in the expression, it seems. I pushed a fix to master https://github.com/NixOS/nixpkgs/commit/f799749 EDIT: actually the following 46b48b0b4 commit resolved the bad plugins (probably all their hashes were broken).


0

Try nno : ; nno ; : vno : ; vno ; : If you use fFtT this will take some getting used to, but now quitting's just ;x to save if needed, ;q to not save. Plus, everything else gets quicker too.


0

My simple and convenient solution for quit and save from vim - is: Ctrl + X shortcut. Jut add this code to .vimrc file: "Fast quit and save from normal and insert mode :map <C-X> <ESC>:x<CR> :imap <C-X> <ESC>:x<CR>


2

You can drop-ship text from the cut buffer with swap-pasting -- pasting into a selection swaps, so dwVP line-deletes everything but the deleted word. Start with Use three words. This is the first string of another block of strings. This is the second string of another block of strings. This is the third string of another block of strings. and do ...


0

I would start like you do by splitting the sentence up into new lines but after that I would Number each line for both blocks Paste one part completely to the other sort on number remove the numbers This could look like this Blok1 - :%s/\s/\r/g Blok1 - %s/^/\=line('.')*1000+1 Blok2 - %s/^/\=line('.')*1000 Copy entire Blok2 into buffer of Blok1 sort n ...


0

Refer: http://vimdoc.sourceforge.net/htmldoc/options.html Look at Note section at the bottom of the reference: When enabling the mouse, the mouse buttons can still be used by keeping the shift key pressed. This includes copy paste using mouse buttons. *'mouse'* *E538* 'mouse' string (default "", "a" for GUI, MS-DOS and Win32) global ...


1

One options is to use: if system("uname") == "Linux" set filetype off match ExtraWhitespace /\s\+$/ endif


0

Here are few steps: Place your cursor on the first tag. Select outer html code by pressing: vat. Press Esc to exit visual mode and type: :'<,'<s/span/div/ :'>,'>s/span/div/ Note that :'>,'>s/span/div/ won't work correctly if there are two occurrences of the same closing tag in the same line, as it'll always change the first one. To fix ...


3

This is nothing to do with the shell, or with the version of vim. It's a simple configuration thing, as the operation of backspace in insert mode is ordinary vim configurable behaviour. Specifically, it is vim's backspace setting. On one machine you (most probably) have that set to the empty string, and on another you have it set to include the value ...


0

I believe this might due to the version of vim installed on OSX by default. You can always install vim via homebrew and see if that replacement helps. I found this page that kind of helps supe up the OSX terminal experience. https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/ Take note of this line 'brew install vim ...


2

/\/var\/adm\> \< means start of a word (/var is not start of a word)


0

The best answer to my own question is found in the answer to another post: vim: create file with +x bit. That makes this question essentially a duplicate. I think I'll delete this question unless someone sees a reason to keep it.


2

If you automate things with scripts and make scripts on a regular basis, you should automate the script creation...with a script. So instead of calling: vi some_new_program.py you should have a script newpy: #!/bin/bash echo '#!/usr/bin/env python' > "$1" echo '# coding: utf-8' >> "$1" echo '' >> "$1" chmod +x "$1" vi +3 "$1" Of course ...


0

To execute vim in non-interactive mode, you can use either +{command}/-c {command} or -s parameter which will allow you to execute the vim commands after the first file has been read. Check few examples below. Simple standard input and output using pipes can be achieved by the command: $ echo Example | vim -es '+:wq! /dev/stdout' /dev/stdin | cat To ...


2

Start just above the first function and jump to the opening brace with ]M. You can now jump to the next one with ]}]M (]} = closing brace, then ]M again), which is a bit long-winded, so map that to an f-key: :nmap <F9> ]}]M If you use "goldilocks" style indenting, e.g.: void foo (int bar) { This takes you to the same line as the signature -- ...


0

Ok it looks like the EOF was just a lot more sensitive than I excpected this doesn't work vim -E -s dummy.out <<-EOF :%s/old/new/g :%s/old2/new2/g :%s/old3/new3/g :update :quit EOF this does vim -E -s dummy.out << EOF :%s/old/new/g :%s/old2/new2/g :%s/old3/new3/g :update :quit EOF


0

The simplest way is to pass locate as shell substitution, like: vim $(locate filename123) You can also consider to use find instead of locate to pass file names to edit, in example: find . -name 'filename123' -exec vim {} + On Unix/OSX you can use xargs with -o parameter, like: locate filename123 | xargs -o vim -o Reopen stdin as /dev/tty in the ...


2

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

automatic edition should be done using sed(1) (see man sed ) The commend your are looking for are sed -i -e s/old/new/g -e /deletethis/d -e '/^$/d' postgresdb.out I am not sure what you expect with :%s/\n\n//d. where -i means edit in place (usually sed will output edition do standard output) -e ... do the edition/deletion -e '/^$/d' shoudl delete ...


1

You can jump between tags using visual operators, in example: Place the cursor on the tag. Enter visual mode by pressing v. Select the outer tag block by pressing a+t or i+t for inner tag block. Your cursor should jump forward to the matching closing html/xml tag. To jump backwards from closing tag, press o or O to jump to opposite tag. Now you can ...


3

It seems like if it's a tab. You can confirm this by placing your cursor on it and press ga in normal mode. If it displays <^I> 9, Hex 09, Octal 011 then it's a tab. A space looks like this: < > 32, Hex 20, Octal 040 To change each tab to a single space: %s/\t/ /g


0

I quick search found these resources: How to uninstall How to uninstall spf13 vim distribution If you have saved your own configuration, it should be enough to remove the following files and directories, and restore your own, pre-spf13 configuration: ~/.vimrc ~/.gvimrc ~/.vim/


0

You need to find out which syntax group causes the highlighting. :syn list shows all active groups, but it's easier when you install the SyntaxAttr.vim - Show syntax highlighting attributes of character under cursor plugin. When you have the name of the offending syntax group, you can link it to another highlighting group in your ~/.vimrc, like this: ...


0

There is an easy to remember solution, without modifying buffers or files. Place your cursor on the first character (L on your example) of the file portion you want to see, then type :set nowrap zs The zs command will setup vi so that that the character with the cursor appears at first column of the screen. Be sure that you didn't type :set nosol in your ...


0

Most systems at this point use a symlink of vi to the vim program. Calling the program in this manner enables some functionality and disables other modes of operation. More to the point, you note that you're wanting to utilize the paste functions in vi. I'm going to make the assumption that you're using vi on Mac OSX in the terminal program. To utilize the ...


1

From your description I suspect you're looking for enabling Paste mode in Vim. You may do this as follows: :set paste It can be disabled with :set nopaste This mode is useful when you copy-paste some code snippet from your OS buffer to Vim. This will prevent Vim from adding lots of extra spaces to line beginnings making pasted text look ugly.


2

To have search results highlighted, the option is hlsearch. According to the help it is off by default. So either use :set hlsearch or add it to your .vimrc. The command :nohlsearch turns the highlighting off temporarily, until the next search. To make the cursor position more obvious I also use set cul and set cuc to highlight the current line and ...


0

in your .tmux.conf: set -g default-terminal "screen-256color"


1

sed -e 's/\(match\)\([_[:alnum:]]*\)\(\(.*\)\n\)*/\1\ /2;tc' -e b -e :c -e 's//\1\2\4\2/' The above sequence will always handle only the first and second occurrence of match on a line - regardless of how many there may be on a line. It works by doing the the first s///ubstitution on the s///2cd occurrence of the pattern, then, if the substitution tests ...


1

:%s/\v(match\$(\w+).*match\$)xxx/\1\2/ \v very magical (we can use less \\)


2

:%s/match\$\zs\(\w\+\)\(.*match\$\)xxx/\1\2\1/ Explanation match\$\zs: anchor the match at the first match$; I use \zs to start the match after that, to avoid yet another capturing group \(\w\+\): capture the text after the first occurrence of match$ \(.*match\$\): capture what's after that, up to the second occurrence of match$, and capture that as we ...


1

Try this: sed -e 's/\(match\$\)\([a-zA-Z_]\+\)\([a-zA-Z ]\+match\$\)[a-zA-Z]\+/\1\2\3\2/' < input.txt > output.txt Using an input.txt of: text match$something_here and match$xxx blablabla text match$something_else_here and match$xxx blablabla I get an output.txt of: text match$something_here and match$something_here blablabla text ...


3

This answer should really be a comment, but I do not have the reputation on this StackExchange yet. Anyway, vim is a superset of vi. Meaning, everything that works in vi works in vim. For all intents and purposes, it is a more extensible version of vi. for example the arrow keys print ABCD instead of moving. There are 2 solutions to this. Change ...


4

The original question has already been answered explaining that vi is an alias for vim, and that it is normal for the command vi to start vim. What should be noted is that vim is (in some setups) sensitive to which name it is called by. Even though vi and vim both execute the same binary they can behave differently.


0

You can do multiple commands in a row using |, as a command delimiter. %s/cat/dog/g|%s/car/truck/g


9

On many Linux systems, the default vi really is a version of Vim, typically one compiled with fewer options (no built-in perl and python support, no GUI, etc) than the one you would get if you installed a Vim package. for example the arrow keys print ABCD instead of moving. This is caused by an inconsistency between your terminal emulator and Vim's ...


15

If you are using Debian then vi is opening as vim because of the entry of vi in /etc/alternatives. Let me break this up for you. When you do ls -l /usr/bin/vi: lrwxrwxrwx 1 root root 20 Jul 1 2014 /usr/bin/vi -> /etc/alternatives/vi As you can see the vi binary is a symbolic link to /etc/alternatives/vi. Now if you do ls -l /etc/alternatives/vi: ...


25

While the original vi is still available, I do not think it is much used on current linux or BSD distributions;1 apparently it was dusted off in 2000 after having been mothballed a decade before that, and the last release was 2005. There are various implementations of vi around, which is really now a POSIX specification. These include nvi and elvis, but ...


2

The SwapStrings.vim plugin allows to do this elegantly: :%SwapStrings car truck :%SwapStrings cat dog More alternatives can be found here.


1

You can use the \= special replacement which allows to run vim code: For instance, to swap foo and bar: %s/foo\|bar/\=submatch(0) == "foo" ? "bar" : "foo"/g Or for your example: %s/ca[rt]/\=submatch(0) == "car" ? "truck" : "dog"/g See: :h sub-replace-expression for details.


0

:%s/foo/bar/gc This command changes foo with bar! :%s is a substitute for vim


1

The [:foo:] bracket expression is meant to be used inside a [...] collection, like this: :g/[[:digit:]]/s/1/2/g This allows you to specify multiple (alternative; otherwise it would be concatenation) groups, and mix with other characters, e.g.: [[:space:][:digit:]abc].



Top 50 recent answers are included