Vim newbie here.
I would like to be able to create tabs in Vim such that, for example, the tabs are at 4" left and 1.5" right for one type of section, 1.5"/1.5" for another, etc.
I know how to set tab stops, etc. but the trick here is I would like vim to recognize key combinations like shift-enter to go to one kind of formatting, plain enter to go to another kind, etc.
Is this even possible with vim?
TIA
I think you're confusing Vim with a word processor (like Word or Writer). There's no measurement in inches, no left / right margins, etc.
Vim's 'tabstop' option is a multiple of the width of a single space character that a <Tab> character (ASCII 0x09) expands to. This is fixed for the entire buffer (though you could use a set of :autocmds to change it in different parts of a buffer). Vim has no notion of paragraph text styles like a word processor, where you can define different styles. Vim only has a rather primitive :hardcopy command for printing.
If you need elaborate text formatting capabilities, Vim probably is the wrong tool, except if you choose to edit a source code document (like Latex, HTML, or Markdown), which is only compiled into a document (for those, like editing programming languages, it's actually well suited and powerful).
The vimtutor command (see :help vimtutor inside Vim) provides a good introduction to Vim's capabilities.
Check out these screenplay scripts. At least the first one contains custom tab widths as required in the traditional play formats. Perhaps they provide you the right idea on what's possible with Vim:
http://www.vim.org/scripts/script.php?script_id=2447 by Mike Zazaian
http://www.vim.org/scripts/script.php?script_id=1842 by Alex Lance
Related
I'm looking for some way to connect indets into tree structure similliar to the one used by terminal tree command.
Something that interprets the indents in same way tree interprets file system.
Alternatively for sublime text or another text editor.
Edit: Apologies for the broadness of question, to specify what i wanna do is>
Rather then replacing the actuall text i just want it to interpet the indents into the tree structure while retaining the actuall file should retain it's indents.
You've asked a broad question (and did not show any research effort so far), so I all I can do is answering it broadly as well (for Vim):
permanent change
For a permanent change of the actual text, all you need is :substitute. A start would be
:%substitute/ \ze\S/└── /
To make this more beautiful, another pass could turn └ into ├ by comparing previous and current line; :substitute or :global can do this.
just visualization
If you don't want to actually manipulate the buffer contents, but just affect the visual appearance, :set list and the 'listchars' option come to mind. Unfortunately, though this can display spaces and tabs, it does so uniformly; i.e. you cannot just apply it to the "last" part of the indent. You have a chance to implement this with :help conceal; this can translate a (sequence of) character(s) to a single (different) character. This is based on syntax highlighting. You could define matches for fourth last space before non-whitespace and conceal that as └, and third and second last space before non-whitespace and conceal as ─, for example.
or a hybrid
Another approach would be a combination: Use (easier) modification with :substitute, but undo this before writing (with :autocmd hooks into the BufWritePre and BufWritePost events). If this is purely for viewing, you could also simply :setlocal nomodifiable or :setlocal buftype=nowrite to disallow editing / saving.
I recently started using git, and by default it would want to use vim. I always wanted to look a bit deeper in this editor, but was always thrown back, only using it if for some reason (such as in case of a near dead Linux system) it was unavoidable. Even now I soon ended up reconfiguring git to use mcedit instead (which I use for programming).
The problem was that OK, I gave the command :help to see how I could start. Then in the help system it suggests me to jump to the subject interesting me using CTRL-]. And here I am lost. I have a Hungarian keyboard, and simply couldn't find where it excepted to find ]. So I can just scroll around in a list of topics I can not enter.
This is just the beginning: In general how much such "weird" combinations I may except? And how I could fix those up? An other problem with the Hungarian language is that it has a bunch of extra vowels which have to be mapped on the same amount of keys like English with it's 26 letters (there are 9 extra letters, so 9 keys "lost"!). Would this hinder the use of vim for writing Hungarian text (where I would require these keys to produce the language-specific vowels)?
How this problem could be solved in a way that if I happen to get an English keyboard (for which layout I guess vim was originally designed), I wouldn't have to re-learn the positioning of the keys? (Since I have no English keyboard around I can't try what happens. As I tried neither of the two keys on the left of 'P' would suffice for the CTRL-] combination while as far as the layouts I checked the second should be it. Of course my system is configured for Hungarian layout)
The language truly is irrelevant, I guess everyone having non-English keyboards might face similar problems. So how you work yourself around these?
Look at /usr/share/vim/vim74/keymap/ directory (in debian/ubuntu it is a part of the vim-runtime package), you should see a bunch of keymap files for different locales. Chose the one you like. In the example I use russian-jcukenwin.vim.
Add to your .vimrc file →
set keymap=russian-jcukenwin
set iminsert=0
set imsearch=0
highlight lCursor guifg=NONE guibg=Cyan
Now you can switch layout with Ctrl-^ keys. Note: layout is switchable when in insert-mode.
As you can guess the first line is the name of the file I mentioned. The next two lines sets the iminsert and imsearch in order to start writing the very first time with latin layout. In fact Ctrl-^ toggles them between 1 and 0. And the last line draws the caret with cyan color when layout is changed.
You can remap all vim defaults bindings with the map function.
For further information, you can read this tutorial
simple solution
you can switch to English layout when using vim:
setxkbmap us
and switch back to hungarian keyboard (hu) afterwards.
xkb
To show you another way:
the xkeyboard layout for hu keyboard is located in /usr/share/X11/xkb/symbols/hu. Try to compare the layout with /usr/share/X11/xkb/symbols/us.
There are also layout variants for hu keyboard than just default.
See my post here
If you want to do something advanced, you could also apply the english keyboard to the CAPS LOCK modifier LEVEL
When I open a file Foo.txt in vim, and then use :vsplit so that I can examine different segments of it side-by-side, I notice that if I do any kind of visual selection on the left, vim will select the same text on the right. Furthermore, if the two sides are not lined up when I started the visual selection, whichever side I switch to will jump to match the one that was selected.
I would like to be able to use visual mode to highlight different segments of the text on the two sides of the split window, or at least to be able to use visual mode on the left and then move my cursor to the right. This works perfectly fine if the two files are actually different files.
Is there some option that would enable this, or is the only way to make a copy of the file?
Edit: I am expanding the scope of this question to include any vimscript-based solutions, since it does not seem to be an option that can be set. If someone has a nice hack for getting this behavior, please share. I will also be looking into autocmd in the meantime, although it is most likely beyond my current knowledge in vimscript.
It is as if vim is trying to be clever when it sees two same files, and this cleverness should be disableable.
This "cleverness" is the implementation detail that the visual selection (precisely, the '<,'> marks) is local to the buffer. As you have observed, different buffers can have (and remember) different selections.
The alternative would be to make the visual selection window-local. I guess that approach wasn't chosen because often, the exact selection range cannot be transferred to another buffer; the number and lengths of lines are different.
That said, you can probably implement what you want with :autocmds that save the '<,'> marks in a window-local variable on WinLeave and restore from those on WinEnter.
In both Eclipse and Notepad++, I have my text editors configured so a space has a semi-transparent dot in the center, which makes it easy to count whitespace. I prefer to use spaces instead of tabs in my text editing, and this feature is crucial when working with a whitespace-sensitive language like Python.
I have attached a screenshot with some dummy code in case my wording wasn't clear.
At any rate, is there any way to come close to this functionality in Vim (or GVim)? I suppose there is highlighting but that does seem a bit subpar. There's also good old fashioned math by looking at the column number. What are my other options?
Thes lines in your vimrc should give you an approximation but you won't get dots for normal or leading space: only trailing spaces. That's a Vim limitation.
set list
set listchars=
set listchars+=tab:»\
set listchars+=extends:›
set listchars+=precedes:‹
set listchars+=nbsp:·
set listchars+=trail:·
See :help 'list' and :help 'listchars.
I agree with romainl's answer, but would like to add a mention of the indent guides, which can colour indentation based on your current tab size settings.
Community Wiki
As the documentation of the yank system shows (thanks Michal), The Vim yank system seems to be more intricate then a standard clipboard. I therefore think it beneficial if vim veterans could perhaps show us some different styles of making use of this mechanism. particularly with the usage of vim for complicated projects without the use of a heavyweight IDE (say C++ ?).
Original Question
Now that I am using vim for everything I type, rather then just for configuring servers, I wan't to sort out the following trivialities. I tried to formulate Google search queries but the results didn't address my questions :D.
Question one: How do I yank and replace multiple times ?
Once I have something in the yank history (if that is what its called) and then highlight and use the 'p' char in command mode the replaced text is put at the front of the yank history; therefore subsequent replace operations do not use the the text I intended. I imagine this to be a usefull feature under certain circumstances but I do not have a need for it in my workflow.
Question two: How do I type text without causing the line to ripple forward ?
I use hard-tab stops to allign my code in a certain way -- e.g.,
FunctionNameX ( lala * land );
FunctionNameProto ( );
When I figure out what needs to go into the second function, how do I insert it without move the text up ?
Question three Is there a way of having a uniform yank history across gvim instances on the same machine ? I have > 1 monitors. Just wondering, atm I am using highlight + mouse middle click.
Answer one: A relevant, if not particularly encouraging, qoute from the Vim docs (see :help put-Visual-mode):
When using a put command like |p| or |P| in Visual mode, Vim will try to
replace the selected text with the contents of the register. Whether this
works well depends on the type of selection and the type of the text in the
register. With blockwise selection it also depends on the size of the block
and whether the corners are on an existing character. (Implementation detail:
it actually works by first putting the register after the selection and then
deleting the selection.)
The previously selected text is put in the unnamed register. If you want to
put the same text into a Visual selection several times you need to use
another register. E.g., yank the text to copy, Visually select the text to
replace and use "0p . You can repeat this as many times as you like, the
unnamed register will be changed each time.
Answer two: R (the capital 'R') puts you in replace mode.
I'm missing answer three, I'm afraid.
Answer three: Not quite matching the "uniform yank history" spec, but "+y yanks to clipboard and "+p pastes from clipboard if a clipboard is available.
Yank into a buffer
:y b
yanks into buffer b
And
:p b
places it.
I think there are more named buffers available.