vim , Selecting a code block from middle of it

Selecting a code block from middle of it


Tag: vim

I can select a word when cursor at middle of the word by doing this --> v+i+w

But can i select a block from middle of it?

For example:

def foo(x):
    y = x + 5 --> cursor is in this line 
    return x * y

Is there way to select whole block by doing something like v+i+codeblock ?


The paragraph text object is built-in, so if your block is delimited by empty lines, vip (visual mode, select inner paragraph) will select it.

Apart from that, many plugins extend Vim's built-in text objects with custom ones. vim-dentures defines several generally useful ones based on indent. I've once seen one especially for Ruby blocks; you can search for such.

With my CountJump plugin, or the textobj-user plugin, you can even (relatively) easily define your own text objects!


Why does Vim make certain object keys yellow by default?

I use Vim as my terminal editor and one of the things I noticed was that it marks certain words such as 'status' yellow by default. Here's a screenshot: I'm little confused because I'm not sure whether it's suggesting that I don't use that word in my model object?...

Open file under cursor declared as #include in the C/C++ code in Vim?

I now how I can open a file under cursor in Vim. Is there any way to also open files declared like below? #include <iostream> #include "limits.h" ...

How to map a key in command-line mode but not in search mode

I want to map a key in VIM in command-line mode but not in search mode(with a leading /), like below: Map Q to q Map W to w Sometimes I typed the wrong command in VIM, like :Q and :W, and I want to make these wrong commands to...

How to skip a command in redo

How is it possible to skip a command wile using redo (ctrl-R) ? I made a mistake and put my file in lowercase, I can go back and undo the command, how can I redo all the other commands done after?

Prevent single letter deletes to spam clipboard manager

With unnamed clipboard option included, single letter deletes spam my clipboard manager Is it possible to fix this so that single letter deletes (with x) are not yanked to clipboard.

How to highlight rulerformat

I want highlight the rulerformat in my .vimrc. I have set ruler set rulerformat=%55(%{strftime('%a\ %b\ %e\ %I:%M\ %p')}\ %5l,%-6(%c%V%)\ %P%) I have subsequently tried all of the following: hi rulerformat ctermbg=1 hi rulerformat ctermbg=red hi Group1 ctermbg=red "if you modify the rulerformat slightly you can try to access group 1...

What is difference between Vim's clipboard “unnamed” and “unnamedplus” settings?

What is the difference between these 2 settings? set clipboard=unnamed set clipboard=unnamedplus Which one should I use in order to have multi-platform .vimrc?...

Highlighting Vim text with black background when ANSI colors are off

I'm on OSX. I've turned ANSI colors off in This is great, but now visual selections are no longer highlighted. I'd like them to be simply inverted with a black background and white text. I know this is possible in a colorless terminal, because the status line is still...

Automatically switch back to NerdTree after pressing “o” on file

When I press "o" on any file in NerdTree list, it opens this file in one of currently opened tabs. Sometimes, when I'm not 100% sure what file to open, I have to do this: 1) o (open file) 2) ctrl-ww (switch back to nerdtree) 3) j or k (go...

how to replace NumberInt(1) to 1 with vim?

I want to replace NumberInt(1) to 1 except in the string in my file with some tool: "bz":NumberInt(1), "batch": NumberInt(2), "something": "something else NumberInt(1)" "bz":NumberInt(1), "batch": NumberInt(2), "something": "something else NumberInt(2)" "bz":NumberInt(1), "batch": NumberInt(2), "something": "something else NumberInt(3)" "bz":NumberInt(1), "batch": NumberInt(2), "something": "something else NumberInt(4)" "bz":NumberInt(1), "batch": NumberInt(2), "something": "something...

Return to shell output from last run shell command

I run my tests file like such: :!bundle exec rspec my_file_spec.rb When I run that command it displays my test results in another window and I get "Press ENTER or type command to continue" to return back to vim. That's all working. What I'd like to do though is get...

Vim - how to run current python3 file in the python shell?

