vimscript

Paste from clipboard in vim script

I want to write a vim function that includes pasting from the clipboard (windows if it matters) I think it should be something like function MyPastingFunc() "+p "paste from clipboard "do more stuff endfunction Of course the "+p is just a comment in the .vim file. How can I make this work? ...

Preventing redefining existing buffer mapping

I want to prevent *noremap command from remapping an existing sequence, but only if this sequence is local to buffer: noremap a b " Will fail, must succeed noremap <buffer> <unique> a c noremap <buffer> a b " Will fail, OK noremap <unique> <buffer> a c noremap a b noremap <buffer> a c " Will fail, OK noremap <unique> <buffer> a d ...

How do I write a vim function to output the result of a system command?

What I have so far: function! GetMarker() return system('echo $random `date` | md5sum | cut -d" " -f1') endfunction I would like to be able to do a :getmarker and have it insert the output of that system command at my cursor, with no new lines. Also what is the difference between function! and function? Edit: before any of you...

VIM: How to pass arguments to functions from user commands?

I am trying to create a user-defined command in VIM that takes one argument and calls a function with the user supplied argument. Seems simple but I am unable to get it to work. Here is the code from my foo.vim plugin: function! s:MyFunc(myParam) do something endfunction command! -nargs=1 MyCommand call s:MyFunc(myParam) When I ...

How do you paste with vim without code being commented?

Dumb question, right? Literally can't figure this out. Everytime I paste in vim, every line is commented out. Is there a way around this? ...

Tab to exit quotes in Vim

Usually when I code in Python, I have to create a dictionary, and I press " once and it creates "|", being | my cursor. I'm using TAB key in the snipMate plugin to use snippets. I would like to press tab, when inside quotes after writing a string, that "exits" the quotes, but mantain snipMate. Example: "name|", and, pressing TAB, to be...

Backspace, if chars from cursor to begin of line are tabs/spaces, go back one indent level.

I'm using Vim for Python development. Sometimes, after an expression in an if clause: (suppose | is cursor). if test: pass | ...I press enter, and want to go to the if identation level. I know I can go back to command mode and just press <, but I would like to know if it's possble to, when Vim knows all characters behind the...

Where color of cursor line is defined?

If I set cursorline option I get my current cursor line underlined and all characters which color is not specified also turn to yellow (yellow appears only if Normal highlight group is untouched). I wonder, where this color (yellow) is defined? Edit: I know about CursorLine highlight group. The problem is that in default colorscheme whi...

Using an argument of a function in normal mode in Vim?

I have a Vimscript function defined like this: function Cs(a, b) normal a:a|"cylr a:b|x"cP endfunction However, the intended action (do some crazy stuff with the arguments a and b in normal mode) doesn't work, instead it takes the first "a" as "append" and writes the rest of the line to the file. How can I use arguments on a "no...

Formatting DateTime in VIM without leading zeroes on Month, Day, and Hour.

Does anyone know if there's a way to format the date generated by strftime in Vim (under MS Windows) such that Month, Day, and Hour are not padded to two digits with a leading zero? For example, the following commands in vimrc: nmap <F3> a<C-R>=strftime("%I:%M %p %m/%d/%Y ")<CR><Esc> imap <F3> <C-R>=strftime("%I:%M %p %m/%d/%Y ")<CR> ...

How do I get python.vim to work with vim?

I am playing around with vim and I heard that python.vim has some nifty settings for python. Link to python.vim http://www.vim.org/scripts/script.php?script_id=790 Q1: How do I integrate python.vim with vim? Q2: Because I am not familiar with vim, if I use something like python.vim will it have a crazy effect on non-python files or w...

Conditional colorscheme in .vimrc

I am using vim and MacVim. I have a 256-colour colorscheme which I like for my MacVim, but if I load it into regular vim, it obviously does not work (I get blinkies instead). I would like to be able to use the same vim config on all my systems, so: Is there a way to check for palette size in .vimrc and set one of the two colorschemes ac...

Appending a message to a buffer from a Vim script

What's the best way to append the content of a string variable from a Vim script? ...

vim replace for a pattern

<created> [email protected] </created> I want to replace the above with but the username may vary i.e,[email protected] ,[email protected]... <created> [email protected] </created> What is the command to replace this in vim %s/<created>\r*\r</created>/new string ...

How to move or create a window on the right side on Vimscript?

I'm trying to modify project.vim to open the project window on the right side instead of in the left. I see several references in the source to "vertical new", "vertical split" and "vertical resize". Trying them I see that a new vertical split is opened to the left, but I can't find how can I make a new vertical split open (or move) to t...

What are some good resources for learning to develop VIM plugins?

I am learning VIM and would like to try to hack on some VIM plugins, but can't seem to find any resources for learning the scripting language. It seems like its called VIMscript, but I'm finding almost nothing useful on Google. Does anyone have any recommendations for learning how to develop VIM plugins from scratch? Thanks ...

Mode-local keybindings in ViM?

I've recently return to ViM, after several years in Emacs, and something I'm missing is the ability to set filetype-local keybindings: e.g. I want to make _ underline the current word in Markdown-type files, but do something completely different in, say, Python. Is there a way to do this other than just autocmds that override each othe...

How to get short option name from long option name in vim

I have a list of vim long option names as strings (e.g. ["tabstop","shiftwidth"]). What would be the best way to convert it into a list containing only short names (e.g. ["ts,"sw"]). What about if the original list is a mix of short and long names? ...

Vim auto-indentation: Align an array initialization which extends over multiple lines

Sometimes an array initialization in C extends over several lines, especially if the array is multidimensional. In Emacs the result of auto-indentation looks like this: int a[N][N] = {{0, 0, 6, 7, 0, 4, 0, 2, 0}, {0, 5, 0, 6, 0, 0, 0, 0, 1}, {2, 0, 0, 0, 0, 8, 0, 0, 4}, {4, 0, 9, 5, 0, 7, 0, ...

Path for tags in VIM for multiple projects

Hi, I've recently started using ctags on my projects. I currently have the following setup: root/tags [contains all non-static tags] root/foo/tags [contains static tags for the foo directory] root/bar/tags [static] root/something/else/tags [etc.] ... I can set tags=./tags,tags,/path/to/root/tags and everything works perfectly. Howev...