├── Changes
├── README.markdown
├── doc
└── lost.txt
└── plugin
└── lost.vim
/Changes:
--------------------------------------------------------------------------------
1 | Changelog for lost-vim
2 |
3 | - 1.0 2017-05-16 12:12 Los Angeles
4 |
5 | * Added a way to change the regex used (Good idea Léonard Messier!)
6 | * Added statusline support (Good idea Andrew Farmer and Chris Heithoff!)
7 | * Fixed link to pathogen in docs (Fixes #1) (Thanks Christopher Fujino!)
8 |
9 | - 0.9 2017-05-13 15:55 Los Angeles
10 |
11 | * Initial Release
12 |
--------------------------------------------------------------------------------
/README.markdown:
--------------------------------------------------------------------------------
1 | # lost.vim
2 |
3 | Vim plugin to provide a command to help you orient yourself when editing a large
4 | chunk of code. While we should try to avoid having huge functions or huge
5 | classes or huge blobs of code, they will likely exist forever and I aim to make
6 | working with them less painful.
7 |
8 | ## Example
9 |
10 | Imagine you have the following code block, and the cursor is where the `|` is:
11 |
12 | ```
13 | sub foo {
14 | # 1000 lines of nonsense
15 | |dwigt();
16 | # 1000 more lines of nonsense
17 | }
18 | ```
19 |
20 | If you run the `:Lost` command you will see `sub foo {` at the bottom of your
21 | vim window. Nice!
22 |
23 | [](https://asciinema.org/a/2b64vpw1pmx3fl94ly1q4kyi8)
24 |
25 | ## Inspiration
26 |
27 | (The following is quoted from [the blog
28 | post](https://blog.afoolishmanifesto.com/posts/file-context-lost-in-a-file/)
29 | where I had the idea for this tool.)
30 |
31 | One of the subtle brilliances that `git` provides is context other than simple
32 | line numbers in diffs. I know that it wasn't the first tool to implement such a
33 | feature (`diff -p` does the same thing) but it was the first one that I've seen
34 | use it by default. For example, the diff
35 | [here](https://github.com/frioux/DBIx-Class-Helpers/commit/2bef898e9c2c70c79d269c7222e619ac08be027c#diff-541385fdf1ae526e444d502ed0483b3cL33)
36 | includes the following snippet:
37 |
38 | ```
39 | @@ -33,9 +44,9 @@ sub _defaults {
40 | my ($self, $params) = @_;
41 |
42 | $params->{namespace} ||= [ get_namespace_parts($self) ]->[0];
43 | - $params->{left_method} ||= String::CamelCase::decamelize($params->{left_class});
44 | - $params->{right_method} ||= String::CamelCase::decamelize($params->{right_class});
45 | - $params->{self_method} ||= String::CamelCase::decamelize($self);
46 | + $params->{left_method} ||= $decamelize->($params->{left_class});
47 | + $params->{right_method} ||= $decamelize->($params->{right_class});
48 | + $params->{self_method} ||= $decamelize->($self);
49 | $params->{left_method_plural} ||= $self->_pluralize($params->{left_method});
50 | $params->{right_method_plural} ||= $self->_pluralize($params->{right_method});
51 | $params->{self_method_plural} ||= $self->_pluralize($params->{self_method});
52 |
53 | ```
54 |
55 | The top of the snippet is the function that the change was made in. The
56 | context is not always perfect, but it's right so often it is astounding. This
57 | is exactly what I wanted, but generalized.
58 |
59 | ## Installation
60 |
61 | If you don't have a preferred installation method, I recommend installing
62 | [pathogen.vim](https://github.com/tpope/vim-pathogen), and then simply copy and
63 | paste:
64 |
65 | cd ~/.vim/bundle
66 | git clone git://github.com/frioux/vim-lost
67 |
68 | Once help tags have been generated, you can view the manual with
69 | `:help lost`.
70 |
71 | ## Self-Promotion
72 |
73 | Like lost.vim? Follow the repository on
74 | [GitHub](https://github.com/frioux/vim-lost). And if you're feeling especially
75 | charitable, follow [frioux](https://blog.afoolishmanifesto.com) on
76 | [Twitter](http://twitter.com/frioux) and [GitHub](https://github.com/frioux).
77 |
78 | ## License
79 |
80 | Copyright (c) Arthur Axel fREW Schmidt. Distributed under the same terms as Vim
81 | itself. See `:help license`.
82 |
--------------------------------------------------------------------------------
/doc/lost.txt:
--------------------------------------------------------------------------------
1 | *lost.txt* I'm all lost in this big old file
2 | Author: Arthur Axel fREW Schmidt
3 | License: Same terms as Vim itself (see |license|)
4 |
5 | INTRODUCTION *lost*
6 |
7 | Lost provides a single command, |lost-:Lost|, to help you orient yourself in
8 | large sections of code.
9 |
10 | Context *lost-context*
11 |
12 | Lost borrows the concept of the C function from `diff(1)`, which `git(1)` uses
13 | to give context by default. I am astounded, after using `git(1)` as long as I
14 | have, how often the "C function" works for almost every single bit of code
15 | I've ever written. I hope it works just as well for you!
16 |
17 |
18 | COMMANDS *lost-commands*
19 |
20 | *lost-:Lost*
21 | :Lost |:echom| the |lost-context| of the current line.
22 |
23 | FUNCTIONS *lost-functions*
24 |
25 | *lost-Lost_string()*
26 | Lost_string() returns the |lost-context| of the current line.
27 |
28 | MAPPINGS *lost-mappings*
29 |
30 | *lost-gL*
31 | gL call |lost-:Lost|
32 |
33 | SETTINGS *lost-settings*
34 |
35 | *lost-regex*
36 |
37 | If you work in a language that does not typically work with this venerable
38 | heuristic, you can tweak it by setting `b:lost_regex`. For markdown, to match
39 | titles, I did the following in my vimrc:
40 |
41 | augroup vimrc
42 | autocmd!
43 |
44 | au FileType markdown let b:lost_regex = '\v^#'
45 | augroup END
46 |
47 | *lost-statusline*
48 |
49 | If you want to see your context directly in your statusline, you can use
50 | something like this:
51 |
52 | %{strpart(Lost_string(), 0, 20)}
53 |
54 | Any expression using |lost-Lost_string()| should work; though I'd recommend
55 | using |strpart()| if only to avoid overlong status lines.
56 |
57 | ABOUT *lost-about*
58 |
59 | Grab the latest version or report a bug on GitHub:
60 |
61 | https://github.com/frioux/vim-lost
62 |
63 | vim:tw=78:et:ft=help:norl:
64 |
65 |
--------------------------------------------------------------------------------
/plugin/lost.vim:
--------------------------------------------------------------------------------
1 | " lost.vim - I'm all lost in this file
2 | " Maintainer: Arthur Axel fREW Schmidt
3 | " Version: 0.9
4 |
5 | if exists('g:loaded_lost') || &cp || v:version < 700
6 | finish
7 | endif
8 | let g:loaded_lost = 1
9 |
10 | function! Lost_string()
11 | " https://git.savannah.gnu.org/cgit/diffutils.git/tree/src/diff.c?id=eaa2a24#n464
12 | let re = get(b:, 'lost_regex', '\v^[[:alpha:]$_]')
13 | let found = search(re, "bn", 1, 100)
14 | if found > 0
15 | let line = getline(found)
16 | return line
17 | else
18 | return '?'
19 | endif
20 | endfunction
21 | command! -bar Lost echom Lost_string()
22 |
23 | nnoremap gL :Lost
24 |
--------------------------------------------------------------------------------