I have a file called on my desktop. This is the file: class Node: def __init__(self, data, next): = data = next def __str__(self): self = node while print( node = return I normally edit the file in IDLE. In IDLE I can click...

"+y operator for yanking to clip-board, not working

I use "+y to yank to clip-board so I can paste it somewhere else. It's working fine on one of my computers but not on an other. Both computers are Linux (Ubuntu) machines. The one where it is not working, I am connecting to it through SSH. Does anyone know...

Right way to set up Rust using Vim

I've finally started to dive into Rust and want to clarify some issues when it comes to setting up everything nicely. I'm using vim on Linux and found a nice plugin for syntax highlighting. Autocompletion is somewhat troublesome though, using phildawes/racer. The plugin needs the src location for Rust which...

Pylint Error when using metaclass

i try to fix all pylint errors and pylint warnings in a project. but i keep getting an error when i set a metaclass ( here is my example code: #!/usr/bin/env python3 class MyMeta(type): pass class MyObject(object, metaclass=MyMeta): # pylint error here pass the error just says "invalid syntax". i...

Vim Statusline: Word search

I've searched hard for this and haven't been able to find what I'm after. On my statusline I want a count of the number of matches that occur in the current file. The vim command below returns what I want. I need the returned number to be displayed in my...

Show tex section list in vim

I like to use vim for tex file editing. My document is lengthy, so I hope to show a list of section or subsection and navigate by just typing enter on the section name. Please let me know some good plug-in or setting. I know taglist plug-in shows a method...

match wordchar and/or dot string of anylength

This matches a word /\w\+ This matches a any number of dots /\.\+ Why doesn't this match any number of words combined by dots? /[\w\.]\+ ? The w seems to be matching actual 'w's instead of a word character, whether I escape it or not....

Temporarily declare a word as wrong in vim spellchecker

I'm writing a document with vim and latex. I recently noticed a word that I use ("tree"), but which is incorrect in the context of my document. I corrected it on the whole document. However, I have the habit to use this word instead of the correct one, when writing....

expand delimited text over multiplie lines

I am looking for a power vim tip - to expand specially formatted text over multiple lines. say i have Bill | 12 | Male | Blue | right | Pay 150k i'd like it to expand (after some vim magic) to Name: Bill Age: 12 Gender: Male Eyes: Blue...

How can I 'change in number' or 'change in digits' in Vim

I'm regularly editing CSS in Vim and need to change a value like: width: 300px; to something else like: width: 178px; Normally what I do is navigate to the 3 in 300 and type cw to change the word. But if I do this I have to type the px...

Substitute both the beginning and end of every occurrence of a string with vim

I have more than a hundred of occurrences of the string ?dep= followed by two numbers. So it goes like ?dep=01, ?dep=02, ?dep=03, etc. I need to change the string but keep the numbers at the same time, so for example ?dep=01 needs to become {{ path('annonce-index', {departement: 01}) }}...

Disable Wrapping Cursor in Eclipse

I'm mostly using Vi (edit: Vim) for text editing and the viPlugin for Eclipse Juno. Eclipse seems to have a very annoying behaviour of "wrapping" the cursor to the next/previous line, if yout reach the end/start of a line through cursor keys. (Reproduce by placing the cursor on the first...

How to jump/display the column of an error

To check the syntax of my python scripts I am using the syntastic vim plugin with pylint as checker. Is there a way to not only display or highlight the line where an error occurs but the column/exact position of this error too? I used a vim syntax checker plugin...

How do you know what VIM help keyword to search?

I was trying to google how to search within a scope in VIM and found this link. Limiting search scope for code in Vim I wouldn't imagine to come up with the keyword "/\%V" to search help in VIM help. So, I'm wondering how most people get help from VIM...

Make vim follow symlinks when opening files from command line

I'm a huge vim lover, but I can't find a way to get vim to follow symlinks when opening files. As an example, all the dotfiles in my home dirs are symlinked to within the .zprezto directory: .vimrc -> ~/.zprezto/runcoms/vimrc .zshrc -> ~/.zprezto/runcoms/zshrc I'm keeping my fork of .zprezto in...

Assigning save (:w) to w in vim

I want to be able to save a file in vim while in the insert mode. I thought of using the following shortcut: inoremap <leader>w <Esc>:w<cr> While the shortcut saves the file in the insert mode, it leaves the cursor one spot ahead of where the cursor would be if...

How to search and replace from the last match of a until b?

I have a latex file in which I want to get rid of the last \\ before a \end{quoting}. The section of the file I'm working on looks similar to this: \myverse{some text \\ some more text \\}% % \myverse{again some text \\ this is my last line \\}% \footnote{possibly...

Vim: Is it possible to have a filtered view of a file?

In a given text file, I would like to work on a "filtered view" (hiding lines with a pattern), but still to be able to edit visible lines : the filtering would only affect the visibility of some lines, and as soon as I would reset the filter, the hidden...

Enforcing coding styles in Visual Studio and VIM

I work with a medium sized team of developers, with half being Linux developers using VIM on Ubuntu and MacVIM on OSX, and the other half being Windows developers using Visual Studio 2010 or later. A fair bit of time has been wasted in the past when handling things like...

Selecting text and saving it with keymap

I've made c# command line program that takes a window handle and a string as parameters. It brings the window with the handle to the foreground, uses SendKeys to send the string that was passed, and brings the window that was previously at the foreground back to the foreground. I...

OSX tmux configuration session open file in vim automatically

So I have tmux and vim running in iterm2 on OSX. I have a tmux.conf file that sources a session in ~/.tmux/ called 'left'. I have successfully loaded this session with three panes. Two panes in a left column and a single pane on the right. I have also managed...

How to use Ctags to list all the references of a symbol(tag) in vim?

Can I list all the references of a symbol in vim using Ctags? like the 'Find References' In some GUI IDE. The Ctag tutorial just tell how to locate the definition of a symbol ,not all the usages....

Dynamic pattern for vim highlight

In the vim help, there is a suggestion to use highlight groups for highlighting text greater than the textwidth: Another example, which highlights all characters in virtual column 72 and more: :highlight rightMargin term=bold ctermfg=blue guifg=blue :match rightMargin /.\%>72v/ I would like this to always reflect the value of texwidth...

Vim keeps unindenting

Vim keeps unindenting the lines I want to keep indented if I don't write anything on them... I'll give an example, where the | is the caret. Caret is indented and I press enter if expression: print("hello world") | Caret is indented on the next line, and now I press...

Unknown function: pathogen#infect

I just installed MacVim (and did an override of Vim). And I am trying to get Pathogen to work. When I start Vim, I get the following error: Error detected while processing /Users/nir/.vim/autoload/pathogen.vim: line 1: E477: No ! allowed: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> line 2: E488: Trailing characters:...

how to apply macro on list of lines with vim

let's suppose I want to apply a macro stored on register 1 on lines: 2, 5, 9 but without applying on lines in between. I saw that you can give a range but that is not what I want. I've tried some variation on :2, 5, 9 @1 without success

element.queryselector not showing in Vim

Using various javascript-syntax for Vim, but for some reason element.queryselector() and element.queryselectorAll() don't seem to be visible from my omni-completion. Here are my list of javascript syntax libraries. NeoBundle 'pangloss/vim-javascript' NeoBundle 'isRuslan/vim-es6' NeoBundle 'othree/yajs.vim' NeoBundle 'nikvdp/ejs-syntax' Any ideas? Could there be a conflict between the various syntax libraries? ...

Vim highlighting sometimes requires a kickstart?

Centos 6, vim 7.2.411, my .vimrc file: autocmd BufNewFile,BufRead *.html set filetype=php set tabstop=4 set shiftwidth=4 set nowrap set autoindent set number if has('mouse') set mouse=a endif set backspace=start,indent,eol set t_Co=256 colorscheme molokai (Although I code in php I save my files as .html - a bad practice I imagine?...

issues with installing newer cabal version for haskell vim now

I would like to install this vim plugin: When trying to run the suggested installation script: curl -o - | bash I get: --- Cabal version 1.18 or later is required. Aborting. I then try to install a newer version of cabal: [email protected]:~/Downloads/cabal-install-$ ./ The response I get:...

how to change the regex responsible for vim's “current word” search

Is there any way to modify the "current word" search (asterisk) settings so it includes certain characters in its definition of "word". For example, I have a lot of CSS code where there is a dash character in the class names. So, if I have a class named "blue-text" and...

Vim search using regular expression

I want to search a string which starts with "abc" and ends with "xyz" in vim. Below are the commands I've tried: :1,$g/abc[\w\W]*xyz/ :1,$g/abc\[\\w\\W\]\*xyz/ :1,$g/abc*xyz/ "[\w\W]*" means the texts between "abc" and "xyz" can be any characters "1,$" means the search range is from the 1st line to the last...

Using vim-quickrun for “PHP REPL style”

I'm trying to get some "repl-like" feature for PHP, inside vim. Basically, what I want is to be able to visually select a part of my script, execute it, and see the result in a separate buffer. But I don't want to execute the whole current file (so :!php %...

The “-” key goes up a line in vim

When I hit the "-" key on my keyboard vim goes up a line. My .vimrc is blank and when I type in :map - vim says "no mappings found." I have no idea what could be causing this. I am using a Mac—could it be a problem? Thanks...

VIM - Reformatting indentation and braces

When working with blocks of code in VIM, I'm able to easily re-indent blocks of code via selecting a region in visual mode (SHIFT+v), then just hit =. This re-tabs lines of code, uses the correct indentation depths, hard-tabs vs spaces, etc. I have a large set of functions I...

Custom mappings in help text buffers

I tend not to use windows much in Vim (I prefer tabs), but there are certain things that use them, such as help text buffers. I'm fine with that, but with how seldom I use windows, it usually takes me a second to remember how to close the window (<C-w>c)...

Moved .vimrc in a new dir, trying to get it to work

Disclaimer: I'm new to vim/tmux. I'm on a Mac using MacVim I was told to use version control on my dotfiles. Before my dot files were all placed in my root ~ like so: ~/ .vimrc .tmux.conf .vim /bundle /autoload .viminfo etc But then I figured it would be a...

Replace all newlines between “two lines with certain patterns” with a comma in vim

If I have to replace newlines with comma for all lines between Pattern 1 and Pattern 2, how do I do it? From: Pattern 1 abcd edfgads asd adsad ... Pattern 2 to: Pattern 1, abcd, edfgads asd, adsad, ..., Pattern 2 ...

How to delete a WORD in vim in insert mode

Is there a way how to delete a whole WORD (e.g. from vim path/to/some/file.txt to vim) in insert mode? To delete a word in insert mode the C-W shortcut works well. I got used to use C-W in bash too but bash actually deletes whole WORDs. Now I'd love to...

Vim background color “dark” = “black”? or I didn't install correctly?

I added a color theme expected to be, in which the background color is lighter than black.: But my my color theme looks complete dark. Whats wrong with it? ...