Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim travel to pathfile via shortcut, directly, always

Tags:

path

vim

when i travel between files using a shortcut over a pathfile, then it seems like i don't just travel between files.

i go to a file using >, within that file i change location of the cursor and do something, then i press <. but instead of going to the previous file, it first goes to the original location i was at when i entered the file, then i need to press < again to actually get to the previous file.

that's a nuisance for it doesn't allow me to change the stored location within the destination file. it always remains the same so i always enter at the same place, plus this requires two clicks to travel when only one is necessary. and this makes the system behavior more confusing.

this problem only seems to arise when i enter very large files. with the small ones the location works fine.

how do i make the < button move me to the previous file i was in, directly, always?

p.s.
is use the following mapping in my vimrc:
noremap > gf
noremap < <C-o>

i have tried substituting <C-o> with <C-6>, but that doesn't work, for some reason.

like image 647
john-jones Avatar asked Oct 08 '10 11:10

john-jones


People also ask

How do I quickly switch between files in vim?

Switch between files Here, N is capital (Type SHIFT+n). Start editing the files as the way you do with Vim editor. Press 'i' to switch to interactive mode and modify the contents as per your liking. Once done, press ESC to go back to normal mode.

How do I go to the top of a file in Vim?

Type "gg" in command mode. This brings the cursor to the first line.

How do you jump between lines in Vim?

If we are in the vim editor, then simply do this, “Press the ENTER key, write the Line number, and press Shift+ g”: Again the output is the same.

What does Ctrl-w do in Vim?

Ctrl-w = tells Vim to assign an equal number of lines to each viewport.


3 Answers

You can use :bp in your mapping (previous buffer):

:noremap < :bp<CR>
like image 150
jhwist Avatar answered Nov 15 '22 05:11

jhwist


Mapping to <C-6> doesn't work for me either, but <C-^> does.

like image 25
Curt Nelson Avatar answered Nov 15 '22 06:11

Curt Nelson


It seems to me that you're looking for a way to move directly to a certain buffer rather than a previous buffer. Using <C-o> takes you backwards through the jumplist, which is why you lose position in the edited file.

Do your pathfiles usually have a certain extension? If not you could give them a unique extension and try a mapping something like this:

noremap < :b *.pf

.pf being whatever extension you choose. This switches to the buffer with that name.

Unfortunately if you have more than one buffer with that extension it'll fail, in which case it's probably best to do a quick :b followed by the name.

I use this mapping for when I'm working with a handful of buffers:

nnoremap <Leader>ls :ls<CR>:b 

Using this I can just hit ,ls, look at the list, type the buffer I want and hit enter to move to that buffer.

like image 44
Alligator Avatar answered Nov 15 '22 06:11

Alligator